diff --git a/.github/workflows/airtable_to_json.yml b/.github/workflows/airtable_to_json.yml index 9720ecca6..ea8f499dc 100644 --- a/.github/workflows/airtable_to_json.yml +++ b/.github/workflows/airtable_to_json.yml @@ -19,6 +19,7 @@ jobs: - name: Install dependencies run: + pip install pyairtable pip install airtable-python-wrapper pip install boto3 diff --git a/ersilia/_static_version.py b/ersilia/_static_version.py index 89eeb1746..f00373dda 100644 --- a/ersilia/_static_version.py +++ b/ersilia/_static_version.py @@ -1 +1 @@ -version = "0.1.33" +version = "0.1.34" diff --git a/ersilia/db/hubdata/interfaces.py b/ersilia/db/hubdata/interfaces.py index d8fb0976e..bbd0dbbd8 100644 --- a/ersilia/db/hubdata/interfaces.py +++ b/ersilia/db/hubdata/interfaces.py @@ -1,7 +1,8 @@ import requests -from pyairtable import Table +import importlib from ... import ErsiliaBase from ...default import AIRTABLE_MODEL_HUB_BASE_ID, AIRTABLE_MODEL_HUB_TABLE_NAME +from ...setup.requirements.pyairtable import PyAirtableRequirement AIRTABLE_MAX_ROWS = 100000 AIRTABLE_PAGE_SIZE = 100 @@ -16,7 +17,15 @@ def __init__(self, config_json): self.max_rows = AIRTABLE_MAX_ROWS self.page_size = AIRTABLE_PAGE_SIZE self.write_api_key = None - self.table = Table(self.api_key, self.base_id, self.table_name) + self.table = self._create_table() + + def _create_table(self): + pyairtable_req = PyAirtableRequirement() + if not pyairtable_req.is_installed(): + self.logger.debug("Installing PyAirTable from pip") + pyairtable_req.install() + pyairtable = importlib.import_module("pyairtable") + return pyairtable.Table(self.api_key, self.base_id, self.table_name) @staticmethod def _get_read_only_airtable_api_key(): diff --git a/ersilia/setup/requirements/isaura.py b/ersilia/setup/requirements/isaura.py index 4518d2dca..ba2337835 100644 --- a/ersilia/setup/requirements/isaura.py +++ b/ersilia/setup/requirements/isaura.py @@ -1,7 +1,7 @@ import importlib from ...utils.terminal import run_command - +# TODO class IsauraRequirement(object): def __init__(self): self.name = "isaura" diff --git a/ersilia/setup/requirements/pyairtable.py b/ersilia/setup/requirements/pyairtable.py new file mode 100644 index 000000000..cca83530c --- /dev/null +++ b/ersilia/setup/requirements/pyairtable.py @@ -0,0 +1,18 @@ +import importlib +import sys +from ...utils.terminal import run_command + +class PyAirtableRequirement: + def __init__(self): + self.name = "pyairtable" + + def is_installed(self): + try: + importlib.import_module(self.name) + return True + except: + return False + + def install(self): + version = '<2' if sys.version_info.minor == 7 else '<3' + run_command(f"python -m pip install 'pyairtable{version}'") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index f7cb10655..c22b7102a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ersilia" -version = "0.1.33" +version = "0.1.34" description = "A hub of AI/ML models for open source drug discovery and global health" license = "GPLv3" authors = ["Ersilia Open Source Initiative "] @@ -40,10 +40,6 @@ pandas = [ ] h5py = "^3.7.0" # For compatibility with isaura loguru = "^0.6.0" # For compatibility with isaura -pyairtable = [ - {version="<2", python="3.7.*"}, - {version="<3", python=">=3.8"}, -] PyYAML = "^6.0.1" dockerfile-parse = "^2.0.1" tqdm = "^4.66.1"