Skip to content

Commit

Permalink
Clean up dependencies related to ersilia test module (#1238)
Browse files Browse the repository at this point in the history
* make scipy and sklearn optional installs

* Sort imports; raise import error with useful instruction for installing missing packages
  • Loading branch information
DhanshreeA authored Aug 22, 2024
1 parent a0cdd0d commit ce4600d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
40 changes: 19 additions & 21 deletions ersilia/publish/test.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
# TODO adapt to input-type agnostic. For now, it works only with Compound input types.

from collections import defaultdict
from sklearn.metrics import mean_squared_error
import numpy as np
import time
from datetime import datetime
import os
import json
import tempfile
import types
import os
import subprocess
import shutil
import tempfile
import time
import re
import numpy as np
from scipy.stats import spearmanr
import types
from collections import defaultdict
from datetime import datetime

import numpy as np

from ersilia.utils.conda import SimpleConda
from .. import ErsiliaBase, ErsiliaModel, throw_ersilia_exception
from ..cli import echo
from ..core.session import Session
from ..default import EOS, INFORMATION_FILE
from ..io.input import ExampleGenerator
from .. import ErsiliaBase
from .. import throw_ersilia_exception
from .. import ErsiliaModel
from ..utils.exceptions_utils import test_exceptions as texc
from ..utils.logging import make_temp_dir
from ..utils.terminal import run_command_check_output
from ..core.session import Session
from ..default import INFORMATION_FILE
from ..default import EOS


# Check if we have the required imports in the environment
MISSING_PACKAGES = False
try:
from scipy.stats import spearmanr
from sklearn.metrics import mean_squared_error
from fuzzywuzzy import fuzz
except:
fuzz = None
except ImportError:
MISSING_PACKAGES = True

RUN_FILE = "run.sh"
DATA_FILE = "data.csv"
Expand Down Expand Up @@ -891,6 +885,10 @@ def make_output(self, output, time):


def run(self, output_file):
if MISSING_PACKAGES:
raise ImportError(
"Missing packages required for testing, please install test extras as 'pip install ersilia[test]'"
)
output_file = os.path.join(self._model_path(self.model_id), "TEST_MODULE_OUTPUT.csv")
start = time.time()
self.check_information(output_file)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ scikit-learn = "<=1.5.1"
# Instead of using poetry dependency groups, we use extras to make it pip installable
lake = ["isaura"]
docs = ["sphinx", "jinja2"]
test = ["pytest", "fuzzywuzzy"]
test = ["pytest", "fuzzywuzzy", "scipy", "scikit-learn"]
#all = [lake, docs, test]

[tool.poetry.scripts]
Expand Down

0 comments on commit ce4600d

Please sign in to comment.