-
Notifications
You must be signed in to change notification settings - Fork 6
Migrate build to pyproject.toml #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ coverage.xml | |
| *.cover | ||
| .hypothesis/ | ||
| .pytest_cache/ | ||
| prof/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "2.2.0" | ||
| __version__ = "2.2.1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,25 @@ | ||
| """Implementation of units.""" | ||
| from deprecation import deprecated | ||
| import functools | ||
| from importlib_resources import files | ||
| from importlib.resources import files | ||
| import os | ||
| from pathlib import Path | ||
| import re | ||
| from tempfile import TemporaryDirectory | ||
| from typing import Union, List, Tuple, Generator, Any | ||
| try: | ||
| from typing import TypeAlias # Python 3.10+ | ||
| except ImportError: # pragma nocover | ||
| from typing_extensions import TypeAlias # Python 3.9 | ||
|
Comment on lines
10
to
13
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only residual bit of dependency from the python-dependent subclassing. Removable with 3.10. |
||
|
|
||
| from pint import UnitRegistry, register_unit_format | ||
| try: # Pint 0.23 migrated the location of this method, and augmented it | ||
| from pint.pint_eval import tokenizer | ||
| except ImportError: # pragma: no cover | ||
| from pint.compat import tokenizer | ||
| from pint.pint_eval import tokenizer | ||
| from tokenize import NAME, NUMBER, OP, ERRORTOKEN, TokenInfo | ||
| # alias the error that is thrown when units are incompatible | ||
| # this helps to isolate the dependence on pint | ||
| from pint.errors import DimensionalityError as IncompatibleUnitsError # noqa Import | ||
| from pint.errors import UndefinedUnitError, DefinitionSyntaxError # noqa Import | ||
| from pint.errors import DimensionalityError as IncompatibleUnitsError | ||
| from pint.errors import UndefinedUnitError, DefinitionSyntaxError | ||
| from pint.registry import GenericUnitRegistry | ||
|
|
||
| # Store directories so they don't get auto-cleaned until exit | ||
| _TEMP_DIRECTORY = TemporaryDirectory() | ||
|
|
@@ -216,43 +218,29 @@ def _unmangle_scaling(input_string: str) -> str: | |
| return input_string | ||
|
|
||
|
|
||
| try: # pragma: no cover | ||
| # Pint 0.23 modified the preferred way to derive a custom class | ||
| # https://pint.readthedocs.io/en/0.23/advanced/custom-registry-class.html | ||
| from pint.registry import GenericUnitRegistry | ||
| from typing_extensions import TypeAlias | ||
| # Standard approach to creating a custom registry class: | ||
| # https://pint.readthedocs.io/en/0.23/advanced/custom-registry-class.html | ||
|
|
||
| class _ScaleFactorUnit(UnitRegistry.Unit): | ||
| """Child class of Units for generating units w/ clean scaling factors.""" | ||
| class _ScaleFactorUnit(UnitRegistry.Unit): | ||
| """Child class of Units for generating units w/ clean scaling factors.""" | ||
|
|
||
| def __format__(self, format_spec): | ||
| result = super().__format__(format_spec) | ||
| return _unmangle_scaling(result) | ||
| def __format__(self, format_spec): | ||
| result = super().__format__(format_spec) | ||
| return _unmangle_scaling(result) | ||
|
|
||
| class _ScaleFactorQuantity(UnitRegistry.Quantity): | ||
| """Child class of Quantity for generating units w/ clean scaling factors.""" | ||
|
|
||
| pass | ||
|
|
||
| class _ScaleFactorRegistry(GenericUnitRegistry[_ScaleFactorQuantity, _ScaleFactorUnit]): | ||
| """UnitRegistry class that uses _GemdUnits.""" | ||
| class _ScaleFactorQuantity(UnitRegistry.Quantity): | ||
| """Child class of Quantity for generating units w/ clean scaling factors.""" | ||
|
|
||
| Quantity: TypeAlias = _ScaleFactorQuantity | ||
| Unit: TypeAlias = _ScaleFactorUnit | ||
| pass | ||
|
|
||
| except ImportError: # pragma: no cover | ||
| # https://pint.readthedocs.io/en/0.21/advanced/custom-registry-class.html | ||
| class _ScaleFactorUnit(UnitRegistry.Unit): | ||
| """Child class of Units for generating units w/ clean scaling factors.""" | ||
|
|
||
| def __format__(self, format_spec): | ||
| result = super().__format__(format_spec) | ||
| return _unmangle_scaling(result) | ||
| class _ScaleFactorRegistry(GenericUnitRegistry[_ScaleFactorQuantity, _ScaleFactorUnit]): | ||
| """UnitRegistry class that uses _GemdUnits.""" | ||
|
|
||
| class _ScaleFactorRegistry(UnitRegistry): | ||
| """UnitRegistry class that uses _GemdUnits.""" | ||
| Quantity: TypeAlias = _ScaleFactorQuantity | ||
| Unit: TypeAlias = _ScaleFactorUnit | ||
|
|
||
| _unit_class = _ScaleFactorUnit | ||
|
|
||
| _REGISTRY: _ScaleFactorRegistry = None # global requires it be defined in this scope | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| [project] | ||
| name = "gemd" | ||
| dynamic = ["version"] | ||
| dependencies = [ | ||
| "pint>=0.24.4,<0.25", | ||
| "deprecation>=2.1.0,<3", | ||
| "typing_extensions>=4.8,<5; python_version<'3.10'", | ||
| ] | ||
| requires-python = ">=3.9" | ||
| authors = [ | ||
| {name = "Citrine Informatics"} | ||
| ] | ||
| description = "Python binding for Citrine's GEMD data model" | ||
| readme = "README.md" | ||
| license-files = ["LICENSE"] | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.9", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "http://github.com/CitrineInformatics/gemd-python" | ||
|
|
||
| [build-system] | ||
| requires = ["setuptools>=61.0", "wheel"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [tool.setuptools.dynamic] | ||
| version = {attr = "gemd.__version__.__version__"} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woah, this is a small but awesome little feature! |
||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["."] | ||
| include = ["gemd"] | ||
| exclude = ["docs", "tests"] | ||
|
|
||
| [tool.setuptools.package-data] | ||
| "gemd.demo" = ["strehlow_and_cook.pif", "strehlow_and_cook_small.pif", "toothpick.jpg"] | ||
| "gemd.units" = ["citrine_en.txt", "constants_en.txt"] | ||
| "tests.units" = ["test_units.txt"] | ||
|
|
||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "flake8==7.0.0", | ||
| "flake8-docstrings==1.7.0", | ||
| "numpy==1.24.4; python_version<'3.10'", | ||
| "pandas==2.0.3; python_version<'3.10'", | ||
| "numpy>=2.0.2,<=2.1.0; python_version>='3.10'", | ||
| "pandas==2.3.0; python_version>='3.10'", | ||
| "pytest==8.4.2", | ||
| "pytest-cov==7.0.0", | ||
| "derp==0.1.1", | ||
| "tomli>=2.2.1", | ||
| ] | ||
| docs = [ | ||
| "sphinx==5.0.0", | ||
| "sphinx-rtd-theme==1.0.0", | ||
| "sphinxcontrib-apidoc==0.3.0", | ||
| ] | ||
|
|
||
| [tool.pytest.ini_options] | ||
| testpaths = [ | ||
| "tests", | ||
| ] | ||
|
|
||
| [tool.coverage.run] | ||
| omit = [ | ||
| "gemd/demo/*", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| pint==0.24.4 | ||
| deprecation==2.1.0 | ||
| typing-extensions==4.8.0 | ||
| importlib-resources==5.3.0 | ||
| typing_extensions>=4.8,<5; python_version<'3.10' |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,5 @@ max-doc-length = 119 | |
| # D401: Imperative mood requirement basically gets in the way | ||
| ignore = D100,D104,D105,D107,D301,D401 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flake8 can't pull configuration from pyproject.toml, so it remains here. |
||
|
|
||
| [pytest] | ||
| testpaths = tests | ||
|
|
||
| [run] | ||
| omit = gemd/demo/* | ||
| omit = gemd/demo/* | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be removed in a follow up. It's required to pass tests common-gh-actions no longer references tox.ini. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor personal annoyance.