From f5bd3784d0083cf0278844123206dda8d884bbf2 Mon Sep 17 00:00:00 2001 From: deeenes Date: Thu, 14 Sep 2023 15:39:13 +0200 Subject: [PATCH] new option `fallback_urls`; by default it contains the http domain of OmniPath --- omnipath/_core/utils/_options.py | 5 +++++ omnipath/constants/_pkg_constants.py | 1 + tests/conftest.py | 2 ++ tests/test_downloader.py | 2 ++ tests/test_interactions.py | 2 ++ tests/test_options.py | 2 ++ tests/test_requests.py | 2 ++ 7 files changed, 16 insertions(+) diff --git a/omnipath/_core/utils/_options.py b/omnipath/_core/utils/_options.py index 1ec035e..6f88781 100644 --- a/omnipath/_core/utils/_options.py +++ b/omnipath/_core/utils/_options.py @@ -89,6 +89,11 @@ class Options: validator=[attr.validators.instance_of(str), _is_valid_url], on_setattr=attr.setters.validate, ) + fallback_urls: tuple[str] = attr.ib( + default=DEFAULT_OPTIONS.fallback_urls, + converter=(lambda val: (val,) if isinstance(val, str) else tuple(val)), + on_setattr=attr.setters.convert, + ) license: License = attr.ib( default=None, validator=attr.validators.optional(attr.validators.instance_of((str, License))), diff --git a/omnipath/constants/_pkg_constants.py b/omnipath/constants/_pkg_constants.py index bc45798..41e9456 100644 --- a/omnipath/constants/_pkg_constants.py +++ b/omnipath/constants/_pkg_constants.py @@ -31,6 +31,7 @@ class DEFAULT_OPTIONS: """Default options for :attr:`omnipath.options`.""" url: str = "https://omnipathdb.org" + fallback_urls: tuple[str] = ("http://no-tls.omnipathdb.org",) license: Optional[License] = None num_retries: int = 3 timeout: int = 600 diff --git a/tests/conftest.py b/tests/conftest.py index 01057da..9c19c03 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,6 +52,7 @@ def options() -> "Options": opt = Options.from_config() opt.cache = "memory" opt.progress_bar = False + opt.fallback_urls = () return opt @@ -97,6 +98,7 @@ def server_url(): @pytest.fixture(scope="function") def downloader(options) -> "Downloader": + options.fallback_urls = () return Downloader(options) diff --git a/tests/test_downloader.py b/tests/test_downloader.py index 09637c5..acab86b 100644 --- a/tests/test_downloader.py +++ b/tests/test_downloader.py @@ -12,6 +12,8 @@ from omnipath.constants._pkg_constants import UNKNOWN_SERVER_VERSION, Endpoint from omnipath._core.downloader._downloader import Downloader, _get_server_version +opt.fallback_urls = () + class TestDownloader: def test_options_wrong_type(self): diff --git a/tests/test_interactions.py b/tests/test_interactions.py index 5858885..d993978 100644 --- a/tests/test_interactions.py +++ b/tests/test_interactions.py @@ -28,6 +28,8 @@ lncRNAmRNA, ) +options.fallback_urls = () + class TestInteractions: def test_all_excluded_excluded(self): diff --git a/tests/test_options.py b/tests/test_options.py index 52988b4..1e2a0f5 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -101,6 +101,7 @@ def test_write_config(self, options: Options, config_backup): options.timeout = 1337 options.license = License.COMMERCIAL options.password = "foobarbaz" + options.fallback_urls = DEFAULT_OPTIONS.fallback_urls options.write() new_opt = Options.from_config() @@ -118,6 +119,7 @@ def test_write_config(self, options: Options, config_backup): def test_write_new_section(self, options: Options, config_backup): options.timeout = 42 + options.fallback_urls = DEFAULT_OPTIONS.fallback_urls options.write("https://foo.bar") new_opt = Options.from_config("https://foo.bar") diff --git a/tests/test_requests.py b/tests/test_requests.py index 447d3c6..13f983c 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -18,6 +18,8 @@ from omnipath.constants._pkg_constants import Key, Endpoint from omnipath._core.requests._annotations import _MAX_N_PROTS +options.fallback_urls = () + class TestEnzsub: def test_str_repr(self):