From 0353d9590ca85c9a36b0d8eeabc03237e2c79d6f Mon Sep 17 00:00:00 2001 From: Eleanor Lewis Date: Mon, 1 Jul 2024 14:16:02 -0700 Subject: [PATCH] get url from env first if possible --- pori_python/graphkb/util.py | 3 ++- pori_python/ipr/connection.py | 2 +- pori_python/ipr/inputs.py | 5 +++-- pori_python/ipr/main.py | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pori_python/graphkb/util.py b/pori_python/graphkb/util.py index 7c6ef94..def8f0d 100644 --- a/pori_python/graphkb/util.py +++ b/pori_python/graphkb/util.py @@ -1,5 +1,6 @@ import hashlib import json +import os import logging import re import time @@ -95,7 +96,7 @@ def cache_key(request_body) -> str: class GraphKBConnection: def __init__( self, - url: str = DEFAULT_URL, + url: str = os.environ.get("GRAPHKB_URL", DEFAULT_URL), username: str = "", password: str = "", use_global_cache: bool = True, diff --git a/pori_python/ipr/connection.py b/pori_python/ipr/connection.py index c86a373..d842f0d 100644 --- a/pori_python/ipr/connection.py +++ b/pori_python/ipr/connection.py @@ -11,7 +11,7 @@ class IprConnection: - def __init__(self, username: str, password: str, url: str = DEFAULT_URL): + def __init__(self, username: str, password: str, url: str = os.environ.get("IPR_URL", DEFAULT_URL)): self.token = None self.url = url self.username = username diff --git a/pori_python/ipr/inputs.py b/pori_python/ipr/inputs.py index c18608e..2d97797 100644 --- a/pori_python/ipr/inputs.py +++ b/pori_python/ipr/inputs.py @@ -18,13 +18,14 @@ IprVariant, ) from .util import hash_key, logger, pandas_falsy +from .constants import DEFAULT_URL protein_letters_3to1.setdefault('Ter', '*') SPECIFICATION = os.path.join(os.path.dirname(__file__), 'content.spec.json') -# content in the local specification should match the values in IPR_API_SPEC_JSON_URL -IPR_API_SPEC_JSON_URL = 'https://ipr-api.bcgsc.ca/api/spec.json' +# content in the local specification should match the values in IPR_API_SPEC_JSON_URL +IPR_API_SPEC_JSON_URL = f'{os.environ.get("IPR_URL", DEFAULT_URL)}/spec.json' # TODO: GERO-307 - use SPECIFICATION json to derive the variant required and optional details defined below diff --git a/pori_python/ipr/main.py b/pori_python/ipr/main.py index ea53473..74d15cb 100644 --- a/pori_python/ipr/main.py +++ b/pori_python/ipr/main.py @@ -69,8 +69,8 @@ def command_interface() -> None: req.add_argument( '-c', '--content', required=True, type=file_path, help="Report Content as JSON" ) - parser.add_argument('--ipr_url', default=DEFAULT_URL) - parser.add_argument('--graphkb_url', default=None) + parser.add_argument('--ipr_url', default=os.environ.get("IPR_URL", DEFAULT_URL)) + parser.add_argument('--graphkb_url', default=os.environ.get("GRAPHKB_URL", None)) parser.add_argument('--log_level', default='info', choices=LOG_LEVELS.keys()) parser.add_argument( '--therapeutics', default=False, help='Generate therapeutic options', action='store_true'