Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pint/pint_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import argparse
import contextlib
import re
import sys
from typing import Any

from pint import UnitRegistry
Expand All @@ -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
Expand All @@ -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 = [
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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())
6 changes: 5 additions & 1 deletion pint/testsuite/benchmarks/test_00_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ sphinx-book-theme>=1.1.0
sphinx_copybutton
sphinx_design
typing_extensions
sciform
sciform
scipy
Loading