From 2c577f9ef63fb564961786e6a8c691880578a8a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:52:20 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- repo2docker/contentproviders/hydroshare.py | 10 +++++---- setup.py | 1 + tests/contentproviders/test_hydroshare.py | 26 ++++++++++++++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/repo2docker/contentproviders/hydroshare.py b/repo2docker/contentproviders/hydroshare.py index ce870b59..ba232365 100755 --- a/repo2docker/contentproviders/hydroshare.py +++ b/repo2docker/contentproviders/hydroshare.py @@ -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): @@ -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" diff --git a/setup.py b/setup.py index d37aa17c..a4e59d8c 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,7 @@ def finalize_options(self): def run(self): import json + import requests resp = requests.get(self.url) diff --git a/tests/contentproviders/test_hydroshare.py b/tests/contentproviders/test_hydroshare.py index abd485f3..e6d8a4c8 100755 --- a/tests/contentproviders/test_hydroshare.py +++ b/tests/contentproviders/test_hydroshare.py @@ -1,5 +1,5 @@ -import os import hashlib +import os from tempfile import TemporaryDirectory import pytest @@ -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 @@ -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", }, ), ], @@ -56,4 +65,3 @@ def test_fetch(specs: list[str], md5tree): h = hashlib.md5() h.update(f.read()) assert h.hexdigest() == expected_sha -