Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into unique_molecules-re…
Browse files Browse the repository at this point in the history
…quired
  • Loading branch information
mattwthompson committed Mar 8, 2024
2 parents c3610dd + 118918c commit b2131cb
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
PYTEST_ARGS+=" --runslow"
fi
python -m pytest $PYTEST_ARGS $COV
python -m pytest --durations=20 $PYTEST_ARGS $COV
- name: Run code snippets in docs
if: ${{ matrix.rdkit == true && matrix.openeye == true }}
Expand Down
21 changes: 5 additions & 16 deletions .github/workflows/beta_rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- ubuntu-latest
- macos-latest
python-version:
- 3.9
- 3.10

env:
OE_LICENSE: ${{ github.workspace }}/oe_license.txt
Expand All @@ -39,12 +39,6 @@ jobs:
create-args: >-
python=${{ matrix.python-version }}
- name: Additional info about the build
run: |
uname -a
df -h
ulimit -a
- name: Make oe_license.txt file from GH org secret "OE_LICENSE"
env:
OE_LICENSE_TEXT: ${{ secrets.OE_LICENSE }}
Expand All @@ -57,21 +51,16 @@ jobs:
python -m pip install .
- name: Install test plugins
run: |
python -m pip install utilities/test_plugins
run: python -m pip install utilities/test_plugins

- name: Environment Information
run: |
conda info
conda list
run: micromamba info && micromamba list

- name: Check links
run: |
pytest -r fE --tb=short openff/toolkit/_tests/test_links.py
run: pytest -r fE --tb=short openff/toolkit/_tests/test_links.py

- name: Run mypy
run: |
mypy --namespace-packages -p "openff.toolkit"
run: mypy -p "openff.toolkit"

- name: Run unit tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion devtools/conda-envs/beta_rc_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ dependencies:
- openff-nagl-models ==0.1.0
# Toolkit-specific
- ambertools >=22
- rdkit
# https://github.com/rdkit/rdkit/issues/7221
- rdkit >=2023.09.6
- openeye-toolkits
# Test-only/optional/dev
- pytest
Expand Down
3 changes: 2 additions & 1 deletion devtools/conda-envs/rdkit-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ dependencies:
# AmberTools 23 brings in ParmEd 4, which doesn't yet work with examples
# https://github.com/openforcefield/openff-toolkit/issues/1532
- ambertools =22.4
- rdkit
# https://github.com/rdkit/rdkit/issues/7221
- rdkit <2023.09.6
# Test-only/optional/dev/typing/examples
- pytest
- pytest-xdist
Expand Down
3 changes: 2 additions & 1 deletion devtools/conda-envs/rdkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies:
- typing_extensions
# Toolkit-specific
- ambertools >=22
- rdkit
# https://github.com/rdkit/rdkit/issues/7221
- rdkit <2023.09.6
# Test-only/optional/dev/typing
- pytest
- pytest-cov
Expand Down
3 changes: 2 additions & 1 deletion devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies:
- openff-nagl-models ==0.1.0
# Toolkit-specific
- ambertools >=22
- rdkit
# https://github.com/rdkit/rdkit/issues/7221
- rdkit <2023.09.6
- openeye-toolkits
# Test-only/optional/dev/typing
- pytest
Expand Down
36 changes: 22 additions & 14 deletions openff/toolkit/_tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test that the examples in the repo run without errors.
"""

import os
import pathlib
import re
import subprocess
Expand All @@ -11,10 +10,9 @@

import pytest

from openff.toolkit._tests.utils import _get_readme_path
from openff.toolkit.utils import RDKIT_AVAILABLE, get_data_file_path, temporary_cd

ROOT_DIR_PATH = pathlib.Path(__file__).joinpath("../../../../").resolve()


def run_script_file(file_path):
"""Run through the shell a python script."""
Expand All @@ -38,32 +36,37 @@ def run_script_str(script_str):
"""
with tempfile.TemporaryDirectory() as tmp_dir:
temp_file_path = os.path.join(tmp_dir, "temp.py")
temp_file_path = pathlib.Path(tmp_dir, "temp.py").as_posix()

# Create temporary python script.
with open(temp_file_path, "w") as f:
f.write(script_str)
# Run the Python script.
try:
run_script_file(temp_file_path)
except: # noqa
except Exception as error:
script_str = textwrap.indent(script_str, " ")
raise Exception(f"The following script failed:\n{script_str}")
raise Exception(f"The following script failed:\n{script_str}") from error


def find_example_scripts():
def find_example_scripts() -> list[str]:
"""Find all Python scripts, excluding Jupyter notebooks, in the examples folder.
Returns
-------
example_file_paths : list[str]
List of full paths to python scripts to execute.
"""
examples_dir_path = ROOT_DIR_PATH.joinpath("examples")
# Count on the examples/ path being equivalently accessible as the README file
readme_file_path = _get_readme_path()

if readme_file_path is None:
return list()

examples_dir_path = pathlib.Path(_get_readme_path().parent, "examples")

# Examples that require RDKit
rdkit_examples = {
examples_dir_path.joinpath("conformer_energies/conformer_energies.py"),
}
rdkit_examples = {examples_dir_path / "conformer_energies/conformer_energies.py"}

example_file_paths = []
for example_file_path in examples_dir_path.glob("*/*.py"):
Expand All @@ -75,17 +78,22 @@ def find_example_scripts():
return example_file_paths


def find_readme_examples():
def find_readme_examples() -> list[str]:
"""Yield the Python scripts in the main README.md file.
Returns
-------
readme_examples : list[str]
The list of Python scripts included in the README.md files.
"""
readme_path = ROOT_DIR_PATH.joinpath("README.md")
with open(readme_path, "r") as f:
readme_file_path = _get_readme_path()

if readme_file_path is None:
return list()

with open(readme_file_path, "r") as f:
readme_content = f.read()

return re.findall("```python(.*?)```", readme_content, flags=re.DOTALL)


Expand Down
1 change: 1 addition & 0 deletions openff/toolkit/_tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -4075,6 +4075,7 @@ def test_toolkit_registry_bad_charge_method(self):

class TestSmirnoffVersionConverter:
@requires_openeye_mol2
@pytest.mark.slow
@pytest.mark.parametrize(
("freesolv_id", "forcefield_version", "allow_undefined_stereo"),
generate_freesolv_parameters_assignment_cases(),
Expand Down
21 changes: 12 additions & 9 deletions openff/toolkit/_tests/test_links.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import os
import re
from urllib.request import Request, urlopen

import pytest

ROOT_DIR_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "..", ".."
)
from openff.toolkit._tests.utils import _get_readme_path


def find_readme_links():
def find_readme_links() -> list[str]:
"""Yield all the links in the main README.md file.
Returns
-------
readme_examples : list[str]
The list of links included in the README.md file.
"""
readme_file_path = os.path.join(ROOT_DIR_PATH, "README.md")
with open(readme_file_path, "r") as f:
readme_content = f.read()
return re.findall("http[s]?://(?:[0-9a-zA-Z]|[-/.%:_])+", readme_content)
readme_file_path = _get_readme_path()

if readme_file_path is None:
return list()

else:
with open(readme_file_path.as_posix(), "r") as f:
readme_content = f.read()

return re.findall("http[s]?://(?:[0-9a-zA-Z]|[-/.%:_])+", readme_content)


@pytest.mark.parametrize("readme_link", find_readme_links())
Expand Down
1 change: 1 addition & 0 deletions openff/toolkit/_tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,7 @@ def test_topology_hierarchy_iterators(

@skip_if_missing("nglview")
class TestTopologyVisaulization:
@pytest.mark.slow
@requires_rdkit
def test_visualize_basic(self):
import nglview
Expand Down
18 changes: 18 additions & 0 deletions openff/toolkit/_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import importlib
import itertools
import os
import pathlib
import pprint
import textwrap
from contextlib import contextmanager
from typing import Union

import numpy as np
import openmm
Expand Down Expand Up @@ -45,6 +47,22 @@
)


def _get_readme_path() -> Union[pathlib.Path, None]:
"""
Return a path to the README file or None if it cannot be assured to be the toolkit's README.
"""
if "site-packages" in __file__:
# This test file is being collected from the installed package, which
# does not provide the README file.
# Note that there will likely be a mis-bundled file
# $CONDA_PREFIX/lib/python3.x/site-packages/README.md, but this is not
# the toolkit's README file!
return None

else:
return pathlib.Path(__file__).parents[3] / "README.md"


def has_pkg(pkg_name):
"""
Helper function to generically check if a package is installed. Intended
Expand Down

0 comments on commit b2131cb

Please sign in to comment.