Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# against a conda build of Interchange. (It may also be pulled down
# by `openmmforcefields` and should be removed in that case a well.)
micromamba remove --force openff-toolkit openff-toolkit-base
python -m pip install .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes for reviewer:

  • this is necessary to preserve existing behavior
  • previously there weren't any dependencies declared in pyproject.toml, so nothing happened
  • now, without --no-deps, pip will install those Python dependencies declared in pyproject.toml
  • the difference is almost entirely inconsequential, but it brings down the PyPI build of openff-forcefields which includes file(s) that may or may not hash differently because they're on different
    • this is generally good practice, since this file isn't meant to test PyPI deployment, independent of this quirk

python -m pip install . --no-deps

- name: Install test plugins
run: python -m pip install utilities/test_plugins
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
python=${{ matrix.python-version }}

- name: Install package
run: python -m pip install .
run: python -m pip install . --no-deps

- name: Environment Information
run: |
Expand Down
203 changes: 203 additions & 0 deletions .github/workflows/publish.yml
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
6 changes: 3 additions & 3 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ dependencies:
- xmltodict
- python-constraint2
- openmm >=7.6
- openff-forcefields >=2023.05.1
- openff-forcefields >=2026.11
- openff-units
- openff-amber-ff-ports
- openff-utilities >=0.1.5
- openff-interchange-base >=0.5
- openff-nagl-base >=0.4.0
- openff-nagl-models >=0.3.0
- openff-nagl-base >=0.5.0
- openff-nagl-models >=2025
# Toolkit-specific
- ambertools >=22
- rdkit >=2025
Expand Down
33 changes: 33 additions & 0 deletions devtools/scripts/test_openff_toolkit.py
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())
2 changes: 1 addition & 1 deletion openff/toolkit/_tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def test_hash(self):
ffs = get_available_force_fields()

for ff1, ff2 in itertools.combinations(ffs, 2):
assert hash(ff1) != hash(ff2)
assert hash(ff1) != hash(ff2), f"Hashes equal (when they shouldn't) for force fields {ff1=} and {ff2=}"

def test_hash_cosmetic(self, force_field):
"""Test that adding a cosmetic attribute does not change the hash"""
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ classifiers = [
"Topic :: Utilities",
]
dynamic = [ "version" ]
dependencies = [
"cachetools",
"networkx",
"numpy",
"openff-amber-ff-ports",
"openff-forcefields",
"openff-interchange>=0.5.2",
"openff-nagl",
"openff-nagl-models",
"openff-units",
"openff-utilities",
"openmm",
"packaging",
"python-constraint2",
"rdkit",
"xmltodict",
]
optional-dependencies.test = [
"msgpack",
"nglview",
"pydantic",
"pymongo",
"pytest>=6",
"pytest-randomly",
"pytest-rerunfailures",
"pytest-timeout",
"pytest-xdist",
]
urls = { Homepage = "https://github.com/openforcefield/openff-toolkit" }

[tool.setuptools]
Expand Down