Spaces:
Running
Running
Upload folder using huggingface_hub (part 2)
Browse files- scripts/provision_local_blast.py +13 -1
- tests/test_local_blast.py +12 -0
scripts/provision_local_blast.py
CHANGED
|
@@ -27,7 +27,19 @@ def digest(path):
|
|
| 27 |
|
| 28 |
|
| 29 |
def download(name, target):
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
shutil.copyfileobj(source, out)
|
| 32 |
return target
|
| 33 |
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def download(name, target):
|
| 30 |
+
if name == "reldate.txt":
|
| 31 |
+
response = urllib.request.urlopen(
|
| 32 |
+
"https://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/reldate.txt",
|
| 33 |
+
timeout=120,
|
| 34 |
+
)
|
| 35 |
+
elif name == "uniprot_sprot.fasta.gz":
|
| 36 |
+
response = urllib.request.urlopen(
|
| 37 |
+
"https://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot.fasta.gz",
|
| 38 |
+
timeout=120,
|
| 39 |
+
)
|
| 40 |
+
else:
|
| 41 |
+
raise ValueError("Only the two fixed official Swiss-Prot resources may be downloaded")
|
| 42 |
+
with response as source, target.open("wb") as out:
|
| 43 |
shutil.copyfileobj(source, out)
|
| 44 |
return target
|
| 45 |
|
tests/test_local_blast.py
CHANGED
|
@@ -102,3 +102,15 @@ def test_native_reference_does_not_claim_an_ncbi_page_was_queried(monkeypatch):
|
|
| 102 |
"blast": {"source": "local-blast+", "top_hit": {"accession": "P68871"}}
|
| 103 |
}, "test-user")
|
| 104 |
assert captured == []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
"blast": {"source": "local-blast+", "top_hit": {"accession": "P68871"}}
|
| 103 |
}, "test-user")
|
| 104 |
assert captured == []
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_reference_download_resource_allowlist(monkeypatch, tmp_path):
|
| 108 |
+
import runpy
|
| 109 |
+
module = runpy.run_path(str(Path(__file__).resolve().parents[1] / "scripts" / "provision_local_blast.py"))
|
| 110 |
+
opened = []
|
| 111 |
+
monkeypatch.setattr(module["urllib"].request, "urlopen",
|
| 112 |
+
lambda *args, **kwargs: opened.append(args))
|
| 113 |
+
for name in ("file:///etc/passwd", "../reldate.txt", "https://example.com", "unexpected"):
|
| 114 |
+
with pytest.raises(ValueError, match="fixed official"):
|
| 115 |
+
module["download"](name, tmp_path / "unused")
|
| 116 |
+
assert opened == []
|