diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml deleted file mode 100644 index 709e8d0..0000000 --- a/.github/workflows/lint.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: lint - -on: - push: - branches: - - main - pull_request: - -jobs: - ruff: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: chartboost/ruff-action@v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d6d4fd..1d020b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,25 +6,13 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: check-toml - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.10.0 - hooks: - - id: black - # It is recommended to specify the latest version of Python - # supported by your project here, or alternatively use - # pre-commit's default_language_version, see - # https://pre-commit.com/#top_level-default_language_version - language_version: python3.11 - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - name: isort (python) - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.7.4 + rev: v0.9.4 hooks: - id: ruff + args: [--fix] + - id: ruff-format - repo: https://github.com/numpy/numpydoc rev: "v1.8.0" hooks: diff --git a/pyproject.toml b/pyproject.toml index a855a60..0937d46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,6 +107,7 @@ target-version = ["py311"] [tool.isort] profile = "black" line_length = 110 +known_first_party = ["lsst"] [tool.lsst_versions] write_to = "python/lsst/resources/version.py" @@ -167,17 +168,26 @@ select = [ "D", # pydocstyle "UP", # pyupgrade "C4", + "I", # isort + "RUF022", # __all__ sorting ] extend-select = [ "RUF100", # Warn about unused noqa ] +[tool.ruff.lint.isort] +known-first-party = ["lsst"] + [tool.ruff.lint.pycodestyle] max-doc-length = 79 [tool.ruff.lint.pydocstyle] convention = "numpy" +[tool.ruff.format] +docstring-code-format = true +docstring-code-line-length = 79 + [tool.numpydoc_validation] checks = [ "all", # All except the rules listed below. diff --git a/python/lsst/resources/_resourceHandles/_httpResourceHandle.py b/python/lsst/resources/_resourceHandles/_httpResourceHandle.py index e3396ae..1fe1dea 100644 --- a/python/lsst/resources/_resourceHandles/_httpResourceHandle.py +++ b/python/lsst/resources/_resourceHandles/_httpResourceHandle.py @@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, AnyStr, NamedTuple import requests + from lsst.utils.timer import time_this from ._baseResourceHandle import BaseResourceHandle, CloseStatus diff --git a/python/lsst/resources/_resourceHandles/_s3ResourceHandle.py b/python/lsst/resources/_resourceHandles/_s3ResourceHandle.py index 086bd6e..c1b7505 100644 --- a/python/lsst/resources/_resourceHandles/_s3ResourceHandle.py +++ b/python/lsst/resources/_resourceHandles/_s3ResourceHandle.py @@ -20,6 +20,7 @@ from typing import TYPE_CHECKING from botocore.exceptions import ClientError + from lsst.utils.introspection import find_outside_stacklevel from lsst.utils.timer import time_this diff --git a/python/lsst/resources/http.py b/python/lsst/resources/http.py index 73afca0..b3bbaf0 100644 --- a/python/lsst/resources/http.py +++ b/python/lsst/resources/http.py @@ -51,11 +51,12 @@ import requests from astropy import units as u -from lsst.utils.timer import time_this from requests.adapters import HTTPAdapter from requests.auth import AuthBase from urllib3.util.retry import Retry +from lsst.utils.timer import time_this + from ._resourceHandles import ResourceHandleProtocol from ._resourceHandles._httpResourceHandle import HttpReadResourceHandle, parse_content_range_header from ._resourcePath import ResourcePath diff --git a/python/lsst/resources/s3.py b/python/lsst/resources/s3.py index bdfb708..7b3b0e8 100644 --- a/python/lsst/resources/s3.py +++ b/python/lsst/resources/s3.py @@ -25,6 +25,7 @@ from typing import IO, TYPE_CHECKING, cast from botocore.exceptions import ClientError + from lsst.utils.timer import time_this from ._resourceHandles._baseResourceHandle import ResourceHandleProtocol @@ -258,7 +259,7 @@ def remove(self) -> None: def read(self, size: int = -1) -> bytes: args = {} if size > 0: - args["Range"] = f"bytes=0-{size-1}" + args["Range"] = f"bytes=0-{size - 1}" try: response = self.client.get_object(Bucket=self._bucket, Key=self.relativeToPathRoot, **args) except (self.client.exceptions.NoSuchKey, self.client.exceptions.NoSuchBucket) as err: diff --git a/python/lsst/resources/s3utils.py b/python/lsst/resources/s3utils.py index 24d6e33..6bacdf0 100644 --- a/python/lsst/resources/s3utils.py +++ b/python/lsst/resources/s3utils.py @@ -12,16 +12,16 @@ from __future__ import annotations __all__ = ( - "getS3Client", - "s3CheckFileExists", - "bucketExists", - "backoff", + "_TooManyRequestsError", "all_retryable_errors", + "backoff", + "bucketExists", + "clean_test_environment_for_s3", + "getS3Client", "max_retry_time", - "retryable_io_errors", "retryable_client_errors", - "_TooManyRequestsError", - "clean_test_environment_for_s3", + "retryable_io_errors", + "s3CheckFileExists", ) import functools diff --git a/python/lsst/resources/tests.py b/python/lsst/resources/tests.py index 7ac057d..2c29280 100644 --- a/python/lsst/resources/tests.py +++ b/python/lsst/resources/tests.py @@ -10,7 +10,7 @@ # license that can be found in the LICENSE file. from __future__ import annotations -__all__ = ["GenericTestCase", "GenericReadWriteTestCase"] +__all__ = ["GenericReadWriteTestCase", "GenericTestCase"] import logging import os diff --git a/python/lsst/resources/utils.py b/python/lsst/resources/utils.py index ef47c70..9491b69 100644 --- a/python/lsst/resources/utils.py +++ b/python/lsst/resources/utils.py @@ -11,7 +11,7 @@ from __future__ import annotations -__all__ = ("os2posix", "posix2os", "NoTransaction", "TransactionProtocol") +__all__ = ("NoTransaction", "TransactionProtocol", "os2posix", "posix2os") import contextlib import logging diff --git a/tests/test_http.py b/tests/test_http.py index f33730b..5354377 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -31,9 +31,10 @@ except ImportError: WsgiDAVApp = None -import lsst.resources import requests import responses + +import lsst.resources from lsst.resources import ResourcePath from lsst.resources._resourceHandles._httpResourceHandle import ( HttpReadResourceHandle, diff --git a/tests/test_s3utils.py b/tests/test_s3utils.py index 51814cf..c86fe64 100644 --- a/tests/test_s3utils.py +++ b/tests/test_s3utils.py @@ -34,6 +34,8 @@ except ImportError: boto3 = None +from urllib3.exceptions import LocationParseError + from lsst.resources import ResourcePath from lsst.resources.location import Location from lsst.resources.s3utils import ( @@ -43,7 +45,6 @@ getS3Client, s3CheckFileExists, ) -from urllib3.exceptions import LocationParseError @unittest.skipIf(not boto3, "Warning: boto3 AWS SDK not found!")