From c614e1bddb3bcc5e5ad4c8e0f4c66ff4d4f47d0c Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 11:59:40 -0400 Subject: [PATCH 01/11] Remove many deprecated pylint options These were mostly useful for the python2->python3 transition --- .pylintrc | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7634d5b6..c94307d3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -50,7 +50,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init,similarities,bad-continuation,,import-error +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,deprecated-pragma,attribute-defined-outside-init,similarities,,import-error # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -111,12 +111,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=2000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -196,36 +190,21 @@ spelling-store-unknown-words=no [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -class-name-hint=[A-Z_][a-zA-Z0-9]+$ - # Regular expression matching correct class names class-rgx=[A-Z_][a-zA-Z0-9]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -233,9 +212,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,50})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,50})|(_[a-z0-9_]*))$ @@ -245,21 +221,12 @@ good-names=i,j,k,w,e,s,n,x,y,z,cv,ax # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -275,9 +242,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 4e895728c2087945fcb48b7abda494eb7adef291 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:19:47 -0400 Subject: [PATCH 02/11] Do not use dict() use {} --- pooch/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pooch/core.py b/pooch/core.py index 674c2cf1..901aabfe 100644 --- a/pooch/core.py +++ b/pooch/core.py @@ -489,10 +489,10 @@ def __init__( self.path = path self.base_url = base_url if registry is None: - registry = dict() + registry = {} self.registry = registry if urls is None: - urls = dict() + urls = {} self.urls = dict(urls) self.retry_if_failed = retry_if_failed self.allow_updates = allow_updates From 11ecf78258af69e4dee13beed8c212d0a5ceb327 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:21:41 -0400 Subject: [PATCH 03/11] Always specify timeout for get requests. --- pooch/downloaders.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pooch/downloaders.py b/pooch/downloaders.py index 383f2a12..8a84b798 100644 --- a/pooch/downloaders.py +++ b/pooch/downloaders.py @@ -193,17 +193,19 @@ def __call__(self, url, output_file, pooch, check_only=False): """ if check_only: - response = requests.head(url, allow_redirects=True) + timeout = self.kwargs.get("timeout", 5) + response = requests.head(url, timeout=timeout, allow_redirects=True) available = bool(response.status_code == 200) return available kwargs = self.kwargs.copy() + timeout = kwargs.pop("timeout", 5) kwargs.setdefault("stream", True) ispath = not hasattr(output_file, "write") if ispath: output_file = open(output_file, "w+b") try: - response = requests.get(url, **kwargs) + response = requests.get(url, timeout=timeout, **kwargs) response.raise_for_status() content = response.iter_content(chunk_size=self.chunk_size) total = int(response.headers.get("content-length", 0)) @@ -627,7 +629,7 @@ def doi_to_url(doi): """ # Use doi.org to resolve the DOI to the repository website. - response = requests.get(f"https://doi.org/{doi}") + response = requests.get(f"https://doi.org/{doi}", timeout=5) url = response.url if 400 <= response.status_code < 600: raise ValueError( @@ -781,7 +783,8 @@ def api_response(self): if self._api_response is None: article_id = self.archive_url.split("/")[-1] self._api_response = requests.get( - f"https://zenodo.org/api/records/{article_id}" + f"https://zenodo.org/api/records/{article_id}", + timeout=5, ).json() return self._api_response @@ -801,7 +804,6 @@ def download_url(self, file_name): download_url : str The HTTP URL that can be used to download the file. """ - files = {item["key"]: item for item in self.api_response["files"]} if file_name not in files: raise ValueError( @@ -879,7 +881,8 @@ def api_response(self): if self._api_response is None: # Use the figshare API to find the article ID from the DOI article = requests.get( - f"https://api.figshare.com/v2/articles?doi={self.doi}" + f"https://api.figshare.com/v2/articles?doi={self.doi}", + timeout=5, ).json()[0] article_id = article["id"] # Parse desired version from the doi @@ -906,7 +909,7 @@ def api_response(self): f"{article_id}/versions/{version}" ) # Make the request and return the files in the figshare repository - response = requests.get(api_url) + response = requests.get(api_url, timeout=5) response.raise_for_status() self._api_response = response.json()["files"] @@ -977,7 +980,6 @@ def initialize(cls, doi, archive_url): # Access the DOI as if this was a DataVerse instance response = cls._get_api_response(doi, archive_url) - # If we failed, this is probably not a DataVerse instance if 400 <= response.status_code < 600: return None @@ -998,7 +1000,8 @@ def _get_api_response(cls, doi, archive_url): parsed = parse_url(archive_url) response = requests.get( f"{parsed['protocol']}://{parsed['netloc']}/api/datasets/" - f":persistentId?persistentId=doi:{doi}" + f":persistentId?persistentId=doi:{doi}", + timeout=5, ) return response @@ -1036,7 +1039,6 @@ def download_url(self, file_name): """ parsed = parse_url(self.archive_url) - # Iterate over the given files until we find one of the requested name for filedata in self.api_response.json()["data"]["latestVersion"]["files"]: if file_name == filedata["dataFile"]["filename"]: From 6c165df567b5581562939cb8fe4aaee67015bf29 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:24:56 -0400 Subject: [PATCH 04/11] Always specify encoding when opening files. --- pooch/core.py | 2 +- pooch/downloaders.py | 4 ++++ pooch/hashes.py | 2 +- pooch/tests/test_core.py | 10 +++++----- pooch/tests/test_hashes.py | 4 ++-- pooch/tests/test_integration.py | 2 +- pooch/tests/test_utils.py | 8 ++++---- pooch/tests/utils.py | 4 ++-- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pooch/core.py b/pooch/core.py index 901aabfe..23aaa225 100644 --- a/pooch/core.py +++ b/pooch/core.py @@ -646,7 +646,7 @@ def load_registry(self, fname): fin = fname else: # It's a file path - fin = stack.enter_context(open(fname)) + fin = stack.enter_context(open(fname, encoding="utf-8")) for linenum, line in enumerate(fin): if isinstance(line, bytes): diff --git a/pooch/downloaders.py b/pooch/downloaders.py index 8a84b798..56b67f4d 100644 --- a/pooch/downloaders.py +++ b/pooch/downloaders.py @@ -203,7 +203,9 @@ def __call__(self, url, output_file, pooch, check_only=False): kwargs.setdefault("stream", True) ispath = not hasattr(output_file, "write") if ispath: + # pylint: disable=consider-using-with output_file = open(output_file, "w+b") + # pylint: enable=consider-using-with try: response = requests.get(url, timeout=timeout, **kwargs) response.raise_for_status() @@ -344,7 +346,9 @@ def __call__(self, url, output_file, pooch, check_only=False): ispath = not hasattr(output_file, "write") if ispath: + # pylint: disable=consider-using-with output_file = open(output_file, "w+b") + # pylint: enable=consider-using-with try: ftp.login(user=self.username, passwd=self.password, acct=self.account) command = f"RETR {parsed_url['path']}" diff --git a/pooch/hashes.py b/pooch/hashes.py index d487d5f4..ebac68b9 100644 --- a/pooch/hashes.py +++ b/pooch/hashes.py @@ -215,7 +215,7 @@ def make_registry(directory, output, recursive=True): hashes = [file_hash(str(directory / fname)) for fname in files] - with open(output, "w") as outfile: + with open(output, "w", encoding="utf-8") as outfile: for fname, fhash in zip(files, hashes): # Only use Unix separators for the registry so that we don't go # insane dealing with file paths. diff --git a/pooch/tests/test_core.py b/pooch/tests/test_core.py index 0a46aea5..73262763 100644 --- a/pooch/tests/test_core.py +++ b/pooch/tests/test_core.py @@ -317,7 +317,7 @@ def test_pooch_update(): # Create a dummy version of tiny-data.txt that is different from the # one in the remote storage true_path = str(path / "tiny-data.txt") - with open(true_path, "w") as fin: + with open(true_path, "w", encoding="utf-8") as fin: fin.write("different data") # Setup a pooch in a temp dir pup = Pooch(path=path, base_url=BASEURL, registry=REGISTRY) @@ -344,7 +344,7 @@ def test_pooch_update_disallowed(): # Create a dummy version of tiny-data.txt that is different from the # one in the remote storage true_path = str(path / "tiny-data.txt") - with open(true_path, "w") as fin: + with open(true_path, "w", encoding="utf-8") as fin: fin.write("different data") # Setup a pooch in a temp dir pup = Pooch( @@ -367,7 +367,7 @@ def test_pooch_update_disallowed_environment(): # Create a dummy version of tiny-data.txt that is different from # the one in the remote storage true_path = str(path / "tiny-data.txt") - with open(true_path, "w") as fin: + with open(true_path, "w", encoding="utf-8") as fin: fin.write("different data") # Setup a pooch in a temp dir pup = create( @@ -454,7 +454,7 @@ def test_pooch_load_registry_fileobj(): # Text mode pup = Pooch(path="", base_url="") - with open(path) as fin: + with open(path, "r", encoding="utf-8") as fin: pup.load_registry(fin) assert pup.registry == REGISTRY assert pup.registry_files.sort() == list(REGISTRY).sort() @@ -604,7 +604,7 @@ def test_download_action(): assert verb == "Updating" with temporary_file() as tmp: - with open(tmp, "w") as output: + with open(tmp, "w", encoding="utf-8") as output: output.write("some data") action, verb = download_action(Path(tmp), known_hash=file_hash(tmp)) assert action == "fetch" diff --git a/pooch/tests/test_hashes.py b/pooch/tests/test_hashes.py index 9932b986..7bac299d 100644 --- a/pooch/tests/test_hashes.py +++ b/pooch/tests/test_hashes.py @@ -71,7 +71,7 @@ def test_make_registry(data_dir_mirror): outfile.close() try: make_registry(data_dir_mirror, outfile.name, recursive=False) - with open(outfile.name) as fout: + with open(outfile.name, encoding="utf-8") as fout: registry = fout.read() assert registry == REGISTRY # Check that the registry can be used. @@ -92,7 +92,7 @@ def test_make_registry_recursive(data_dir_mirror): outfile.close() try: make_registry(data_dir_mirror, outfile.name, recursive=True) - with open(outfile.name) as fout: + with open(outfile.name, encoding="utf-8") as fout: registry = fout.read() assert registry == REGISTRY_RECURSIVE # Check that the registry can be used. diff --git a/pooch/tests/test_integration.py b/pooch/tests/test_integration.py index 0083c590..831a41f9 100644 --- a/pooch/tests/test_integration.py +++ b/pooch/tests/test_integration.py @@ -41,7 +41,7 @@ def test_create_and_fetch(): assert log_file.getvalue().split()[0] == "Downloading" check_tiny_data(fname) # Now modify the file to trigger an update on the next fetch - with open(fname, "w") as fin: + with open(fname, "w", encoding="utf-8") as fin: fin.write("The data is now different") with capture_log() as log_file: fname = pup.fetch(target) diff --git a/pooch/tests/test_utils.py b/pooch/tests/test_utils.py index b364fc97..71401297 100644 --- a/pooch/tests/test_utils.py +++ b/pooch/tests/test_utils.py @@ -167,9 +167,9 @@ def test_temporary_file(): "Make sure the file is writable and cleaned up in the end" with temporary_file() as tmp: assert Path(tmp).exists() - with open(tmp, "w") as outfile: + with open(tmp, "w", encoding="utf-8") as outfile: outfile.write("Meh") - with open(tmp) as infile: + with open(tmp, encoding="utf-8") as infile: assert infile.read().strip() == "Meh" assert not Path(tmp).exists() @@ -180,9 +180,9 @@ def test_temporary_file_path(): with temporary_file(path) as tmp: assert Path(tmp).exists() assert path in tmp - with open(tmp, "w") as outfile: + with open(tmp, "w", encoding="utf-8") as outfile: outfile.write("Meh") - with open(tmp) as infile: + with open(tmp, encoding="utf-8") as infile: assert infile.read().strip() == "Meh" assert not Path(tmp).exists() diff --git a/pooch/tests/utils.py b/pooch/tests/utils.py index 5a6ce699..6dc1332d 100644 --- a/pooch/tests/utils.py +++ b/pooch/tests/utils.py @@ -24,7 +24,7 @@ def check_tiny_data(fname): Load the tiny-data.txt file and check that the contents are correct. """ assert os.path.exists(fname) - with open(fname) as tinydata: + with open(fname, encoding="utf-8") as tinydata: content = tinydata.read() true_content = "\n".join( ["# A tiny data file for test purposes only", "1 2 3 4 5 6"] @@ -37,7 +37,7 @@ def check_large_data(fname): Load the large-data.txt file and check that the contents are correct. """ assert os.path.exists(fname) - with open(fname) as data: + with open(fname, encoding="utf-8") as data: content = data.read() true_content = ["# A larer data file for test purposes only"] true_content.extend(["1 2 3 4 5 6"] * 6002) From 16ed3b89c7340757cc238d4239df9f42d8106cb7 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:26:08 -0400 Subject: [PATCH 05/11] Disable targetted consider-using-with warnings --- pooch/tests/test_hashes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pooch/tests/test_hashes.py b/pooch/tests/test_hashes.py index 7bac299d..d9991b8e 100644 --- a/pooch/tests/test_hashes.py +++ b/pooch/tests/test_hashes.py @@ -66,7 +66,7 @@ def data_dir_mirror(tmp_path): def test_make_registry(data_dir_mirror): "Check that the registry builder creates the right file names and hashes" - outfile = NamedTemporaryFile(delete=False) + outfile = NamedTemporaryFile(delete=False) # pylint: disable=consider-using-with # Need to close the file before writing to it. outfile.close() try: @@ -87,7 +87,7 @@ def test_make_registry(data_dir_mirror): def test_make_registry_recursive(data_dir_mirror): "Check that the registry builder works in recursive mode" - outfile = NamedTemporaryFile(delete=False) + outfile = NamedTemporaryFile(delete=False) # pylint: disable=consider-using-with # Need to close the file before writing to it. outfile.close() try: From a27407137e3eb8524aeb2d3cb54c669f01af1536 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:26:22 -0400 Subject: [PATCH 06/11] Use more fstrings --- pooch/tests/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pooch/tests/utils.py b/pooch/tests/utils.py index 6dc1332d..a248ead7 100644 --- a/pooch/tests/utils.py +++ b/pooch/tests/utils.py @@ -58,9 +58,8 @@ def pooch_test_url(): The versioned URL for pooch's test data. """ - url = "https://github.com/fatiando/pooch/raw/{version}/pooch/tests/data/".format( - version=check_version(full_version, fallback="main") - ) + version = check_version(full_version, fallback="main") + url = f"https://github.com/fatiando/pooch/raw/{version}/pooch/tests/data/" return url From 07f0edecfc9832f9bdfdbf689ae727ab147d4c1b Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:26:31 -0400 Subject: [PATCH 07/11] use maxsplit --- pooch/tests/test_hashes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pooch/tests/test_hashes.py b/pooch/tests/test_hashes.py index d9991b8e..cf6897e2 100644 --- a/pooch/tests/test_hashes.py +++ b/pooch/tests/test_hashes.py @@ -17,7 +17,7 @@ try: import xxhash - XXHASH_MAJOR_VERSION = int(xxhash.VERSION.split(".")[0]) + XXHASH_MAJOR_VERSION = int(xxhash.VERSION.split(".", maxsplit=1)[0]) except ImportError: xxhash = None XXHASH_MAJOR_VERSION = 0 From 40603bc8e5c571a355f35f228a8384602a5b2eb2 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sun, 16 Oct 2022 12:28:04 -0400 Subject: [PATCH 08/11] Make sure pylint knows when to expect failures --- pooch/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pooch/utils.py b/pooch/utils.py index 13670f12..fb88dab7 100644 --- a/pooch/utils.py +++ b/pooch/utils.py @@ -249,15 +249,18 @@ def make_local_storage(path, env=None): """ path = str(path) # Check that the data directory is writable + if not os.path.exists(path): + action = "create" + else: + action = "write to" + try: - if not os.path.exists(path): - action = "create" + if action == "create": # When running in parallel, it's possible that multiple jobs will # try to create the path at the same time. Use exist_ok to avoid # raising an error. os.makedirs(path, exist_ok=True) else: - action = "write to" with tempfile.NamedTemporaryFile(dir=path): pass except PermissionError as error: From 3bfd27ea2cfb86aa887665ea47d42c89a3ec906b Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sat, 22 Oct 2022 10:16:03 -0400 Subject: [PATCH 09/11] update requirements in environment file --- env/requirements-style.txt | 2 +- environment.yml | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/env/requirements-style.txt b/env/requirements-style.txt index 21ef9c09..cb76f5ed 100644 --- a/env/requirements-style.txt +++ b/env/requirements-style.txt @@ -1,5 +1,5 @@ # Style checks black flake8 -pylint==2.4.* +pylint>=2.4 pathspec diff --git a/environment.yml b/environment.yml index 29dfafb9..af398d2b 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,6 @@ name: pooch channels: - conda-forge - - defaults dependencies: - python==3.11 - pip @@ -17,12 +16,11 @@ dependencies: - pytest-localftpserver - coverage # Documentation - - sphinx==4.4.* - - sphinx-book-theme==0.2.* - - sphinx-panels==0.6.* + - sphinx ==4.4.* + - sphinx-book-theme ==0.2.* + - sphinx-panels ==0.6.* # Style - pathspec - - black>=20.8b1 + - black >=20.8b1 - flake8 - - pip: - - pylint==2.4.* + - pylint >=2.4 From 770504650514ca4ba001c442b32dd7de5d7d0f6d Mon Sep 17 00:00:00 2001 From: Leonardo Uieda Date: Fri, 20 Oct 2023 13:16:49 -0300 Subject: [PATCH 10/11] Ignore new edge case introduced in another PR --- pooch/downloaders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pooch/downloaders.py b/pooch/downloaders.py index febb8001..5f6c796b 100644 --- a/pooch/downloaders.py +++ b/pooch/downloaders.py @@ -165,7 +165,9 @@ def __init__(self, progressbar=False, chunk_size=1024, **kwargs): if self.progressbar is True and tqdm is None: raise ValueError("Missing package 'tqdm' required for progress bars.") - def __call__(self, url, output_file, pooch, check_only=False): + def __call__( + self, url, output_file, pooch, check_only=False + ): # pylint: disable=R0914 """ Download the given URL over HTTP to the given output file. From 5b487f6cac62dc352179fb1fab12e223bce2e51e Mon Sep 17 00:00:00 2001 From: Leonardo Uieda Date: Sat, 17 Feb 2024 20:16:39 -0300 Subject: [PATCH 11/11] Use {} instead of dict --- pooch/downloaders.py | 4 +-- pooch/tests/test_downloaders.py | 52 ++++++++++++++++----------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pooch/downloaders.py b/pooch/downloaders.py index 15d7d07e..ccf4cecb 100644 --- a/pooch/downloaders.py +++ b/pooch/downloaders.py @@ -826,9 +826,9 @@ def api_version(self): str """ if self._api_version is None: - if all(["key" in file for file in self.api_response["files"]]): + if all("key" in file for file in self.api_response["files"]): self._api_version = "legacy" - elif all(["filename" in file for file in self.api_response["files"]]): + elif all("filename" in file for file in self.api_response["files"]): self._api_version = "new" else: raise ValueError( diff --git a/pooch/tests/test_downloaders.py b/pooch/tests/test_downloaders.py index d1777293..09cfeabd 100644 --- a/pooch/tests/test_downloaders.py +++ b/pooch/tests/test_downloaders.py @@ -401,13 +401,13 @@ class TestZenodoAPISupport: ) file_checksum = "2942bfabb3d05332b66eb128e0842cff" - legacy_api_response = dict( - created="2021-20-19T08:00:00.000000+00:00", - modified="2021-20-19T08:00:00.000000+00:00", - id=article_id, - doi=doi, - doi_url=doi_url, - files=[ + legacy_api_response = { + "created": "2021-20-19T08:00:00.000000+00:00", + "modified": "2021-20-19T08:00:00.000000+00:00", + "id": article_id, + "doi": doi, + "doi_url": doi_url, + "files": [ { "id": "513d7033-93a2-4eeb-821c-2fb0bbab0012", "key": file_name, @@ -417,15 +417,15 @@ class TestZenodoAPISupport: }, } ], - ) - - new_api_response = dict( - created="2021-20-19T08:00:00.000000+00:00", - modified="2021-20-19T08:00:00.000000+00:00", - id=article_id, - doi=doi, - doi_url=doi_url, - files=[ + } + + new_api_response = { + "created": "2021-20-19T08:00:00.000000+00:00", + "modified": "2021-20-19T08:00:00.000000+00:00", + "id": article_id, + "doi": doi, + "doi_url": doi_url, + "files": [ { "id": "513d7033-93a2-4eeb-821c-2fb0bbab0012", "filename": file_name, @@ -435,15 +435,15 @@ class TestZenodoAPISupport: }, } ], - ) - - invalid_api_response = dict( - created="2021-20-19T08:00:00.000000+00:00", - modified="2021-20-19T08:00:00.000000+00:00", - id=article_id, - doi=doi, - doi_url=doi_url, - files=[ + } + + invalid_api_response = { + "created": "2021-20-19T08:00:00.000000+00:00", + "modified": "2021-20-19T08:00:00.000000+00:00", + "id": article_id, + "doi": doi, + "doi_url": doi_url, + "files": [ { "id": "513d7033-93a2-4eeb-821c-2fb0bbab0012", "filename": file_name, @@ -461,7 +461,7 @@ class TestZenodoAPISupport: }, }, ], - ) + } @pytest.mark.parametrize( "api_version, api_response",