Skip to content

Commit

Permalink
Add hatch version_source plugin
Browse files Browse the repository at this point in the history
Update Dev and Build
- make `dev` extra authoritative for dev requirements
- Remove retired `pytest-openfiles`.
- Use tarfile `data_filter` when supported.

Add v1.6.0 release notes

fixes #13
  • Loading branch information
tcjennings committed Jan 21, 2025
1 parent 8464c43 commit c914b64
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 17 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions doc/lsst_versions/CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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 <https://jira.lsstcorp.org/browse/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
==============================

Expand Down
16 changes: 16 additions & 0 deletions doc/lsst_versions/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
==============

Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions python/lsst_versions/hatch.py
Original file line number Diff line number Diff line change
@@ -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())
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c914b64

Please sign in to comment.