From 97b6626497b5b43a7961a751ed69be3d0ec2bf8a Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 08:22:26 -1000 Subject: [PATCH 1/7] use poetry dynamic versioning plugin. This will help with the switch to use the OpenAstronomy workflow in the pypi publishing workflow. --- pyproject.toml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 816f2af6..0b0e9a94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,15 @@ authors = ["D. J. Teal ", "DRAGONS development team"] license = "BSD3" readme = "README.md" + +[tool.poetry-dynamic-versioning] +enable = true +vcs = "git" +style = "pep440" +# your tags are plain "1.2.3", not "v1.2.3", so drop the v from the pattern: +pattern = "^(?P\\d+\\.\\d+\\.\\d+)" + + [tool.poetry.urls] "Homepage" = "https://github.com/GeminiDRSoftware/astrodata/" "Documentation" = "https://geminidrsoftware.github.io/astrodata/" @@ -62,8 +71,8 @@ devpi-server = "^6.14.0" devpi-client = "^7.2.0" [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend" [tool.pytest.ini_options] testpaths = [ From 0efdb333b8fabc96c507999486d8eb8126256494 Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 08:32:18 -1000 Subject: [PATCH 2/7] fix the version pattern to work with dev0, rc, a/alpha, etc. --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0b0e9a94..04cd9ab2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,8 +12,7 @@ enable = true vcs = "git" style = "pep440" # your tags are plain "1.2.3", not "v1.2.3", so drop the v from the pattern: -pattern = "^(?P\\d+\\.\\d+\\.\\d+)" - +pattern = "^(?P\\d+\\.\\d+\\.\\d+)(\\.?(?P[a-zA-Z]+)\\.?(?P\\d+)?)?" [tool.poetry.urls] "Homepage" = "https://github.com/GeminiDRSoftware/astrodata/" From d328c4baf36581324c896b74b2059d0bf6587e51 Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 13:43:16 -1000 Subject: [PATCH 3/7] Use the dynamic versioning when installing from devpi. We use the filename of the build artifact to ensure robustness when it is run in a github workflow. "poetry version --short" works locally but not in the workflow. --- noxfile.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/noxfile.py b/noxfile.py index c986aceb..2645371d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -671,7 +671,7 @@ def conda_unit_tests(session: nox.Session) -> None: session.run("pytest", *SessionVariables.unit_pytest_options, *pos_args) -def unit_test_build(session: nox.Session) -> None: +def unit_test_build(session: nox.Session, version: str) -> None: """Run the unit tests using the build version of the package. This is meant to be called from the `build_tests` session. @@ -687,7 +687,7 @@ def unit_test_build(session: nox.Session) -> None: "localhost", "--index-url", session.env["PIP_INDEX_URL"], - "astrodata==0.0.0", + f"astrodata=={version}", ) # Positional arguments after -- are passed to pytest. @@ -697,7 +697,7 @@ def unit_test_build(session: nox.Session) -> None: session.run("pytest", *SessionVariables.unit_pytest_options, *pos_args) -def integration_test_build(session: nox.Session) -> None: +def integration_test_build(session: nox.Session, version: str) -> None: """Run the integration tests using the build version of the package. This is meant to be called from the `build_tests` session. @@ -730,7 +730,7 @@ def integration_test_build(session: nox.Session) -> None: "localhost", "--index-url", session.env["PIP_INDEX_URL"], - "astrodata==0.0.0", + f"astrodata=={version}", ) # Positional arguments after -- are passed to pytest. @@ -793,7 +793,7 @@ def wrapper(session, *args, **kwargs): return wrapper -def build_and_publish_to_devpi(session: nox.Session): +def build_and_publish_to_devpi(session: nox.Session) -> str: """Build the astrodata package and publish it. If the devpi server is not running, this will raise an error. @@ -804,6 +804,9 @@ def build_and_publish_to_devpi(session: nox.Session): session.run("poetry", "build", f"--output={tmp_build_dir}", external=True) + sdist = next(Path(tmp_build_dir).glob("astrodata-*.tar.gz")) + version = sdist.stem.removeprefix("astrodata-").removesuffix(".tar") + _DEBUG = False if _DEBUG: session.run( @@ -845,6 +848,8 @@ def build_and_publish_to_devpi(session: nox.Session): env=poetry_config_env_vars, ) # fmt: skip + return version + @nox.session(python=SessionVariables.python_versions, tags=["build_tests"]) @use_devpi_server @@ -855,12 +860,12 @@ def build_tests_unit(session: nox.Session) -> None: and run the tests using the build version of the package. """ apply_data_caching_environment_variable(session) - build_and_publish_to_devpi(session) + version = build_and_publish_to_devpi(session) working_dir = Path(session.create_tmp()) with session.chdir(working_dir): - unit_test_build(session) + unit_test_build(session, version) @nox.session( @@ -877,12 +882,12 @@ def build_tests_integration(session): and run the tests using the build version of the package. """ apply_data_caching_environment_variable(session) - build_and_publish_to_devpi(session) + version = build_and_publish_to_devpi(session) working_dir = Path(session.create_tmp()) with session.chdir(working_dir): - integration_test_build(session) + integration_test_build(session, version) @nox.session(python=SessionVariables.python_versions) @@ -901,7 +906,7 @@ def script_tests(session: nox.Session) -> None: def build_tests_scripts(session: nox.Session) -> None: """Run the script tests using the build version of the package.""" apply_data_caching_environment_variable(session) - build_and_publish_to_devpi(session) + version = build_and_publish_to_devpi(session) # This debug block proved useful in debugging the devpi server. _DEBUG = False @@ -939,8 +944,14 @@ def build_tests_scripts(session: nox.Session) -> None: "localhost", "--index-url", session.env["PIP_INDEX_URL"], - "astrodata==0.0.0", + f"astrodata=={version}", ) + if _DEBUG: + session.run( + "python", + "-c", + "import astrodata; print(astrodata.__version__)", + ) # Run the tests. Need to pass arguments to pytest. test_dir = Path(__file__).parent / "tests" / "script_tests" From c79df6b34937043c0d24d1fdfe982d11ebe13b97 Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 16:21:48 -1000 Subject: [PATCH 4/7] Ensure that all the tags are retrieved at checkout --- .github/workflows/build_tests.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index b76294fc..d8cfded2 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -29,6 +29,13 @@ jobs: steps: - name: "Check out the repo" uses: "actions/checkout@v7" + with: + fetch-depth: 0 + + - name: "Check git tags" + run: | + git fetch --tags + git describe --tags - name: "Set up Python" uses: "actions/setup-python@v6" @@ -109,6 +116,13 @@ jobs: steps: - uses: "actions/checkout@v7" + with: + fetch-depth: 0 + + - name: "Check git tags" + run: | + git fetch --tags + git describe --tags - name: "Set up Python" uses: "actions/setup-python@v6" From 5c162fde885e119ae9dc9a1ed3010404aa56f97c Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 16:25:14 -1000 Subject: [PATCH 5/7] update publish workflow to use OpenAstronomy and trusted publishing The old mint-token workflow is archived and needed to be replaced. --- .github/workflows/publish_pypi.yml | 58 +++++++++++++----------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 85aea849..8d025da7 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -5,6 +5,7 @@ on: tags: # Matches any tags; tags are only used for versioning in this project. - '*' + - '!*dev*' workflow_dispatch: jobs: @@ -17,44 +18,35 @@ jobs: name: Build tests uses: ./.github/workflows/build_tests.yml - deploy: + build: + name: Build package needs: [source_test, build_test] + uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v2 + with: + python-version: '3.12' + save_artifacts: true + upload_to_pypi: false # never let this workflow attempt the upload itself + + upload: + name: Upload to PyPI + if: ${{ github.event_name != 'workflow_dispatch' }} + needs: [build] runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/astrodata/ + permissions: - # This permission is required for trusted publishing. - id-token: write - contents: read + id-token: write # required for trusted publishing steps: - - uses: actions/checkout@v7 - - - name: Set up Python 3.10 - uses: actions/setup-python@v6 + - name: Download built dists + uses: actions/download-artifact@v7 with: - python-version: '3.10' + merge-multiple: true + pattern: dist-* + path: dist - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: false - - - name: Update version (kept at 0.0.0) in pyproject.toml and build - if: ${{ github.event_name != 'workflow_dispatch' }} - run: | - poetry version ${{ github.ref_name }} - poetry version - poetry build - - - name: Mint token - if: ${{ github.event_name != 'workflow_dispatch' }} - id: mint - uses: tschm/token-mint-action@v1.0.3 - - - name: Publish the package with poetry - # Allow workflow dispatch to trigger this job, but don't allow it - # to publish the package to PyPI. - if: ${{ github.event_name != 'workflow_dispatch' }} - run: | - echo "PUBLISHING!!!! ✨🚀" - poetry publish -u __token__ -p '${{ steps.mint.outputs.api-token }}' + - name: Publish the package + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file From c5b7d00139c776e43bb914145337753e9b294c06 Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 16:34:33 -1000 Subject: [PATCH 6/7] Set up a fallback if there are no tags yet. --- .github/workflows/build_tests.yml | 4 ++-- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index d8cfded2..cf998a11 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -35,7 +35,7 @@ jobs: - name: "Check git tags" run: | git fetch --tags - git describe --tags + git describe --tags --always - name: "Set up Python" uses: "actions/setup-python@v6" @@ -122,7 +122,7 @@ jobs: - name: "Check git tags" run: | git fetch --tags - git describe --tags + git describe --tags --always - name: "Set up Python" uses: "actions/setup-python@v6" diff --git a/pyproject.toml b/pyproject.toml index 04cd9ab2..136c2ae9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ vcs = "git" style = "pep440" # your tags are plain "1.2.3", not "v1.2.3", so drop the v from the pattern: pattern = "^(?P\\d+\\.\\d+\\.\\d+)(\\.?(?P[a-zA-Z]+)\\.?(?P\\d+)?)?" +fallback-version = "0.0.0.dev0" [tool.poetry.urls] "Homepage" = "https://github.com/GeminiDRSoftware/astrodata/" From 8ee95dbfd9984f72bb900bbdae0c2afa5aff950b Mon Sep 17 00:00:00 2001 From: Kathleen Labrie Date: Thu, 16 Jul 2026 16:34:33 -1000 Subject: [PATCH 7/7] Set up a fallback if there are no tags yet. --- .github/workflows/publish_pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 8d025da7..8186621a 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -49,4 +49,4 @@ jobs: path: dist - name: Publish the package - uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file + uses: pypa/gh-action-pypi-publish@release/v1