TypedUnit 0.0.11__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {typedunit-0.0.11 → typedunit-0.2.4}/.github/dependabot.yml +1 -2
- typedunit-0.2.4/.github/workflows/deploy_PyPi.yml +18 -0
- typedunit-0.2.4/.github/workflows/deploy_anaconda.yml +21 -0
- typedunit-0.2.4/.github/workflows/deploy_coverage.yml +21 -0
- typedunit-0.2.4/.github/workflows/deploy_documentation.yml +58 -0
- typedunit-0.2.4/.github/workflows/quality.yml +22 -0
- typedunit-0.2.4/.github/workflows/tests.yml +26 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/.gitignore +7 -1
- typedunit-0.2.4/CONTRIBUTING.md +7 -0
- typedunit-0.2.4/Makefile +15 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/PKG-INFO +4 -4
- {typedunit-0.0.11 → typedunit-0.2.4}/README.rst +0 -2
- typedunit-0.2.4/TypedUnit/__init__.py +10 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit/_version.py +3 -3
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit/directories.py +10 -10
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit/helper.py +19 -7
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit/units.py +4 -6
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit.egg-info/PKG-INFO +4 -4
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit.egg-info/SOURCES.txt +14 -2
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit.egg-info/requires.txt +2 -1
- typedunit-0.2.4/TypedUnit.egg-info/scm_file_list.json +50 -0
- typedunit-0.2.4/TypedUnit.egg-info/scm_version.json +8 -0
- {typedunit-0.0.11 → typedunit-0.2.4/conda.recipe}/meta.yaml +3 -2
- typedunit-0.2.4/docs/redirect.html +12 -0
- typedunit-0.2.4/docs/source/_static/favicon.svg +1 -0
- typedunit-0.2.4/docs/source/_static/layout.css +89 -0
- typedunit-0.2.4/docs/source/_static/logo.svg +1 -0
- typedunit-0.2.4/docs/source/conf.py +27 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/pyproject.toml +11 -1
- {typedunit-0.0.11 → typedunit-0.2.4}/tests/test_0.py +17 -16
- typedunit-0.2.4/tools/next_release_version.py +33 -0
- typedunit-0.2.4/tools/release_tag.py +46 -0
- typedunit-0.0.11/.github/workflows/deploy_PyPi.yml +0 -20
- typedunit-0.0.11/.github/workflows/deploy_anaconda.yml +0 -21
- typedunit-0.0.11/.github/workflows/deploy_coverage.yml +0 -25
- typedunit-0.0.11/.github/workflows/deploy_documentation.yml +0 -24
- typedunit-0.0.11/TypedUnit/__init__.py +0 -9
- typedunit-0.0.11/docs/source/conf.py +0 -167
- {typedunit-0.0.11 → typedunit-0.2.4}/.coveragerc +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/.flake8 +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/.pre-commit-config.yaml +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/LICENSE +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit/utils.py +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit.egg-info/dependency_links.txt +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/TypedUnit.egg-info/top_level.txt +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/Makefile +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/examples/README.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/examples/example_0.py +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/examples/example_1.py +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/images/logo.png +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/make.bat +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/_static/default.css +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/_static/thumbnail.png +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/code.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/index.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/references.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/sg_execution_times.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/docs/source/theory.rst +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/pytest.ini +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/setup.cfg +0 -0
- {typedunit-0.0.11 → typedunit-0.2.4}/tests/__init__.py +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
uses: MartinPdeS/MPSActions/.github/workflows/publish_pure_package_to_PyPi.yml@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
13
|
+
with:
|
|
14
|
+
python-version: "3.11"
|
|
15
|
+
# The reusable workflow wraps this command in double quotes.
|
|
16
|
+
test-command: python -c 'import TypedUnit; print(TypedUnit.__version__)'
|
|
17
|
+
secrets:
|
|
18
|
+
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Publish Conda package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
uses: MartinPdeS/MPSActions/.github/workflows/publish_compiled_package_to_anaconda.yml@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
13
|
+
with:
|
|
14
|
+
# One noarch archive supports all declared Python versions; test it on 3.14.
|
|
15
|
+
python_versions: '["3.14"]'
|
|
16
|
+
os_list: '["ubuntu-latest"]'
|
|
17
|
+
package_name: typedunit
|
|
18
|
+
recipe_path: conda.recipe
|
|
19
|
+
test_import: TypedUnit
|
|
20
|
+
secrets:
|
|
21
|
+
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Publish coverage
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
pull-requests: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
coverage:
|
|
15
|
+
uses: MartinPdeS/MPSActions/.github/workflows/publish_coverage.yml@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.11"
|
|
18
|
+
apt-package: xvfb
|
|
19
|
+
coverage-package: TypedUnit
|
|
20
|
+
secrets:
|
|
21
|
+
_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Publish documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
pages: write
|
|
11
|
+
id-token: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
documentation:
|
|
15
|
+
uses: MartinPdeS/MPSActions/.github/workflows/publish_documentation.yml@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.11"
|
|
18
|
+
package-name: TypedUnit
|
|
19
|
+
apt-package: xvfb jq
|
|
20
|
+
|
|
21
|
+
maintain_documentation:
|
|
22
|
+
needs: documentation
|
|
23
|
+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }}
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- name: Install documentation landing page
|
|
27
|
+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
|
|
28
|
+
with:
|
|
29
|
+
ref: documentation_page
|
|
30
|
+
fetch-depth: 0
|
|
31
|
+
- run: |
|
|
32
|
+
set -Eeuo pipefail
|
|
33
|
+
git show "${GITHUB_SHA}:docs/redirect.html" > index.html
|
|
34
|
+
test -s docs/latest/index.html
|
|
35
|
+
git config user.name "github-actions[bot]"
|
|
36
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
37
|
+
git add index.html
|
|
38
|
+
if git diff --cached --quiet; then exit 0; fi
|
|
39
|
+
git commit -m "Update documentation landing page [skip ci]"
|
|
40
|
+
git push origin HEAD:documentation_page
|
|
41
|
+
|
|
42
|
+
publish_pages:
|
|
43
|
+
needs: maintain_documentation
|
|
44
|
+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }}
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
environment:
|
|
47
|
+
name: github-pages
|
|
48
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09
|
|
51
|
+
with:
|
|
52
|
+
ref: documentation_page
|
|
53
|
+
- uses: actions/configure-pages@v5
|
|
54
|
+
- uses: actions/upload-pages-artifact@v3
|
|
55
|
+
with:
|
|
56
|
+
path: .
|
|
57
|
+
- id: deployment
|
|
58
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Static quality checks
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
quality:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Set up Python and CI dependencies
|
|
17
|
+
uses: MartinPdeS/MPSActions/actions/setup-python@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.11"
|
|
20
|
+
install-command: >-
|
|
21
|
+
python -m pip install --upgrade pip && python -m pip install "ruff>=0.6,<1"
|
|
22
|
+
- run: python -m ruff check TypedUnit tests
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [master]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
tests:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.11", "3.14"]
|
|
19
|
+
steps:
|
|
20
|
+
- name: Set up Python and CI dependencies
|
|
21
|
+
uses: MartinPdeS/MPSActions/actions/setup-python@a01969bc5af90666281f9d37acffdf6a4629763a
|
|
22
|
+
with:
|
|
23
|
+
python-version: "${{ matrix.python-version }}"
|
|
24
|
+
install-command: >-
|
|
25
|
+
python -m pip install --upgrade pip && python -m pip install -e ".[testing]"
|
|
26
|
+
- run: python -m pytest -q
|
|
@@ -14,9 +14,14 @@
|
|
|
14
14
|
!.gitignore
|
|
15
15
|
!.pre-commit-config.yaml
|
|
16
16
|
!LICENSE
|
|
17
|
-
!
|
|
17
|
+
!conda.recipe
|
|
18
|
+
!conda.recipe/meta.yaml
|
|
18
19
|
!pyproject.toml
|
|
19
20
|
!README.rst
|
|
21
|
+
!CONTRIBUTING.md
|
|
22
|
+
!/Makefile
|
|
23
|
+
!tools
|
|
24
|
+
!tools/*.py
|
|
20
25
|
!notebook.ipynb
|
|
21
26
|
!CMakeLists.txt
|
|
22
27
|
!pytest.ini
|
|
@@ -31,5 +36,6 @@ docs/source/gallery/
|
|
|
31
36
|
*.DS_Store*
|
|
32
37
|
*.so*
|
|
33
38
|
*.a*
|
|
39
|
+
!Makefile
|
|
34
40
|
|
|
35
41
|
# Package specifics
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Contributing to TypedUnit
|
|
2
|
+
|
|
3
|
+
Use Python 3.10 or newer. Install development dependencies with `python -m pip install -e ".[testing,documentation]"`, then run `python -m pytest`.
|
|
4
|
+
|
|
5
|
+
Releases use semantic version tags. Run `make patch`, `make minor`, or `make major` from a clean `master` checkout; the command creates the release commit, tags it, and pushes both. Publishing workflows run only for `v*` tags.
|
|
6
|
+
|
|
7
|
+
The Conda recipe is at `conda.recipe/meta.yaml`. Do not commit generated documentation, virtual environments, build artefacts, or caches.
|
typedunit-0.2.4/Makefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
PYTHON ?= python3
|
|
2
|
+
|
|
3
|
+
.PHONY: release tag patch minor major
|
|
4
|
+
|
|
5
|
+
release:
|
|
6
|
+
@set -eu; release_tag="$$( $(PYTHON) tools/next_release_version.py $(BUMP) )"; \
|
|
7
|
+
$(PYTHON) tools/release_tag.py "$$release_tag"; \
|
|
8
|
+
git push origin HEAD "refs/tags/$$release_tag"
|
|
9
|
+
|
|
10
|
+
tag:
|
|
11
|
+
@set -eu; release_tag="$$( $(PYTHON) tools/next_release_version.py $(BUMP) )"; \
|
|
12
|
+
$(PYTHON) tools/release_tag.py "$$release_tag"
|
|
13
|
+
|
|
14
|
+
patch minor major:
|
|
15
|
+
@$(MAKE) release BUMP=$@
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TypedUnit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A package wrapping pint for handling typed units in Python.
|
|
5
5
|
Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -33,6 +33,7 @@ Classifier: Programming Language :: Python
|
|
|
33
33
|
Classifier: Programming Language :: Python :: 3
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.11
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.12
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
37
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
37
38
|
Classifier: Development Status :: 4 - Beta
|
|
38
39
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
@@ -41,7 +42,7 @@ Classifier: Intended Audience :: Science/Research
|
|
|
41
42
|
Requires-Python: >=3.10
|
|
42
43
|
Description-Content-Type: text/x-rst
|
|
43
44
|
License-File: LICENSE
|
|
44
|
-
Requires-Dist: pint
|
|
45
|
+
Requires-Dist: pint<0.26,>=0.24
|
|
45
46
|
Requires-Dist: numpy
|
|
46
47
|
Requires-Dist: matplotlib
|
|
47
48
|
Requires-Dist: pint_pandas
|
|
@@ -52,6 +53,7 @@ Requires-Dist: pytest-json-report~=1.5; extra == "testing"
|
|
|
52
53
|
Requires-Dist: flake8==7.3.0; extra == "testing"
|
|
53
54
|
Requires-Dist: coverage~=7.6; extra == "testing"
|
|
54
55
|
Provides-Extra: documentation
|
|
56
|
+
Requires-Dist: MartinPdeS-docs<0.2,>=0.1.4; extra == "documentation"
|
|
55
57
|
Requires-Dist: numpydoc~=1.8; extra == "documentation"
|
|
56
58
|
Requires-Dist: sphinx>=6; extra == "documentation"
|
|
57
59
|
Requires-Dist: sphinx-gallery~=0.17; extra == "documentation"
|
|
@@ -240,8 +242,6 @@ TypedUnits is open source and contributions are welcome! Whether you're fixing b
|
|
|
240
242
|
|
|
241
243
|
**Email:** `martin.poinsinet-de-sivry@polymtl.ca <mailto:martin.poinsinet-de-sivry@polymtl.ca?subject=TypedUnits>`_
|
|
242
244
|
|
|
243
|
-
----
|
|
244
|
-
|
|
245
245
|
.. |python| image:: https://img.shields.io/pypi/pyversions/typedunits.svg
|
|
246
246
|
:target: https://www.python.org/
|
|
247
247
|
:alt: Python version
|
|
@@ -179,8 +179,6 @@ TypedUnits is open source and contributions are welcome! Whether you're fixing b
|
|
|
179
179
|
|
|
180
180
|
**Email:** `martin.poinsinet-de-sivry@polymtl.ca <mailto:martin.poinsinet-de-sivry@polymtl.ca?subject=TypedUnits>`_
|
|
181
181
|
|
|
182
|
-
----
|
|
183
|
-
|
|
184
182
|
.. |python| image:: https://img.shields.io/pypi/pyversions/typedunits.svg
|
|
185
183
|
:target: https://www.python.org/
|
|
186
184
|
:alt: Python version
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
try:
|
|
2
|
+
from ._version import __version__ as __version__
|
|
3
|
+
|
|
4
|
+
except ImportError:
|
|
5
|
+
__version__ = "0.0.0"
|
|
6
|
+
|
|
7
|
+
from TypedUnit.helper import validate_units as validate_units
|
|
8
|
+
from TypedUnit.units import * # noqa: F403 -- Re-export the unit module's public types.
|
|
9
|
+
from TypedUnit.units import Quantity as Quantity
|
|
10
|
+
from TypedUnit.units import ureg as ureg
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.
|
|
22
|
-
__version_tuple__ = version_tuple = (0,
|
|
21
|
+
__version__ = version = '0.2.4'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 2, 4)
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id = '
|
|
24
|
+
__commit_id__ = commit_id = 'g8caa1b260'
|
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
import TypedUnit
|
|
6
5
|
|
|
6
|
+
import TypedUnit
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
"root_path",
|
|
10
|
+
"project_path",
|
|
11
|
+
"doc_path",
|
|
12
|
+
"doc_css_path",
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
root_path = Path(TypedUnit.__path__[0])
|
|
16
16
|
|
|
17
17
|
project_path = root_path.parents[0]
|
|
18
18
|
|
|
19
|
-
example_directory = root_path.joinpath(
|
|
19
|
+
example_directory = root_path.joinpath("examples")
|
|
20
20
|
|
|
21
|
-
doc_path = project_path.joinpath(
|
|
21
|
+
doc_path = project_path.joinpath("docs")
|
|
22
22
|
|
|
23
|
-
examples_path = project_path.joinpath(
|
|
23
|
+
examples_path = project_path.joinpath("docs/examples")
|
|
24
24
|
|
|
25
|
-
doc_css_path = doc_path.joinpath(
|
|
25
|
+
doc_css_path = doc_path.joinpath("source/_static/default.css")
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
if __name__ ==
|
|
28
|
+
if __name__ == "__main__":
|
|
29
29
|
for path_name in __all__:
|
|
30
30
|
path = locals()[path_name]
|
|
31
31
|
print(path)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
from TypedUnit.units import BaseUnit
|
|
2
|
-
from typing import get_type_hints, get_origin, get_args, Union
|
|
3
1
|
import inspect
|
|
2
|
+
from typing import Union, get_args, get_origin, get_type_hints
|
|
3
|
+
|
|
4
|
+
from TypedUnit.units import BaseUnit
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
def _get_unit_type(hint):
|
|
6
8
|
"""Extract BaseUnit type from hint, handling Optional and List."""
|
|
@@ -14,16 +16,25 @@ def _get_unit_type(hint):
|
|
|
14
16
|
if origin is Union:
|
|
15
17
|
# Handle Optional[BaseUnit] (Union[BaseUnit, None])
|
|
16
18
|
unit_types = [arg for arg in args if arg is not type(None)]
|
|
17
|
-
if
|
|
19
|
+
if (
|
|
20
|
+
len(unit_types) == 1
|
|
21
|
+
and inspect.isclass(unit_types[0])
|
|
22
|
+
and issubclass(unit_types[0], BaseUnit)
|
|
23
|
+
):
|
|
18
24
|
return unit_types[0], True, False # Optional BaseUnit
|
|
19
25
|
|
|
20
26
|
elif origin in (list, tuple):
|
|
21
27
|
# Handle List[BaseUnit] or Tuple[BaseUnit]
|
|
22
|
-
if
|
|
28
|
+
if (
|
|
29
|
+
len(args) == 1
|
|
30
|
+
and inspect.isclass(args[0])
|
|
31
|
+
and issubclass(args[0], BaseUnit)
|
|
32
|
+
):
|
|
23
33
|
return args[0], False, True # List of BaseUnit
|
|
24
34
|
|
|
25
35
|
return None, False, False
|
|
26
36
|
|
|
37
|
+
|
|
27
38
|
def validate_units(function):
|
|
28
39
|
def wrapper(*args, **kwargs):
|
|
29
40
|
hints = get_type_hints(function)
|
|
@@ -55,13 +66,14 @@ def validate_units(function):
|
|
|
55
66
|
try:
|
|
56
67
|
unit_type.check(item)
|
|
57
68
|
except (AssertionError, ValueError) as e:
|
|
58
|
-
raise ValueError(f"Parameter '{param_name}[{i}]': {e}")
|
|
69
|
+
raise ValueError(f"Parameter '{param_name}[{i}]': {e}") from e
|
|
59
70
|
else:
|
|
60
71
|
# Handle single values
|
|
61
72
|
try:
|
|
62
73
|
unit_type.check(value)
|
|
63
74
|
except (AssertionError, ValueError) as e:
|
|
64
|
-
raise ValueError(f"Parameter '{param_name}': {e}")
|
|
75
|
+
raise ValueError(f"Parameter '{param_name}': {e}") from e
|
|
65
76
|
|
|
66
77
|
return function(*args, **kwargs)
|
|
67
|
-
|
|
78
|
+
|
|
79
|
+
return wrapper
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Initialize a unit registry
|
|
2
2
|
import pint as _pint
|
|
3
|
+
import pint_pandas as pint # noqa: F401 -- Registers the pandas Pint extension.
|
|
3
4
|
from pint import Quantity, UnitRegistry
|
|
4
|
-
import pint_pandas as pint
|
|
5
5
|
|
|
6
6
|
ureg = UnitRegistry(autoconvert_offset_to_baseunit=True)
|
|
7
7
|
ureg.setup_matplotlib()
|
|
@@ -65,7 +65,7 @@ class UnitMeta(type):
|
|
|
65
65
|
num = cls.__name__
|
|
66
66
|
den = other.__name__
|
|
67
67
|
name = f"{num}Per{den}"
|
|
68
|
-
expected = f"{
|
|
68
|
+
expected = f"{cls._expected_dim}/{other._expected_dim}"
|
|
69
69
|
# Create a new subclass that uses the same metaclass
|
|
70
70
|
return UnitMeta(name, (BaseUnit,), {"_expected_dim": expected})
|
|
71
71
|
|
|
@@ -76,16 +76,14 @@ class UnitMeta(type):
|
|
|
76
76
|
a = cls.__name__
|
|
77
77
|
b = other.__name__
|
|
78
78
|
name = f"{a}Times{b}"
|
|
79
|
-
expected = (
|
|
80
|
-
f"({getattr(cls, '_expected_dim')})*({getattr(other, '_expected_dim')})"
|
|
81
|
-
)
|
|
79
|
+
expected = f"({cls._expected_dim})*({other._expected_dim})"
|
|
82
80
|
return UnitMeta(name, (BaseUnit,), {"_expected_dim": expected})
|
|
83
81
|
|
|
84
82
|
def __pow__(cls, power):
|
|
85
83
|
if not isinstance(power, int):
|
|
86
84
|
return NotImplemented
|
|
87
85
|
name = f"{cls.__name__}Pow{power}"
|
|
88
|
-
expected = f"({
|
|
86
|
+
expected = f"({cls._expected_dim})**{power}"
|
|
89
87
|
return UnitMeta(name, (BaseUnit,), {"_expected_dim": expected})
|
|
90
88
|
|
|
91
89
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TypedUnit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A package wrapping pint for handling typed units in Python.
|
|
5
5
|
Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -33,6 +33,7 @@ Classifier: Programming Language :: Python
|
|
|
33
33
|
Classifier: Programming Language :: Python :: 3
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.11
|
|
35
35
|
Classifier: Programming Language :: Python :: 3.12
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
37
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
37
38
|
Classifier: Development Status :: 4 - Beta
|
|
38
39
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
@@ -41,7 +42,7 @@ Classifier: Intended Audience :: Science/Research
|
|
|
41
42
|
Requires-Python: >=3.10
|
|
42
43
|
Description-Content-Type: text/x-rst
|
|
43
44
|
License-File: LICENSE
|
|
44
|
-
Requires-Dist: pint
|
|
45
|
+
Requires-Dist: pint<0.26,>=0.24
|
|
45
46
|
Requires-Dist: numpy
|
|
46
47
|
Requires-Dist: matplotlib
|
|
47
48
|
Requires-Dist: pint_pandas
|
|
@@ -52,6 +53,7 @@ Requires-Dist: pytest-json-report~=1.5; extra == "testing"
|
|
|
52
53
|
Requires-Dist: flake8==7.3.0; extra == "testing"
|
|
53
54
|
Requires-Dist: coverage~=7.6; extra == "testing"
|
|
54
55
|
Provides-Extra: documentation
|
|
56
|
+
Requires-Dist: MartinPdeS-docs<0.2,>=0.1.4; extra == "documentation"
|
|
55
57
|
Requires-Dist: numpydoc~=1.8; extra == "documentation"
|
|
56
58
|
Requires-Dist: sphinx>=6; extra == "documentation"
|
|
57
59
|
Requires-Dist: sphinx-gallery~=0.17; extra == "documentation"
|
|
@@ -240,8 +242,6 @@ TypedUnits is open source and contributions are welcome! Whether you're fixing b
|
|
|
240
242
|
|
|
241
243
|
**Email:** `martin.poinsinet-de-sivry@polymtl.ca <mailto:martin.poinsinet-de-sivry@polymtl.ca?subject=TypedUnits>`_
|
|
242
244
|
|
|
243
|
-
----
|
|
244
|
-
|
|
245
245
|
.. |python| image:: https://img.shields.io/pypi/pyversions/typedunits.svg
|
|
246
246
|
:target: https://www.python.org/
|
|
247
247
|
:alt: Python version
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
.flake8
|
|
3
3
|
.gitignore
|
|
4
4
|
.pre-commit-config.yaml
|
|
5
|
+
CONTRIBUTING.md
|
|
5
6
|
LICENSE
|
|
7
|
+
Makefile
|
|
6
8
|
README.rst
|
|
7
|
-
meta.yaml
|
|
8
9
|
pyproject.toml
|
|
9
10
|
pytest.ini
|
|
10
11
|
.github/dependabot.yml
|
|
@@ -12,6 +13,8 @@ pytest.ini
|
|
|
12
13
|
.github/workflows/deploy_anaconda.yml
|
|
13
14
|
.github/workflows/deploy_coverage.yml
|
|
14
15
|
.github/workflows/deploy_documentation.yml
|
|
16
|
+
.github/workflows/quality.yml
|
|
17
|
+
.github/workflows/tests.yml
|
|
15
18
|
TypedUnit/__init__.py
|
|
16
19
|
TypedUnit/_version.py
|
|
17
20
|
TypedUnit/directories.py
|
|
@@ -22,9 +25,13 @@ TypedUnit.egg-info/PKG-INFO
|
|
|
22
25
|
TypedUnit.egg-info/SOURCES.txt
|
|
23
26
|
TypedUnit.egg-info/dependency_links.txt
|
|
24
27
|
TypedUnit.egg-info/requires.txt
|
|
28
|
+
TypedUnit.egg-info/scm_file_list.json
|
|
29
|
+
TypedUnit.egg-info/scm_version.json
|
|
25
30
|
TypedUnit.egg-info/top_level.txt
|
|
31
|
+
conda.recipe/meta.yaml
|
|
26
32
|
docs/Makefile
|
|
27
33
|
docs/make.bat
|
|
34
|
+
docs/redirect.html
|
|
28
35
|
docs/examples/README.rst
|
|
29
36
|
docs/examples/example_0.py
|
|
30
37
|
docs/examples/example_1.py
|
|
@@ -36,6 +43,11 @@ docs/source/references.rst
|
|
|
36
43
|
docs/source/sg_execution_times.rst
|
|
37
44
|
docs/source/theory.rst
|
|
38
45
|
docs/source/_static/default.css
|
|
46
|
+
docs/source/_static/favicon.svg
|
|
47
|
+
docs/source/_static/layout.css
|
|
48
|
+
docs/source/_static/logo.svg
|
|
39
49
|
docs/source/_static/thumbnail.png
|
|
40
50
|
tests/__init__.py
|
|
41
|
-
tests/test_0.py
|
|
51
|
+
tests/test_0.py
|
|
52
|
+
tools/next_release_version.py
|
|
53
|
+
tools/release_tag.py
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": [
|
|
3
|
+
".coveragerc",
|
|
4
|
+
".flake8",
|
|
5
|
+
".github/dependabot.yml",
|
|
6
|
+
".github/workflows/deploy_PyPi.yml",
|
|
7
|
+
".github/workflows/deploy_anaconda.yml",
|
|
8
|
+
".github/workflows/deploy_coverage.yml",
|
|
9
|
+
".github/workflows/deploy_documentation.yml",
|
|
10
|
+
".github/workflows/quality.yml",
|
|
11
|
+
".github/workflows/tests.yml",
|
|
12
|
+
".gitignore",
|
|
13
|
+
".pre-commit-config.yaml",
|
|
14
|
+
"CONTRIBUTING.md",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"Makefile",
|
|
17
|
+
"README.rst",
|
|
18
|
+
"TypedUnit/__init__.py",
|
|
19
|
+
"TypedUnit/_version.py",
|
|
20
|
+
"TypedUnit/directories.py",
|
|
21
|
+
"TypedUnit/helper.py",
|
|
22
|
+
"TypedUnit/units.py",
|
|
23
|
+
"TypedUnit/utils.py",
|
|
24
|
+
"conda.recipe/meta.yaml",
|
|
25
|
+
"docs/Makefile",
|
|
26
|
+
"docs/examples/README.rst",
|
|
27
|
+
"docs/examples/example_0.py",
|
|
28
|
+
"docs/examples/example_1.py",
|
|
29
|
+
"docs/images/logo.png",
|
|
30
|
+
"docs/make.bat",
|
|
31
|
+
"docs/redirect.html",
|
|
32
|
+
"docs/source/_static/default.css",
|
|
33
|
+
"docs/source/_static/favicon.svg",
|
|
34
|
+
"docs/source/_static/layout.css",
|
|
35
|
+
"docs/source/_static/logo.svg",
|
|
36
|
+
"docs/source/_static/thumbnail.png",
|
|
37
|
+
"docs/source/code.rst",
|
|
38
|
+
"docs/source/conf.py",
|
|
39
|
+
"docs/source/index.rst",
|
|
40
|
+
"docs/source/references.rst",
|
|
41
|
+
"docs/source/sg_execution_times.rst",
|
|
42
|
+
"docs/source/theory.rst",
|
|
43
|
+
"pyproject.toml",
|
|
44
|
+
"pytest.ini",
|
|
45
|
+
"tests/__init__.py",
|
|
46
|
+
"tests/test_0.py",
|
|
47
|
+
"tools/next_release_version.py",
|
|
48
|
+
"tools/release_tag.py"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
@@ -3,7 +3,7 @@ package:
|
|
|
3
3
|
version: {{ GIT_DESCRIBE_TAG | replace("v", "") }}
|
|
4
4
|
|
|
5
5
|
source:
|
|
6
|
-
|
|
6
|
+
path: ..
|
|
7
7
|
|
|
8
8
|
build:
|
|
9
9
|
noarch: python
|
|
@@ -22,6 +22,7 @@ requirements:
|
|
|
22
22
|
- setuptools-scm >=8.0
|
|
23
23
|
- pip
|
|
24
24
|
run:
|
|
25
|
+
- python >=3.10
|
|
25
26
|
- pint
|
|
26
27
|
- numpy
|
|
27
28
|
- matplotlib
|
|
@@ -49,7 +50,7 @@ test:
|
|
|
49
50
|
- pytest >=0.6
|
|
50
51
|
- pytest-cov >=2.0
|
|
51
52
|
- pytest-json-report ~=1.5.0
|
|
52
|
-
- coverage
|
|
53
|
+
- coverage >=7.10,<8
|
|
53
54
|
commands:
|
|
54
55
|
- python -m pytest
|
|
55
56
|
source_files:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="refresh" content="0; url=docs/latest/index.html">
|
|
6
|
+
<link rel="canonical" href="docs/latest/index.html">
|
|
7
|
+
<title>TypedUnit documentation</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<p>Opening the <a href="docs/latest/index.html">TypedUnit documentation</a>.</p>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><circle cx="32" cy="32" r="29" fill="#172033"/><rect x="13" y="25" width="24" height="24" rx="5" fill="#6366f1"/><rect x="28" y="15" width="24" height="24" rx="5" fill="#22d3ee" opacity=".9"/></svg>
|