Skip to content
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

Replace pkg_resources with importlib and add python 3.13 to test suite. #574

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

defaults:
run:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
fail-fast: false
matrix:
os: [macOS-latest, macOS-13, ubuntu-latest, windows-latest]
python-version: ["3.12"]
python-version: ["3.13"]

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion docs/docs-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ dependencies:
- sphinxcontrib-svg2pdfconverter
- nbsphinx
- networkx >=2.0
- lark-parser
- lark
- requests
- lxml
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ dependencies:
- pytest-cov
- pytest-timeout
- pytest-xdist
- python>=3.9
- python>=3.10
- requests
- requests-mock
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ dependencies:
- parmed>=3.4.3
- ele
- requests
- python>=3.9
- python>=3.10
7 changes: 4 additions & 3 deletions foyer/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import collections
import glob
import importlib.resources as resources

Check warning on line 5 in foyer/forcefield.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefield.py#L5

Added line #L5 was not covered by tests
import itertools
import os
import re
import warnings
import xml.etree.ElementTree as ET
from copy import copy
from importlib.metadata import entry_points

Check warning on line 12 in foyer/forcefield.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefield.py#L12

Added line #L12 was not covered by tests
from tempfile import NamedTemporaryFile
from typing import Callable, Iterable, List

Expand All @@ -31,7 +33,6 @@
_convertParameterToNumber,
)
from parmed.gromacs.gromacstop import _Defaults
from pkg_resources import iter_entry_points, resource_filename

import foyer.element as custom_elem
from foyer import smarts
Expand Down Expand Up @@ -133,7 +134,7 @@
def get_available_forcefield_loaders() -> List[Callable]:
"""Get a list of available force field loader functions."""
available_ff_paths = []
for entry_point in iter_entry_points(group="foyer.forcefields"):
for entry_point in entry_points(group="foyer.forcefields"):
available_ff_paths.append(entry_point.load())

return available_ff_paths
Expand Down Expand Up @@ -566,7 +567,7 @@
if any(self._included_forcefields):
return self._included_forcefields

ff_dir = resource_filename("foyer", "forcefields")
ff_dir = resources.files("foyer").joinpath("forcefields")
ff_filepaths = set(glob.glob(os.path.join(ff_dir, "xml/*.xml")))

for ff_filepath in ff_filepaths:
Expand Down
4 changes: 2 additions & 2 deletions foyer/forcefields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Plugin support for forcefields."""

from pkg_resources import iter_entry_points
from importlib.metadata import entry_points

Check warning on line 3 in foyer/forcefields/__init__.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefields/__init__.py#L3

Added line #L3 was not covered by tests


class ForceFields:
Expand All @@ -11,5 +11,5 @@

forcefields = ForceFields()

for entry_point in iter_entry_points(group="foyer.forcefields", name=None):
for entry_point in entry_points(group="foyer.forcefields"):

Check warning on line 14 in foyer/forcefields/__init__.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefields/__init__.py#L14

Added line #L14 was not covered by tests
setattr(forcefields, entry_point.name, entry_point.load())
6 changes: 3 additions & 3 deletions foyer/forcefields/forcefields.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Support user-created forcefield XML files."""

import glob
import importlib.resources as resources

Check warning on line 4 in foyer/forcefields/forcefields.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefields/forcefields.py#L4

Added line #L4 was not covered by tests
import os
import warnings

from pkg_resources import resource_filename

from foyer import Forcefield
from foyer.validator import ValidationWarning


def get_ff_path():
"""Return path to forcefield locations."""
return [resource_filename("foyer", "forcefields")]
ff_dir = resources.files("foyer").joinpath("forcefields")
return [ff_dir]


def get_forcefield_paths(forcefield_name=None):
Expand Down
6 changes: 4 additions & 2 deletions foyer/tests/base_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import importlib.resources as resources
from pathlib import Path

import parmed as pmd
import pytest
from pkg_resources import resource_filename

from foyer import forcefields
from foyer.smarts import SMARTS

OPLS_TEST_FILE_DIR = Path(resource_filename("foyer", "opls_validation")).resolve()
OPLS_TEST_FILE_DIR = Path(
resources.files("foyer").joinpath("opls_validation")
).resolve()


class BaseTest:
Expand Down
4 changes: 2 additions & 2 deletions foyer/tests/test_forcefield.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import difflib
import glob
import importlib.resources as resources
import os
from typing import List

import parmed as pmd
import pytest
from lxml import etree as ET
from parmed.gromacs.gromacstop import _Defaults
from pkg_resources import resource_filename

from foyer import Forcefield, forcefields
from foyer.exceptions import (
Expand All @@ -23,7 +23,7 @@
from foyer.tests.utils import get_fn, register_mock_request
from foyer.utils.io import has_mbuild

FF_DIR = resource_filename("foyer", "forcefields")
FF_DIR = resources.files("foyer").joinpath("forcefields")
FORCEFIELDS = glob.glob(os.path.join(FF_DIR, "xml/*.xml"))

RESPONSE_BIB_ETHANE_JA962170 = """@article{Jorgensen_1996,
Expand Down
4 changes: 2 additions & 2 deletions foyer/tests/test_opls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import glob
import importlib.resources as resources
import itertools as it
import os

import parmed as pmd
import pytest
from pkg_resources import resource_filename

from foyer.tests.base_test import BaseTest
from foyer.tests.utils import atomtype

OPLS_TESTFILES_DIR = resource_filename("foyer", "opls_validation")
OPLS_TESTFILES_DIR = resources.files("foyer").joinpath("opls_validation")


class TestOPLS(BaseTest):
Expand Down
5 changes: 2 additions & 3 deletions foyer/tests/test_trappe.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import glob
import importlib.resources as resources
import itertools as it
import os

import parmed as pmd
import pytest
from pkg_resources import resource_filename

from foyer import Forcefield
from foyer.tests.base_test import BaseTest
from foyer.tests.utils import atomtype

TRAPPE_UA = Forcefield(name="trappe-ua")

TRAPPE_TESTFILES_DIR = resource_filename("foyer", "trappe_validation")
TRAPPE_TESTFILES_DIR = resources.files("foyer").joinpath("trappe_validation")


class TestTraPPE(BaseTest):
Expand Down
4 changes: 2 additions & 2 deletions foyer/tests/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import glob
import importlib.resources as resources
import os

import pytest
from lxml.etree import DocumentInvalid, XMLSyntaxError
from pkg_resources import resource_filename

from foyer.exceptions import (
MultipleValidationError,
Expand All @@ -21,7 +21,7 @@
"documentinvalid": DocumentInvalid,
}

FF_DIR = resource_filename("foyer", "forcefields")
FF_DIR = resources.files("foyer").joinpath("forcefields")
FORCEFIELDS = glob.glob(os.path.join(FF_DIR, "xml/*.xml"))


Expand Down
Loading