Skip to content

Commit

Permalink
Merge pull request #222 from nlesc-nano/packaging
Browse files Browse the repository at this point in the history
REL: Prepare for CAT 0.10.2
  • Loading branch information
BvB93 authored Jan 10, 2022
2 parents 5bd7aeb + c782bbe commit c4f03d3
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
case "${{ matrix.special }}" in
"; minimum version")
conda create -n test -c conda-forge python=${{ matrix.version }} rdkit==2018.03.1 numpy=1.15.0 pandas=0.23.0 h5py=2.7.0 scipy=0.19.1 contextlib2==0.6.0 typing-extensions==3.7.4.3 pytest==5.4.0 pyyaml=5.1.0 pytest-cov pytest-mock
conda create -n test -c conda-forge python=${{ matrix.version }} rdkit==2018.03.1 numpy=1.15.0 pandas=0.23.0 h5py=2.7.0 scipy=0.19.1 contextlib2==0.6.0 typing-extensions==3.7.4.3 pytest==5.4.0 pyyaml=5.1.0 packaging==16.8 pytest-cov pytest-mock
source $CONDA/bin/activate test
pip install schema==0.7.2 Nano-Utils==0.4.3 AssertionLib==2.2.3 plams==1.5.1 qmflows==0.11.0
pip install -e . --no-dependencies
Expand Down
11 changes: 6 additions & 5 deletions CAT/_mol_str_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
import textwrap
from typing import Any, Callable

from nanoutils import PartialPrepend, VersionInfo
from nanoutils import PartialPrepend
from packaging.version import Version

try:
import rdkit
from rdkit import Chem
except ModuleNotFoundError:
# Precaution against sphinx mocking raising a TypeError
FLAGS = 0
RDKIT_VERSION = VersionInfo(0, 0, 0)
RDKIT_VERSION = Version("0.0.0")
else:
FLAGS = Chem.SanitizeFlags.SANITIZE_ALL ^ Chem.SanitizeFlags.SANITIZE_ADJUSTHS
RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__)
RDKIT_VERSION = Version(rdkit.__version__)

__all__ = ["FormatEnum", "str_to_rdmol"]

Expand Down Expand Up @@ -72,8 +73,8 @@ class FormatEnum(enum.Enum):
SMILES = PartialPrepend(str_to_rdmol, Chem.MolFromSmiles, "SMILES string", sanitize=False)
TPL = PartialPrepend(str_to_rdmol, Chem.MolFromTPLBlock, "TPL block", sanitize=False)
TPL_FILE = PartialPrepend(str_to_rdmol, Chem.MolFromTPLFile, "TPL file", sanitize=False)
if RDKIT_VERSION >= (2020, 3, 3):
if RDKIT_VERSION >= Version("2020.03.3"):
SVG = PartialPrepend(str_to_rdmol, Chem.MolFromRDKitSVG, "SVG string", sanitize=False, removeHs=False)
if RDKIT_VERSION >= (2020, 9, 1):
if RDKIT_VERSION >= Version("2020.09.1"):
PNG = PartialPrepend(str_to_rdmol, Chem.MolFromPNGString, "PNG string")
PNG_FILE = PartialPrepend(str_to_rdmol, Chem.MolFromPNGFile, "PNG file")
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.

0.10.2
******
* *placeholder*.
* Added the option to specify dummy atoms as anchor group.
* Added the option to specify the format type of anchor groups (SMILES, SMARTS, *etc.*).
* Fixed an issue wherein anchor-group-parsing could fail for mono-atomic anchors.
* Added ``packaging`` and ``rdkit-pypi`` as dependencies;
manually installing ``rdkit`` via conda is no longer necessary.


0.10.1
Expand Down
5 changes: 2 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

import pytest
import rdkit
from nanoutils import VersionInfo
from packaging.version import Version

from CAT import logger


@pytest.fixture(scope="session", autouse=True)
def rdkit_version() -> None:
"""Validate the rdkit version."""
rdkit_version = VersionInfo.from_str(rdkit.__version__)
if rdkit_version < (2021, 3, 4):
if Version(rdkit.__version__) < Version("2021.03.4"):
warnings.warn(
"The CAT test suite requires RDKit >= 2021.03.4 to properly run; "
f"observed version: {rdkit.__version__}"
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
version=version['__version__'],
description=('A collection of tools designed for the automatic '
'construction of chemical compounds.'),
long_description=f'{readme}\n\n',
long_description=readme + "\n\n",
long_description_content_type='text/x-rst',
author=['Bas van Beek', 'Jelena Belic'],
author_email='[email protected]',
Expand Down Expand Up @@ -100,6 +100,7 @@
'typing-extensions>=3.7.4.3',
'qmflows>=0.11.0',
'rdkit-pypi>=2018.03.1',
'packaging>=1.16.8',
],
setup_requires=[
'pytest-runner',
Expand Down
9 changes: 5 additions & 4 deletions tests/test_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest
import numpy as np
from scm.plams import Molecule
from nanoutils import VersionInfo
from packaging.version import Version

from CAT.data_handling.entry_points import main

Expand All @@ -27,8 +27,6 @@
DB_PATH = PATH / 'database'
PATH_REF = PATH / 'ligand_ref'

RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__)


class TestMain:
@pytest.fixture(scope="class", autouse=True)
Expand Down Expand Up @@ -60,7 +58,10 @@ def test_raise(self) -> None:
main([f'{filename}bob'])

@pytest.mark.parametrize("filename", PATH_DICT.values(), ids=PATH_DICT.keys())
@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_mol(self, filename: str) -> None:
mol = Molecule(LIG_PATH / filename)
mol_ref = Molecule(PATH_REF / filename)
Expand Down
13 changes: 5 additions & 8 deletions tests/test_gen_job_manager.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Tests for the :mod:`CAT.gen_job_manager.GenJobManager` class in :mod:`CAT.gen_job_manager`."""

import re
from os.path import (join, abspath)
from collections import abc

import pytest
import numpy as np
from scm.plams import Settings, JobManager, AMSJob, AMSResults
from assertionlib import assertion
from nanoutils import VersionInfo
from packaging.version import Version

from CAT.gen_job_manager import GenJobManager
from CAT.utils import get_formula
Expand All @@ -19,11 +18,6 @@
FOLDER = 'test_plams_workdir'


NUMPY_VERSION = VersionInfo._make(
int(i) for i in re.match(r'(\d+).(\d+).(\d+)', np.__version__).groups()
)


def test_init() -> None:
"""Test :meth:`CAT.gen_job_manager.GenJobManager.__init__`."""
manager = GenJobManager(SETTINGS, PATH, FOLDER)
Expand All @@ -40,7 +34,10 @@ def test_init() -> None:
assertion.eq(manager.input, join(ABSPATH, FOLDER, SETTINGS.hashing))


@pytest.mark.skipif(NUMPY_VERSION < (1, 16, 0), reason="Unpickling requires numpy >= 1.16.0")
@pytest.mark.skipif(
Version(np.__version__) < Version("1.16.0"),
reason="Unpickling requires numpy >= 1.16.0",
)
def test_load_job() -> None:
"""Test :meth:`CAT.gen_job_manager.GenJobManager.load_job`."""
filename = join(PATH, FOLDER, 'QD_opt_part1', 'QD_opt_part1.hash')
Expand Down
9 changes: 5 additions & 4 deletions tests/test_ligand_anchoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from scm.plams import from_smiles, Molecule, to_rdmol, PT
from assertionlib import assertion
from schema import SchemaError
from nanoutils import VersionInfo
from packaging.version import Version

from CAT.utils import get_template, KindEnum, AnchorTup, FormatEnum
from CAT.base import prep_input
Expand All @@ -36,8 +36,6 @@

PATH = Path('tests') / 'test_files'

RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__)


class TestGetFunctionalGroups:
"""Tests for :func:`CAT.attachment.ligand_anchoring.get_functional_groups`."""
Expand Down Expand Up @@ -158,7 +156,10 @@ def get_h5py_group(self) -> Generator[h5py.Group, None, None]:
})

@pytest.mark.parametrize("kwargs_id,kwargs", OPTIONS_DICT.items(), ids=OPTIONS_DICT.keys())
@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_options(self, kwargs_id: str, kwargs: Dict[str, Any], group: h5py.Group) -> None:
# Parse the anchoring options
mol = from_smiles("OC(=O)CCCCC")
Expand Down
19 changes: 13 additions & 6 deletions tests/test_ligand_attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import h5py
import numpy as np
from assertionlib import assertion
from nanoutils import VersionInfo
from packaging.version import Version
from scm.plams import Settings, Molecule

from CAT.base import prep
Expand All @@ -26,8 +26,6 @@
QD_PATH = PATH / 'qd'
DB_PATH = PATH / 'database'

RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__)


def test_get_rotmat1() -> None:
"""Test :func:`CAT.attachment.ligand_attach._get_rotmat1`."""
Expand Down Expand Up @@ -119,7 +117,10 @@ def run_cat(self, request: "_pytest.fixtures.SubRequest") -> Generator[DihedTup,
for file in files:
shutil.rmtree(file, ignore_errors=True)

@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_atoms(self, output: DihedTup) -> None:
dtype = [("symbols", "U2"), ("coords", "f8", 3)]
atoms = np.fromiter(
Expand Down Expand Up @@ -159,7 +160,10 @@ def run_cat(
for file in files:
shutil.rmtree(file, ignore_errors=True)

@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_atoms(self, output: AllignmentTup) -> None:
dtype = [("symbols", "S2"), ("coords", "f8", 3)]
iterator = ((at.symbol, at.coords) for at in output.mol)
Expand Down Expand Up @@ -215,7 +219,10 @@ def run_cat(
for file in files:
shutil.rmtree(file, ignore_errors=True)

@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_atoms(self, output: AllignmentTup) -> None:
dtype = [("symbols", "S2"), ("coords", "f8", 3)]
iterator = ((at.symbol, at.coords) for at in output.mol)
Expand Down
10 changes: 6 additions & 4 deletions tests/test_multi_ligand.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import pytest
import rdkit
from nanoutils import delete_finally, VersionInfo
from nanoutils import delete_finally
from scm.plams import Settings
from packaging.version import Version
from CAT import base

PATH = Path('tests') / 'test_files'
Expand All @@ -18,8 +19,6 @@
QD_PATH = PATH / 'qd'
DB_PATH = PATH / 'database'

RDKIT_VERSION = VersionInfo.from_str(rdkit.__version__)

with open(PATH / 'input3.yaml', 'r') as f:
SETTINGS = Settings(yaml.load(f, Loader=yaml.FullLoader))

Expand All @@ -33,7 +32,10 @@ def _iterfiles(file1, file2):


@delete_finally(LIG_PATH, QD_PATH, DB_PATH)
@pytest.mark.xfail(RDKIT_VERSION < (2021, 3, 4), reason="requires rdkit >= 2021.03.4")
@pytest.mark.xfail(
Version(rdkit.__version__) < Version("2021.03.4"),
reason="requires rdkit >= 2021.03.4",
)
def test_multi_ligand() -> None:
"""Test :mod:`CAT.multi_ligand`."""
base.prep(SETTINGS.copy())
Expand Down

0 comments on commit c4f03d3

Please sign in to comment.