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

Autoformat Pooch with ruff #454

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#
# This code is part of the Fatiando a Terra project (https://www.fatiando.org)
#
import os
import datetime
import os

import pooch


# Project information
# -----------------------------------------------------------------------------
project = "Pooch"
Expand Down
16 changes: 7 additions & 9 deletions pooch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
# pylint: disable=missing-docstring,import-outside-toplevel,import-self
#
# Import functions/classes to make the API
# This file is generated automatically by setuptools_scm
from . import _version
Comment on lines +10 to +11
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a space here to specify which is the file generated by setuptools_scm

from .core import Pooch, create, retrieve
from .utils import os_cache, check_version, get_logger
from .hashes import file_hash, make_registry
from .downloaders import (
HTTPDownloader,
DOIDownloader,
FTPDownloader,
HTTPDownloader,
SFTPDownloader,
DOIDownloader,
)
from .processors import Unzip, Untar, Decompress

# This file is generated automatically by setuptools_scm
from . import _version

from .hashes import file_hash, make_registry
from .processors import Decompress, Untar, Unzip
from .utils import check_version, get_logger, os_cache

# Add a "v" to the version number
__version__ = f"v{_version.version}"
Expand Down
16 changes: 8 additions & 8 deletions pooch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
"""
The main Pooch class and a factory function for it.
"""
import os
import time

import contextlib
from pathlib import Path
import os
import shlex
import shutil
import time
from pathlib import Path


from .hashes import hash_matches, file_hash
from .downloaders import DOIDownloader, choose_downloader, doi_to_repository
from .hashes import file_hash, hash_matches
from .utils import (
cache_location,
check_version,
get_logger,
make_local_storage,
cache_location,
temporary_file,
os_cache,
temporary_file,
unique_file_name,
)
from .downloaders import DOIDownloader, choose_downloader, doi_to_repository


def retrieve(
Expand Down
8 changes: 3 additions & 5 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""
The classes that actually handle the downloads.
"""

import ftplib
import os
import sys
import ftplib

import warnings

from .utils import parse_url
Expand Down Expand Up @@ -171,9 +171,7 @@ 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
): # pylint: disable=R0914
def __call__(self, url, output_file, pooch, check_only=False): # pylint: disable=R0914
"""
Download the given URL over HTTP to the given output file.

Expand Down
3 changes: 2 additions & 1 deletion pooch/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"""
Calculating and checking file hashes.
"""
import hashlib

import functools
import hashlib
from pathlib import Path

# From the docs: https://docs.python.org/3/library/hashlib.html#hashlib.new
Expand Down
5 changes: 3 additions & 2 deletions pooch/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"""
Post-processing hooks
"""

import abc
import os
import bz2
import gzip
import lzma
import os
import shutil
from zipfile import ZipFile
from tarfile import TarFile
from zipfile import ZipFile

from .utils import get_logger

Expand Down
25 changes: 12 additions & 13 deletions pooch/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@
"""
Test the core class and factory function.
"""

import hashlib
import os
from pathlib import Path
from tempfile import TemporaryDirectory

import pytest

from ..core import create, Pooch, retrieve, download_action, stream_download
from ..utils import get_logger, temporary_file, os_cache
from ..hashes import file_hash, hash_matches

# Import the core module so that we can monkeypatch some functions
from .. import core
from ..downloaders import HTTPDownloader, FTPDownloader

from ..core import Pooch, create, download_action, retrieve, stream_download
from ..downloaders import FTPDownloader, HTTPDownloader
from ..hashes import file_hash, hash_matches
from ..utils import get_logger, os_cache, temporary_file
from .utils import (
pooch_test_url,
capture_log,
check_large_data,
check_tiny_data,
data_over_ftp,
mirror_directory,
pooch_test_dataverse_url,
pooch_test_figshare_url,
pooch_test_registry,
pooch_test_url,
pooch_test_zenodo_url,
pooch_test_zenodo_with_slash_url,
pooch_test_dataverse_url,
pooch_test_registry,
check_tiny_data,
check_large_data,
capture_log,
mirror_directory,
)

DATA_DIR = str(Path(__file__).parent / "data")
Expand Down
16 changes: 8 additions & 8 deletions pooch/tests/test_downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
Test the downloader classes and functions separately from the Pooch core.
"""

import os
import sys
from tempfile import TemporaryDirectory
Expand All @@ -25,29 +26,28 @@

from .. import Pooch
from ..downloaders import (
HTTPDownloader,
FTPDownloader,
SFTPDownloader,
DataverseRepository,
DOIDownloader,
choose_downloader,
FigshareRepository,
FTPDownloader,
HTTPDownloader,
SFTPDownloader,
ZenodoRepository,
DataverseRepository,
choose_downloader,
doi_to_url,
)
from ..processors import Unzip
from .utils import (
pooch_test_url,
check_large_data,
check_tiny_data,
data_over_ftp,
pooch_test_dataverse_url,
pooch_test_figshare_url,
pooch_test_url,
pooch_test_zenodo_url,
pooch_test_zenodo_with_slash_url,
pooch_test_dataverse_url,
)


BASEURL = pooch_test_url()
FIGSHAREURL = pooch_test_figshare_url()
ZENODOURL = pooch_test_zenodo_url()
Expand Down
3 changes: 2 additions & 1 deletion pooch/tests/test_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
Test the hash calculation and checking functions.
"""

import os
from pathlib import Path
from tempfile import NamedTemporaryFile
Expand All @@ -24,9 +25,9 @@

from ..core import Pooch
from ..hashes import (
make_registry,
file_hash,
hash_matches,
make_registry,
)
from .utils import check_tiny_data, mirror_directory

Expand Down
5 changes: 3 additions & 2 deletions pooch/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"""
Test the entire process of creating a Pooch and using it.
"""

import os
import shutil
from pathlib import Path

import pytest

from .. import create, os_cache
from .. import __version__ as full_version
from .utils import check_tiny_data, capture_log
from .. import create, os_cache
from .utils import capture_log, check_tiny_data


@pytest.mark.network
Expand Down
9 changes: 4 additions & 5 deletions pooch/tests/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
"""
Test the processor hooks
"""

import warnings
from pathlib import Path
from tempfile import TemporaryDirectory
import warnings

import pytest

from .. import Pooch
from ..processors import Unzip, Untar, Decompress

from .utils import pooch_test_url, pooch_test_registry, check_tiny_data, capture_log

from ..processors import Decompress, Untar, Unzip
from .utils import capture_log, check_tiny_data, pooch_test_registry, pooch_test_url

REGISTRY = pooch_test_registry()
BASEURL = pooch_test_url()
Expand Down
7 changes: 4 additions & 3 deletions pooch/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
"""
Test the utility functions.
"""

import os
import shutil
import tempfile
import time
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from pathlib import Path
import tempfile
from tempfile import TemporaryDirectory
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

import pytest

from ..utils import (
parse_url,
make_local_storage,
parse_url,
temporary_file,
unique_file_name,
)
Expand Down
1 change: 1 addition & 0 deletions pooch/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
Test the version.
"""

from packaging.version import Version

import pooch
Expand Down
5 changes: 3 additions & 2 deletions pooch/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"""
Utilities for testing code.
"""
import os

import io
import logging
import os
import shutil
import stat
from pathlib import Path
from contextlib import contextmanager
from pathlib import Path

from .. import __version__ as full_version
from ..utils import check_version, get_logger
Expand Down
8 changes: 4 additions & 4 deletions pooch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"""
Misc utilities
"""

import hashlib
import logging
import os
import tempfile
import hashlib
import warnings
from contextlib import contextmanager
from pathlib import Path
from urllib.parse import urlsplit
from contextlib import contextmanager
import warnings

import platformdirs
from packaging.version import Version


LOGGER = logging.Logger("pooch")
LOGGER.addHandler(logging.StreamHandler())

Expand Down
Loading