Repository navigation
Merge PyPI packaging automation #2261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+270
−6
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e35aa75
Add publishing workflow (#2260)
mattwthompson 9e087b8
Merge remote-tracking branch 'upstream/release/0.19.0' into merge-pyp…
mattwthompson 05f8e6c
Merge, update PyPI automation
mattwthompson 5fc130b
Nudge dependencies, make test failure more verbose
mattwthompson a2ae5a5
Do not install Python dependencies into conda environment
mattwthompson 39ddb0c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 94509af
Remove pin from when we were installing from test.pypi.org
mattwthompson b9c08d7
Merge remote-tracking branch 'upstream/merge-pypi-automation' into me…
mattwthompson 6d43e4d
Merge remote-tracking branch 'upstream/main' into merge-pypi-automation
mattwthompson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| 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]}[test]" | ||
|
|
||
| - name: Verify installed wheel version | ||
| env: | ||
| PACKAGE: openff.toolkit | ||
| DISTRIBUTION: openff-toolkit | ||
| run: | | ||
| python -I - <<'PY' | ||
| import importlib | ||
| import os | ||
| from importlib.metadata import version | ||
| from packaging.version 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 Version(module.__version__) == Version(installed_version), ( | ||
| f"{module.__version__=}, {installed_version=}" | ||
| ) | ||
| PY | ||
|
|
||
| - name: Run tests | ||
| # Use isolated directory and --import-mode=importlib to avoid hiding | ||
| # packing bugs by running in checked out repo | ||
| working-directory: /tmp | ||
| # just run "build-time" tests, copied from conda-forge | ||
| run: python -m pytest -v --color=yes --durations=10 --import-mode=importlib "$GITHUB_WORKSPACE/devtools/scripts/test_openff_toolkit.py" | ||
|
|
||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from packaging.version import Version | ||
|
|
||
| from openff.toolkit import __version__ | ||
| from openff.toolkit.topology import Molecule | ||
| from openff.toolkit.typing.engines.smirnoff import ForceField | ||
| from openff.toolkit.utils.toolkits import ( | ||
| GLOBAL_TOOLKIT_REGISTRY, | ||
| NAGLToolkitWrapper, | ||
| RDKitToolkitWrapper, | ||
| ) | ||
|
|
||
|
|
||
| def test_versions_sane(): | ||
| # partially safeguard against a malformed version number; | ||
| # 0.minor.patch and major.0.patch should be okay but not 0.0.patch | ||
| found_version = Version(__version__) | ||
| assert not (found_version.minor == 0 and found_version.major == 0), found_version | ||
|
|
||
| print(f"found version {found_version}") | ||
|
|
||
|
|
||
| def test_wrapped_toolkits_loaded(): | ||
| print(f"{GLOBAL_TOOLKIT_REGISTRY.registered_toolkit_versions=}") | ||
|
|
||
| assert RDKitToolkitWrapper().is_available() | ||
| assert NAGLToolkitWrapper().is_available() | ||
|
|
||
|
|
||
| def test_basic_system_creation(): | ||
| offmol = Molecule.from_smiles("CCO") | ||
| Molecule.from_rdkit(offmol.to_rdkit()) | ||
| ff = ForceField("openff-2.3.0.offxml") | ||
| ff.create_openmm_system(offmol.to_topology()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes for reviewer:
pyproject.toml, so nothing happened--no-deps,pipwill install those Python dependencies declared inpyproject.tomlopenff-forcefieldswhich includes file(s) that may or may not hash differently because they're on different