Skip to content

Commit cfa4c9e

Browse files
authored
Migrate build to pyproject.toml (#226)
Migrate build to pyproject.toml, including dropping obsolete code & dependencies.
1 parent 4b9944d commit cfa4c9e

File tree

12 files changed

+108
-116
lines changed

12 files changed

+108
-116
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ coverage.xml
4949
*.cover
5050
.hypothesis/
5151
.pytest_cache/
52+
prof/
5253

5354
# Translations
5455
*.mo

gemd/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.2.0"
1+
__version__ = "2.2.1"

gemd/demo/cake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Bake a cake."""
2-
from importlib_resources import files
2+
from importlib.resources import files
33
from io import BytesIO
44
import random
55

gemd/demo/strehlow_and_cook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
def import_table(filename=SMALL_TABLE):
4747
"""Return the deserialized JSON table."""
48-
from importlib_resources import files
48+
from importlib.resources import files
4949
import json
5050

5151
return json.loads(files("gemd.demo").joinpath(filename).read_text(encoding='utf-8'))

gemd/units/impl.py

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
"""Implementation of units."""
22
from deprecation import deprecated
33
import functools
4-
from importlib_resources import files
4+
from importlib.resources import files
55
import os
66
from pathlib import Path
77
import re
88
from tempfile import TemporaryDirectory
99
from typing import Union, List, Tuple, Generator, Any
10+
try:
11+
from typing import TypeAlias # Python 3.10+
12+
except ImportError: # pragma nocover
13+
from typing_extensions import TypeAlias # Python 3.9
1014

1115
from pint import UnitRegistry, register_unit_format
12-
try: # Pint 0.23 migrated the location of this method, and augmented it
13-
from pint.pint_eval import tokenizer
14-
except ImportError: # pragma: no cover
15-
from pint.compat import tokenizer
16+
from pint.pint_eval import tokenizer
1617
from tokenize import NAME, NUMBER, OP, ERRORTOKEN, TokenInfo
1718
# alias the error that is thrown when units are incompatible
1819
# this helps to isolate the dependence on pint
19-
from pint.errors import DimensionalityError as IncompatibleUnitsError # noqa Import
20-
from pint.errors import UndefinedUnitError, DefinitionSyntaxError # noqa Import
20+
from pint.errors import DimensionalityError as IncompatibleUnitsError
21+
from pint.errors import UndefinedUnitError, DefinitionSyntaxError
22+
from pint.registry import GenericUnitRegistry
2123

2224
# Store directories so they don't get auto-cleaned until exit
2325
_TEMP_DIRECTORY = TemporaryDirectory()
@@ -216,43 +218,29 @@ def _unmangle_scaling(input_string: str) -> str:
216218
return input_string
217219

218220

219-
try: # pragma: no cover
220-
# Pint 0.23 modified the preferred way to derive a custom class
221-
# https://pint.readthedocs.io/en/0.23/advanced/custom-registry-class.html
222-
from pint.registry import GenericUnitRegistry
223-
from typing_extensions import TypeAlias
221+
# Standard approach to creating a custom registry class:
222+
# https://pint.readthedocs.io/en/0.23/advanced/custom-registry-class.html
224223

225-
class _ScaleFactorUnit(UnitRegistry.Unit):
226-
"""Child class of Units for generating units w/ clean scaling factors."""
224+
class _ScaleFactorUnit(UnitRegistry.Unit):
225+
"""Child class of Units for generating units w/ clean scaling factors."""
227226

228-
def __format__(self, format_spec):
229-
result = super().__format__(format_spec)
230-
return _unmangle_scaling(result)
227+
def __format__(self, format_spec):
228+
result = super().__format__(format_spec)
229+
return _unmangle_scaling(result)
231230

232-
class _ScaleFactorQuantity(UnitRegistry.Quantity):
233-
"""Child class of Quantity for generating units w/ clean scaling factors."""
234231

235-
pass
236-
237-
class _ScaleFactorRegistry(GenericUnitRegistry[_ScaleFactorQuantity, _ScaleFactorUnit]):
238-
"""UnitRegistry class that uses _GemdUnits."""
232+
class _ScaleFactorQuantity(UnitRegistry.Quantity):
233+
"""Child class of Quantity for generating units w/ clean scaling factors."""
239234

240-
Quantity: TypeAlias = _ScaleFactorQuantity
241-
Unit: TypeAlias = _ScaleFactorUnit
235+
pass
242236

243-
except ImportError: # pragma: no cover
244-
# https://pint.readthedocs.io/en/0.21/advanced/custom-registry-class.html
245-
class _ScaleFactorUnit(UnitRegistry.Unit):
246-
"""Child class of Units for generating units w/ clean scaling factors."""
247237

248-
def __format__(self, format_spec):
249-
result = super().__format__(format_spec)
250-
return _unmangle_scaling(result)
238+
class _ScaleFactorRegistry(GenericUnitRegistry[_ScaleFactorQuantity, _ScaleFactorUnit]):
239+
"""UnitRegistry class that uses _GemdUnits."""
251240

252-
class _ScaleFactorRegistry(UnitRegistry):
253-
"""UnitRegistry class that uses _GemdUnits."""
241+
Quantity: TypeAlias = _ScaleFactorQuantity
242+
Unit: TypeAlias = _ScaleFactorUnit
254243

255-
_unit_class = _ScaleFactorUnit
256244

257245
_REGISTRY: _ScaleFactorRegistry = None # global requires it be defined in this scope
258246

pyproject.toml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[project]
2+
name = "gemd"
3+
dynamic = ["version"]
4+
dependencies = [
5+
"pint>=0.24.4,<0.25",
6+
"deprecation>=2.1.0,<3",
7+
"typing_extensions>=4.8,<5; python_version<'3.10'",
8+
]
9+
requires-python = ">=3.9"
10+
authors = [
11+
{name = "Citrine Informatics"}
12+
]
13+
description = "Python binding for Citrine's GEMD data model"
14+
readme = "README.md"
15+
license-files = ["LICENSE"]
16+
classifiers = [
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
]
24+
25+
[project.urls]
26+
Homepage = "http://github.com/CitrineInformatics/gemd-python"
27+
28+
[build-system]
29+
requires = ["setuptools>=61.0", "wheel"]
30+
build-backend = "setuptools.build_meta"
31+
32+
[tool.setuptools.dynamic]
33+
version = {attr = "gemd.__version__.__version__"}
34+
35+
[tool.setuptools.packages.find]
36+
where = ["."]
37+
include = ["gemd"]
38+
exclude = ["docs", "tests"]
39+
40+
[tool.setuptools.package-data]
41+
"gemd.demo" = ["strehlow_and_cook.pif", "strehlow_and_cook_small.pif", "toothpick.jpg"]
42+
"gemd.units" = ["citrine_en.txt", "constants_en.txt"]
43+
"tests.units" = ["test_units.txt"]
44+
45+
46+
[dependency-groups]
47+
dev = [
48+
"flake8==7.0.0",
49+
"flake8-docstrings==1.7.0",
50+
"numpy==1.24.4; python_version<'3.10'",
51+
"pandas==2.0.3; python_version<'3.10'",
52+
"numpy>=2.0.2,<=2.1.0; python_version>='3.10'",
53+
"pandas==2.3.0; python_version>='3.10'",
54+
"pytest==8.4.2",
55+
"pytest-cov==7.0.0",
56+
"derp==0.1.1",
57+
"tomli>=2.2.1",
58+
]
59+
docs = [
60+
"sphinx==5.0.0",
61+
"sphinx-rtd-theme==1.0.0",
62+
"sphinxcontrib-apidoc==0.3.0",
63+
]
64+
65+
[tool.pytest.ini_options]
66+
testpaths = [
67+
"tests",
68+
]
69+
70+
[tool.coverage.run]
71+
omit = [
72+
"gemd/demo/*",
73+
]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pint==0.24.4
22
deprecation==2.1.0
3-
typing-extensions==4.8.0
4-
importlib-resources==5.3.0
3+
typing_extensions>=4.8,<5; python_version<'3.10'

scripts/run_tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ then python $REPO_DIR/scripts/validate_version_bump.py ||
3636
fi
3737

3838
flake8 $REPO_DIR/gemd || exit 1;
39-
derp $REPO_DIR $REPO_DIR/gemd/__version__.py || exit 1;
39+
derp $REPO_DIR/gemd $REPO_DIR/gemd/__version__.py || exit 1;
4040
pytest $QUIET $EXITFIRST --cov=$REPO_DIR/gemd \
4141
--cov-report term-missing:skip-covered \
42-
--cov-config=$REPO_DIR/tox.ini --no-cov-on-fail --cov-fail-under=100 \
42+
--cov-config=$REPO_DIR/pyproject.toml \
43+
--no-cov-on-fail --cov-fail-under=100 \
4344
$REPO_DIR || exit 1;

setup.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

test_requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ numpy==1.24.4; python_version<'3.10'
44
pandas==2.0.3; python_version<'3.10'
55
numpy>=2.0.2,<=2.1.0; python_version>='3.10'
66
pandas==2.3.0; python_version>='3.10'
7-
pytest==8.0.0
8-
pytest-cov==4.1.0
7+
pytest==8.4.2
8+
pytest-cov==7.0.0
99
derp==0.1.1

0 commit comments

Comments
 (0)