Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 21, 2024
1 parent cd9911c commit 2c577f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
10 changes: 6 additions & 4 deletions repo2docker/contentproviders/hydroshare.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
import os
import shutil
import time
import tempfile
import time
import zipfile
from datetime import datetime, timedelta, timezone
from urllib.request import urlretrieve
from urllib.parse import urlparse, urlunparse
from urllib.request import urlretrieve

from ..utils import is_doi
from .base import ContentProviderException
from .doi import DoiProvider
from ..utils import is_doi


class Hydroshare(DoiProvider):
Expand Down Expand Up @@ -70,7 +70,9 @@ def fetch(self, spec, output_dir, yield_output=False, timeout=120):
parts = urlparse(url)
self.resource_id = parts.path.strip("/").rsplit("/", maxsplit=1)[1]

bag_url = urlunparse(parts._replace(path=f"django_irods/download/bags/{self.resource_id}"))
bag_url = urlunparse(
parts._replace(path=f"django_irods/download/bags/{self.resource_id}")
)

yield f"Downloading {bag_url}.\n"

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def finalize_options(self):

def run(self):
import json

import requests

resp = requests.get(self.url)
Expand Down
26 changes: 17 additions & 9 deletions tests/contentproviders/test_hydroshare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import hashlib
import os
from tempfile import TemporaryDirectory

import pytest
Expand All @@ -11,16 +11,25 @@
("spec", "url"),
[
# Test a hydroshare DOI
("10.4211/hs.b8f6eae9d89241cf8b5904033460af61", "http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61"),
(
"10.4211/hs.b8f6eae9d89241cf8b5904033460af61",
"http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61",
),
# Hydroshare DOI in a different form
("https://doi.org/10.4211/hs.b8f6eae9d89241cf8b5904033460af61", "http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61"),
(
"https://doi.org/10.4211/hs.b8f6eae9d89241cf8b5904033460af61",
"http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61",
),
# Test a non-hydroshare DOI
("doi:10.7910/DVN/TJCLKP", None),
# Test a hydroshare URL
("http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61", "http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61"),
(
"http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61",
"http://www.hydroshare.org/resource/b8f6eae9d89241cf8b5904033460af61",
),
# Test a random URL
("https://www.eff.org/cyberspace-independence", None)
]
("https://www.eff.org/cyberspace-independence", None),
],
)
def test_detect(spec, url):
assert Hydroshare().detect(spec) == url
Expand All @@ -30,11 +39,11 @@ def test_detect(spec, url):
("specs", "md5tree"),
[
(
("https://www.hydroshare.org/resource/8f7c2f0341ef4180b0dbe97f59130756/", ),
("https://www.hydroshare.org/resource/8f7c2f0341ef4180b0dbe97f59130756/",),
{
"binder/Dockerfile": "872ab0ef22645a42a5560eae640cdc77",
"README.md": "88ac547c3a5f616f6d26e0689d63a113",
"notebooks/sanity-check.ipynb": "7fc4c455bc8cd244479f4d2282051ee6"
"notebooks/sanity-check.ipynb": "7fc4c455bc8cd244479f4d2282051ee6",
},
),
],
Expand All @@ -56,4 +65,3 @@ def test_fetch(specs: list[str], md5tree):
h = hashlib.md5()
h.update(f.read())
assert h.hexdigest() == expected_sha

0 comments on commit 2c577f9

Please sign in to comment.