Skip to content

Commit

Permalink
Fix Incorrectly Delayed Import in 1.2.0 (#173)
Browse files Browse the repository at this point in the history
1.2.0 introduced an error in which the minimal installation no longer
worked - this resolves that.
  • Loading branch information
JacksonBurns authored Feb 16, 2024
2 parents daf00ac + 90d276c commit ef646ac
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ jobs:
channel_priority: flexible
create-args: |
python=${{ matrix.python-version }}
- name: Install Dependencies
- name: Install Minimal Dependencies
run: |
python -m pip install -e .[molecules]
python -m pip install -e .
python -m pip install coverage pytest
- name: Run Tests
- name: Run Minimal Tests
run: |
coverage run --source=. --omit=astartes/__init__.py,setup.py,test/* -m pytest -v
- name: Install Molecules Dependencies
run: |
python -m pip install -e .[molecules]
- name: Run All Tests
run: |
coverage run --source=. --omit=astartes/__init__.py,setup.py,test/* -m pytest -v
- name: Show Coverage
Expand Down
2 changes: 1 addition & 1 deletion astartes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# convenience import to enable 'from astartes import train_test_split'
from .main import train_test_split, train_val_test_split

__version__ = "1.2.0"
__version__ = "1.2.1"

# DO NOT do this:
# from .molecules import train_test_split_molecules
Expand Down
7 changes: 6 additions & 1 deletion astartes/utils/aimsim_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from astartes.utils.exceptions import MoleculesNotInstalledError

Molecule = None
try:
"""
aimsim depends on sklearn_extra, which uses a version checking technique that is due to
Expand All @@ -16,7 +17,7 @@
from aimsim.chemical_datastructures import Molecule
from aimsim.exceptions import LoadingError
except ImportError: # pragma: no cover
raise MoleculesNotInstalledError("""To use molecule featurizer, install astartes with pip install astartes[molecules].""")
pass # Raise an error later


def featurize_molecules(molecules, fingerprint, fprints_hopts):
Expand All @@ -30,6 +31,10 @@ def featurize_molecules(molecules, fingerprint, fprints_hopts):
Returns:
np.array: X array (featurized molecules)
"""
if Molecule is None:
raise MoleculesNotInstalledError(
"""To use molecule featurizer, install astartes with pip install astartes[molecules] or conda install astartes aimsim."""
)
X = []
for molecule in molecules:
try:
Expand Down
20 changes: 14 additions & 6 deletions test/functional/test_molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
import warnings

import numpy as np
from rdkit import Chem

from astartes.molecules import (
train_test_split_molecules,
train_val_test_split_molecules,
)
from astartes.samplers import (
DETERMINISTIC_EXTRAPOLATION_SAMPLERS,
IMPLEMENTED_EXTRAPOLATION_SAMPLERS,
IMPLEMENTED_INTERPOLATION_SAMPLERS,
)
from astartes.utils.warnings import ImperfectSplittingWarning

aimsim = None
REASON = None
try:
import aimsim
from rdkit import Chem

from astartes.molecules import (
train_test_split_molecules,
train_val_test_split_molecules,
)
except ModuleNotFoundError:
REASON = "molecules subpackage not installed"


@unittest.skipIf(aimsim is None, reason=REASON)
class Test_molecules(unittest.TestCase):
"""
Test the various functionalities of molecules.
Expand Down
12 changes: 11 additions & 1 deletion test/unit/samplers/extrapolative/test_Scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import numpy as np

from astartes import train_test_split
from astartes.samplers import Scaffold
from astartes.utils.exceptions import InvalidConfigurationError
from astartes.utils.warnings import NoMatchingScaffold

aimsim = None
REASON = None
try:
# deliberately trigger an error if molecules subpackage missing
import aimsim

from astartes.samplers import Scaffold
except ModuleNotFoundError:
REASON = "molecules subpackage not installed"


@unittest.skipIf(aimsim is None, reason=REASON)
class Test_scaffold(unittest.TestCase):
"""
Test the various functionalities of Scaffold.
Expand Down
11 changes: 10 additions & 1 deletion test/unit/samplers/extrapolative/test_molecular_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
import numpy as np

from astartes import train_test_split
from astartes.samplers import MolecularWeight

aimsim = None
REASON = None
try:
import aimsim

from astartes.samplers import MolecularWeight
except ModuleNotFoundError:
REASON = "molecules subpackage not installed"


@unittest.skipIf(aimsim is None, reason=REASON)
class Test_MolecularWeight(unittest.TestCase):
"""
Test the various functionalities of MolecularWeight.
Expand Down

0 comments on commit ef646ac

Please sign in to comment.