-
-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor Pint, support Python 3.13, drop 3.8
Refs #2434
- Loading branch information
Showing
82 changed files
with
16,910 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Copyright (c) 2012 by Hernan E. Grecco and contributors. See AUTHORS | ||
for more details. | ||
|
||
Some rights reserved. | ||
|
||
Redistribution and use in source and binary forms of the software as well | ||
as documentation, with or without modification, are permitted provided | ||
that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* The names of the contributors may not be used to endorse or | ||
promote products derived from this software without specific | ||
prior written permission. | ||
|
||
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND | ||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | ||
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | ||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
""" | ||
pint | ||
~~~~ | ||
Pint is Python module/package to define, operate and manipulate | ||
**physical quantities**: the product of a numerical value and a | ||
unit of measurement. It allows arithmetic operations between them | ||
and conversions from and to different units. | ||
:copyright: 2016 by Pint Authors, see AUTHORS for more details. | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from importlib.metadata import version | ||
|
||
from .delegates.formatter._format_helpers import formatter | ||
from .errors import ( # noqa: F401 | ||
DefinitionSyntaxError, | ||
DimensionalityError, | ||
LogarithmicUnitCalculusError, | ||
OffsetUnitCalculusError, | ||
PintError, | ||
RedefinitionError, | ||
UndefinedUnitError, | ||
UnitStrippedWarning, | ||
) | ||
from .formatting import register_unit_format | ||
from .registry import ApplicationRegistry, LazyRegistry, UnitRegistry | ||
from .util import logger, pi_theorem # noqa: F401 | ||
|
||
# Default Quantity, Unit and Measurement are the ones | ||
# build in the default registry. | ||
Quantity = UnitRegistry.Quantity | ||
Unit = UnitRegistry.Unit | ||
Measurement = UnitRegistry.Measurement | ||
Context = UnitRegistry.Context | ||
Group = UnitRegistry.Group | ||
|
||
try: # pragma: no cover | ||
__version__ = version("pint") | ||
except Exception: # pragma: no cover | ||
# we seem to have a local copy not installed without setuptools | ||
# so the reported version will be unknown | ||
__version__ = "unknown" | ||
|
||
|
||
#: A Registry with the default units and constants. | ||
_DEFAULT_REGISTRY = LazyRegistry() | ||
|
||
#: Registry used for unpickling operations. | ||
application_registry = ApplicationRegistry(_DEFAULT_REGISTRY) | ||
|
||
|
||
def _unpickle(cls, *args): | ||
"""Rebuild object upon unpickling. | ||
All units must exist in the application registry. | ||
Parameters | ||
---------- | ||
cls : Quantity, Magnitude, or Unit | ||
*args | ||
Returns | ||
------- | ||
object of type cls | ||
""" | ||
from datasette.vendored.pint.util import UnitsContainer | ||
|
||
for arg in args: | ||
# Prefixed units are defined within the registry | ||
# on parsing (which does not happen here). | ||
# We need to make sure that this happens before using. | ||
if isinstance(arg, UnitsContainer): | ||
for name in arg: | ||
application_registry.parse_units(name) | ||
|
||
return cls(*args) | ||
|
||
|
||
def _unpickle_quantity(cls, *args): | ||
"""Rebuild quantity upon unpickling using the application registry.""" | ||
return _unpickle(application_registry.Quantity, *args) | ||
|
||
|
||
def _unpickle_unit(cls, *args): | ||
"""Rebuild unit upon unpickling using the application registry.""" | ||
return _unpickle(application_registry.Unit, *args) | ||
|
||
|
||
def _unpickle_measurement(cls, *args): | ||
"""Rebuild measurement upon unpickling using the application registry.""" | ||
return _unpickle(application_registry.Measurement, *args) | ||
|
||
|
||
def set_application_registry(registry): | ||
"""Set the application registry, which is used for unpickling operations | ||
and when invoking pint.Quantity or pint.Unit directly. | ||
Parameters | ||
---------- | ||
registry : pint.UnitRegistry | ||
""" | ||
application_registry.set(registry) | ||
|
||
|
||
def get_application_registry(): | ||
"""Return the application registry. If :func:`set_application_registry` was never | ||
invoked, return a registry built using :file:`defaults_en.txt` embedded in the pint | ||
package. | ||
Returns | ||
------- | ||
pint.UnitRegistry | ||
""" | ||
return application_registry | ||
|
||
|
||
# Enumerate all user-facing objects | ||
# Hint to intersphinx that, when building objects.inv, these objects must be registered | ||
# under the top-level module and not in their original submodules | ||
__all__ = ( | ||
"Measurement", | ||
"Quantity", | ||
"Unit", | ||
"UnitRegistry", | ||
"PintError", | ||
"DefinitionSyntaxError", | ||
"LogarithmicUnitCalculusError", | ||
"DimensionalityError", | ||
"OffsetUnitCalculusError", | ||
"RedefinitionError", | ||
"UndefinedUnitError", | ||
"UnitStrippedWarning", | ||
"formatter", | ||
"get_application_registry", | ||
"set_application_registry", | ||
"register_unit_format", | ||
"pi_theorem", | ||
"__version__", | ||
"Context", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Callable | ||
from decimal import Decimal | ||
from fractions import Fraction | ||
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union | ||
|
||
from .compat import Never, TypeAlias | ||
|
||
if TYPE_CHECKING: | ||
from .facets.plain import PlainQuantity as Quantity | ||
from .facets.plain import PlainUnit as Unit | ||
from .util import UnitsContainer | ||
|
||
|
||
HAS_NUMPY = False | ||
if TYPE_CHECKING: | ||
from .compat import HAS_NUMPY | ||
|
||
if HAS_NUMPY: | ||
from .compat import np | ||
|
||
Scalar: TypeAlias = Union[float, int, Decimal, Fraction, np.number[Any]] | ||
Array = np.ndarray[Any, Any] | ||
else: | ||
Scalar: TypeAlias = Union[float, int, Decimal, Fraction] | ||
Array: TypeAlias = Never | ||
|
||
# TODO: Change when Python 3.10 becomes minimal version. | ||
Magnitude = Union[Scalar, Array] | ||
|
||
UnitLike = Union[str, dict[str, Scalar], "UnitsContainer", "Unit"] | ||
|
||
QuantityOrUnitLike = Union["Quantity", UnitLike] | ||
|
||
Shape = tuple[int, ...] | ||
|
||
S = TypeVar("S") | ||
|
||
FuncType = Callable[..., Any] | ||
F = TypeVar("F", bound=FuncType) | ||
|
||
|
||
# TODO: Improve or delete types | ||
QuantityArgument = Any | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class Handler(Protocol): | ||
def __getitem__(self, item: type[T]) -> Callable[[T], None]: ... |
Oops, something went wrong.