Skip to content

Commit

Permalink
new option fallback_urls; by default it contains the http domain of…
Browse files Browse the repository at this point in the history
… OmniPath
  • Loading branch information
deeenes committed Sep 14, 2023
1 parent 7125bde commit f5bd378
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions omnipath/_core/utils/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down
1 change: 1 addition & 0 deletions omnipath/constants/_pkg_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def options() -> "Options":
opt = Options.from_config()
opt.cache = "memory"
opt.progress_bar = False
opt.fallback_urls = ()
return opt


Expand Down Expand Up @@ -97,6 +98,7 @@ def server_url():

@pytest.fixture(scope="function")
def downloader(options) -> "Downloader":
options.fallback_urls = ()
return Downloader(options)


Expand Down
2 changes: 2 additions & 0 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
lncRNAmRNA,
)

options.fallback_urls = ()


class TestInteractions:
def test_all_excluded_excluded(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f5bd378

Please sign in to comment.