From b68046ea96f06bb8aff6f3fd3201f9233e22543d Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 20 Nov 2026 08:07:08 -0600 Subject: [PATCH 1/5] Add publish action --- .github/workflows/publish.yml | 198 +++++++++++++++++++++++++++++++++ devtools/test-requirements.txt | 5 + 2 files changed, 203 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 devtools/test-requirements.txt diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c49a0dc --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,198 @@ +name: Build and publish package + +on: + pull_request: + release: + # Only trigger on GitHub Releases - but include "pre-relesae" if that box is ticked + types: + - released + - prereleased + + workflow_dispatch: + inputs: + source_branch: + description: "Branch containing the source code to publish" + required: true + type: string + version: + description: "Package version to publish (e.g. 0.15.1)" + required: true + type: string + +# Deny permissions by default. Each job gets only what it needs. +permissions: {} + +jobs: + build: + name: Build distributions + runs-on: ubuntu-latest + + # We want to track the commit we use to build, so we use the same commit to test + outputs: + source_sha: ${{ steps.source.outputs.sha }} + + permissions: + contents: read + + steps: + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Grab the ref from the workflow dispatch if that method was used as the trigger, else use the ref that triggered the workflow + ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/heads/{0}', inputs.source_branch) || github.ref }} + # Important for projects using setuptools-scm. + fetch-depth: 0 + # We don't need the token for more git operations + persist-credentials: false + + - name: Record source commit + id: source + run: | + sha=$(git rev-parse HEAD) + echo "sha=$sha" >> "$GITHUB_OUTPUT" + echo "Building from commit: $sha" + + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + # Recommend using min python version supported + python-version: "3.12" + + - name: Install build frontend + run: python -m pip install build + + - name: Build distributions + shell: bash + env: + BACKFILL_VERSION: ${{ inputs.version }} + run: | + if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then + export SETUPTOOLS_SCM_PRETEND_VERSION="$BACKFILL_VERSION" + fi + python -m build + + - name: Show distributions + run: ls -lh dist/ + + # archive: false means the wheel itself is stored directly rather + # than being wrapped in an additional GitHub artifact ZIP. + # + # This requires the glob to resolve to exactly one file. + - name: Upload wheel + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: dist/*.whl + archive: false + if-no-files-found: error + + - name: Upload sdist + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + path: dist/*.tar.gz + archive: false + if-no-files-found: error + + test-package: + name: Test built package + needs: build + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + # We need the checkout for the test suite, but we do NOT install + # the package from this checkout. + - name: Check out repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.build.outputs.source_sha }} + fetch-depth: 1 + persist-credentials: false + + - name: Download wheel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.whl" + path: dist + merge-multiple: true + + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.12" + + - name: Install built wheel with test dependencies + shell: bash + run: | + shopt -s nullglob + wheels=(dist/*.whl) + if (( ${#wheels[@]} != 1 )); then + echo "Expected exactly one wheel, found ${#wheels[@]}" + exit 1 + fi + python -m pip install "${wheels[0]}" pytest-xdist --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple + python -m pip install -r devtools/test-requirements.txt --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple + + - name: Verify installed wheel version + env: + PACKAGE: openforcefields + DISTRIBUTION: openff-forcefields + run: | + python -I - <<'PY' + import importlib + import os + from importlib.metadata import version + + package = os.environ["PACKAGE"] + module = importlib.import_module(package) + installed_version = version(os.getenv("DISTRIBUTION", package)) + + print(f"Package path: {module.__file__}") + print(f"Module version: {module.__version__}") + print(f"Installed version: {installed_version}") + + assert module.__version__ == installed_version + PY + + - name: Run tests + # working-directory: /tmp + run: python -m pytest -n auto -v --color=yes --durations=10 + + publish: + name: Publish to PyPI + + # The publish job exists only for an actual GitHub Release. + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' + + # We only publish if both building and testing the built artifact succeeded. + needs: + - build + - test-package + + runs-on: ubuntu-latest + + environment: + name: pypi + + # This is the only job that can request an OIDC identity. + permissions: + id-token: write + + steps: + - name: Download wheel + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.whl" + path: dist + merge-multiple: true + + - name: Download sdist + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: "*.tar.gz" + path: dist + merge-multiple: true + + - name: Publish distributions to PyPI + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 diff --git a/devtools/test-requirements.txt b/devtools/test-requirements.txt new file mode 100644 index 0000000..da1ef5e --- /dev/null +++ b/devtools/test-requirements.txt @@ -0,0 +1,5 @@ +packaging +pytest +pytest-cov +pytest-xdist +pandas From 638e8d6da0fe75a672c54495f9e1d8ac25ee7847 Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 20 Nov 2026 08:09:46 -0600 Subject: [PATCH 2/5] Unify project name --- openforcefields/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openforcefields/__init__.py b/openforcefields/__init__.py index 2b5667c..ca3620c 100644 --- a/openforcefields/__init__.py +++ b/openforcefields/__init__.py @@ -6,4 +6,4 @@ from openforcefields.openforcefields import get_forcefield_dirs_paths -__version__ = version("openforcefields") +__version__ = version("openff-forcefields") diff --git a/pyproject.toml b/pyproject.toml index e0d327f..09e7161 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = [ ] [project] -name = "openforcefields" +name = "openff-forcefields" description = "Force fields released by the Open Force Field Initiative" readme = { file = "README.md", content-type = "text/markdown" } license = { text = "CC-BY-4.0" } From 45afed1c0bce1470fd9ce3ce3b0aafec4e49b98c Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 20 Nov 2026 08:14:35 -0600 Subject: [PATCH 3/5] Skip water model test if no toolkit --- openforcefields/tests/test_water_models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/openforcefields/tests/test_water_models.py b/openforcefields/tests/test_water_models.py index 7c5c66c..d9c362e 100644 --- a/openforcefields/tests/test_water_models.py +++ b/openforcefields/tests/test_water_models.py @@ -1,7 +1,18 @@ +import pytest + +try: + from openff.toolkit import ForceField, Molecule, Topology + + has_toolkit = True +except ImportError: + has_toolkit = False + +if not has_toolkit: + pytest.skip("Skipping module due to not having the toolkit", allow_module_level=True) + import numpy import openmm import openmm.unit -import pytest from openff.toolkit import ForceField, Molecule, Topology from openff.units import Quantity, unit from openff.units.openmm import ensure_quantity From 2f0fb459ef82fd1b68d0a1ed49f1f92c84360260 Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 20 Nov 2026 08:18:06 -0600 Subject: [PATCH 4/5] Clean up build-time tests --- .github/workflows/publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c49a0dc..2483246 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -131,8 +131,8 @@ jobs: echo "Expected exactly one wheel, found ${#wheels[@]}" exit 1 fi - python -m pip install "${wheels[0]}" pytest-xdist --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple - python -m pip install -r devtools/test-requirements.txt --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple + python -m pip install "${wheels[0]}" + python -m pip install -r devtools/test-requirements.txt - name: Verify installed wheel version env: @@ -156,8 +156,8 @@ jobs: PY - name: Run tests - # working-directory: /tmp - run: python -m pytest -n auto -v --color=yes --durations=10 + # include discvery of all openforcefields/ when toolkit is added as a test dep + run: python -m pytest -n auto -v --color=yes --durations=10 openforcefields/tests/test_openforcefields.py publish: name: Publish to PyPI From 9f48275c39d4cf489cbc6ae975ab5fb469e0840d Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Fri, 20 Nov 2026 08:18:12 -0600 Subject: [PATCH 5/5] Revert "Skip water model test if no toolkit" This reverts commit 45afed1c0bce1470fd9ce3ce3b0aafec4e49b98c. --- openforcefields/tests/test_water_models.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/openforcefields/tests/test_water_models.py b/openforcefields/tests/test_water_models.py index d9c362e..7c5c66c 100644 --- a/openforcefields/tests/test_water_models.py +++ b/openforcefields/tests/test_water_models.py @@ -1,18 +1,7 @@ -import pytest - -try: - from openff.toolkit import ForceField, Molecule, Topology - - has_toolkit = True -except ImportError: - has_toolkit = False - -if not has_toolkit: - pytest.skip("Skipping module due to not having the toolkit", allow_module_level=True) - import numpy import openmm import openmm.unit +import pytest from openff.toolkit import ForceField, Molecule, Topology from openff.units import Quantity, unit from openff.units.openmm import ensure_quantity