diff --git a/pint/pint_convert.py b/pint/pint_convert.py index 49200727c..629566784 100644 --- a/pint/pint_convert.py +++ b/pint/pint_convert.py @@ -13,6 +13,7 @@ import argparse import contextlib import re +import sys from typing import Any from pint import UnitRegistry @@ -24,7 +25,7 @@ def _set(ureg: UnitRegistry, key: str, value: Any): object.__setattr__(obj, "scale", value) -def _define_constants(ureg: UnitRegistry): +def _define_constants(ureg: UnitRegistry, use_corr: bool): # Measured constants subject to correlation # R_i: Rydberg constant # g_e: Electron g factor @@ -38,7 +39,7 @@ def _define_constants(ureg: UnitRegistry): m_e = (ureg._units["m_e"].converter.scale, 0.00000000028e-30) m_p = (ureg._units["m_p"].converter.scale, 0.00000000051e-27) m_n = (ureg._units["m_n"].converter.scale, 0.00000000095e-27) - if args.corr: + if use_corr: # Correlation matrix between measured constants (to be completed below) # R_i g_e m_u m_e m_p m_n corr = [ @@ -109,7 +110,7 @@ def _define_constants(ureg: UnitRegistry): ureg._build_cache() -if __name__ == "__main__": +def main(): parser = argparse.ArgumentParser( description="Unit converter.", usage=argparse.SUPPRESS ) @@ -192,7 +193,7 @@ def _define_constants(ureg: UnitRegistry): "Failed to import uncertainties library!\n Please install uncertainties package" ) - _define_constants(ureg) + _define_constants(ureg, args.corr) num = nq.magnitude fmt = fmt @@ -218,3 +219,7 @@ def _define_constants(ureg: UnitRegistry): fmt = "{:" + fmt + "} {:~P}" print(("{:} = " + fmt).format(q, nq.magnitude, nq.units)) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/pint/testsuite/benchmarks/test_00_common.py b/pint/testsuite/benchmarks/test_00_common.py index 43ee3fee3..31bf11cc4 100644 --- a/pint/testsuite/benchmarks/test_00_common.py +++ b/pint/testsuite/benchmarks/test_00_common.py @@ -4,7 +4,7 @@ import sys -def test_import(benchmark): +def import_pint(): # on py37+ the "-X importtime" usage gives us a more precise # measurement of the import time we actually care about, # without the subprocess or interpreter overhead @@ -16,3 +16,7 @@ def test_import(benchmark): field = line.split(b"|")[-2].strip() total = int(field) # microseconds return total + + +def test_import(benchmark): + benchmark(import_pint) diff --git a/pyproject.toml b/pyproject.toml index 47fd69b45..6c42bbecf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,12 +72,16 @@ docs = [ "recommonmark==0.5.0", "babel", "sciform", + "scipy", ] [project.urls] Homepage = "https://github.com/hgrecco/pint" Documentation = "https://pint.readthedocs.io/" +[project.scripts] +pint-convert = "pint.pint_convert:main" + [build-system] requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" diff --git a/requirements_docs.txt b/requirements_docs.txt index cc766a381..c4865c488 100644 --- a/requirements_docs.txt +++ b/requirements_docs.txt @@ -19,4 +19,5 @@ sphinx-book-theme>=1.1.0 sphinx_copybutton sphinx_design typing_extensions -sciform \ No newline at end of file +sciform +scipy