Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXP] provide signature file loading function via HTTP #2256

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/sourmash/sourmash_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,24 @@
return db


def _load_http_get(filename, **kwargs):
"Load collection from .sig/.sig.gz file available via HTTP"
db = None
if filename.startswith('http'):
import requests

Check warning on line 371 in src/sourmash/sourmash_args.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/sourmash_args.py#L371

Added line #L371 was not covered by tests

req = requests.get(filename, stream=True)

Check warning on line 373 in src/sourmash/sourmash_args.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/sourmash_args.py#L373

Added line #L373 was not covered by tests

# CTB: does this follow redirects?
if req.status_code == 200:
# load from req.raw as LinearIndex, then pass into MultiIndex to
# generate a manifest.
lidx = LinearIndex.load(req.raw, filename=filename)
db = MultiIndex.load((lidx,), (None,), parent=None)

Check warning on line 380 in src/sourmash/sourmash_args.py

View check run for this annotation

Codecov / codecov/patch

src/sourmash/sourmash_args.py#L379-L380

Added lines #L379 - L380 were not covered by tests

return db


def _load_standalone_manifest(filename, **kwargs):
from sourmash.index import StandaloneManifestIndex
idx = StandaloneManifestIndex.load(filename)
Expand Down Expand Up @@ -426,6 +444,7 @@
# all loader functions, in order.
_loader_functions = [
("load from stdin", _load_stdin),
("load via HTTP GET", _load_http_get),
("load collection from sqlitedb", _load_sqlite_db),
("load from standalone manifest", _load_standalone_manifest),
("load from path (file or directory)", _multiindex_load_from_path),
Expand Down