diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 63417b3..03ffa41 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,22 +33,18 @@ jobs: python -m pip install --upgrade pip pip install --upgrade setuptools wheel - # We have two cores so we can speed up the testing with xdist - - name: Install pytest packages - run: pip install pytest pytest-flake8 pytest-openfiles pytest-cov "flake8<5" + - name: Build and install + run: | + python -m pip install -v -e ".[dev]" - name: List installed packages shell: bash -l {0} run: | pip list -v - - name: Build and install - run: | - python -m pip install -v -e . - - name: Run tests run: | - pytest -r a -v --open-files --cov=tests --cov=lsst_versions --cov-report=xml --cov-report=term + pytest -r a -v --cov=tests --cov=lsst_versions --cov-report=xml --cov-report=term - name: Upload coverage to codecov uses: codecov/codecov-action@v2 @@ -70,7 +66,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.8" + python-version: "3.12" cache: "pip" cache-dependency-path: "setup.cfg" diff --git a/.github/workflows/mypy.yaml b/.github/workflows/mypy.yaml index 87e7902..50000ff 100644 --- a/.github/workflows/mypy.yaml +++ b/.github/workflows/mypy.yaml @@ -19,15 +19,12 @@ jobs: - name: Set up python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.12" cache: "pip" cache-dependency-path: "setup.cfg" - - name: Install mypy - run: pip install mypy types-setuptools - - name: Build the package so that all dependencies are installed. - run: pip install -v -e . + run: pip install -v -e ".[dev,typing]" - name: Run mypy run: mypy python diff --git a/doc/lsst_versions/CHANGES.rst b/doc/lsst_versions/CHANGES.rst index 3eb0f40..69ad4c7 100644 --- a/doc/lsst_versions/CHANGES.rst +++ b/doc/lsst_versions/CHANGES.rst @@ -1,3 +1,20 @@ +lsst-versions 1.6.0 2025-01-21 +============================== + +New Features +------------ + +- Adds support for [Hatchling](https://hatch.pypa.io/latest/config/build/#build-system). + Implements a Hatch "version source plugin" interface. (`DM-48515 `_) + + +Miscellaneous Changes of Minor Interest +--------------------------------------- + +- Refreshes development and build environment specifications. + +- Removes retired `pytest-openfiles` testing dependency. + lsst-versions 1.5.0 2023-11-29 ============================== diff --git a/doc/lsst_versions/configuring.rst b/doc/lsst_versions/configuring.rst index faf7410..eb69106 100644 --- a/doc/lsst_versions/configuring.rst +++ b/doc/lsst_versions/configuring.rst @@ -28,6 +28,22 @@ It is expected that the package ``__init__.py`` will import this generated file These minor changes should be sufficient for ``pip install .`` to build the package with the correct version. +Using with Hatchling +-------------------- + +When building a project that employs the Hatchling build backend, ``lsst_versions`` can be used as a Version Source plugin. + +In the project's ``pyproject.toml``, update the build system specification: + +.. code-block:: toml + + [build-system] + requires = ["hatchling", "lsst-versions"] + build-backend = "hatchling.build" + + [tool.hatch.version] + source = "lsst" + GitHub Actions ============== diff --git a/pyproject.toml b/pyproject.toml index 2a67712..75b0c3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,11 @@ +[project] +name = "lsst-versions" +requires-python = ">= 3.8" +dynamic = [ + "version", "classifiers", "description", "entry-points", "scripts", + "dependencies", "optional-dependencies", "urls", "authors", "readme", "keywords" +] + [build-system] requires = [ "setuptools", @@ -8,7 +16,7 @@ requires = [ build-backend = "setuptools.build_meta" [tool.towncrier] - package = "lsst-versions" + package = "lsst_versions" package_dir = "python" filename = "doc/lsst_versions/CHANGES.rst" directory = "doc/changes" diff --git a/python/lsst_versions/hatch.py b/python/lsst_versions/hatch.py new file mode 100644 index 0000000..94946f5 --- /dev/null +++ b/python/lsst_versions/hatch.py @@ -0,0 +1,22 @@ +"""Module implementing a version source plugin for the hatch build system.""" + +from hatchling.plugin import hookimpl +from hatchling.version.source.plugin.interface import VersionSourceInterface + + +@hookimpl +def hatch_register_version_source() -> type["LsstVersionSource"]: + """Register a Hatch Version Source hook.""" + return LsstVersionSource + + +class LsstVersionSource(VersionSourceInterface): + """Implement a Hatch Version Source Interface.""" + + PLUGIN_NAME = "lsst" + + def get_version_data(self) -> dict: + """Return the project version data.""" + from ._versions import find_lsst_version + + return dict(version=find_lsst_version()) diff --git a/setup.cfg b/setup.cfg index 2603ca5..c63e6f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,8 +43,13 @@ install_requires = dev = pytest >= 3.2 flake8 >= 3.7.5 + pytest-cov >= 5.0 pytest-flake8 >= 1.0.4 - pytest-openfiles >= 0.5.0 + hatchling >= 1.27.0 + +typing = + mypy >= 1.14 + types-setuptools >= 75 [options.packages.find] where = python @@ -57,6 +62,8 @@ setuptools.finalize_distribution_options = lsst_versions = lsst_versions:infer_version_for_setuptools console_scripts = lsst-version = lsst_versions._cmd:main +hatch = + lsst = lsst_versions.hatch [pydocstyle] convention = numpy diff --git a/tests/test_versions.py b/tests/test_versions.py index 2facba1..48360c9 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -41,7 +41,11 @@ def setup_module(module): """ if not os.path.exists(GITDIR): with tarfile.open(TARFILE, "r:gz") as tar: - tar.extractall(path=TESTDIR) + if hasattr(tarfile, "data_filter"): + tar.extractall(path=TESTDIR, filter="data") + else: + # Remove when minimum test matrix python >= 3.12 + tar.extractall(path=TESTDIR) # Ensure that the pyproject.toml file is in the test directory. target = os.path.join(GITDIR, "pyproject.toml")