From 97b06b59cf10ddb6a1378e12a3d79d078065afdd Mon Sep 17 00:00:00 2001 From: Jirka Date: Wed, 6 Mar 2024 10:29:08 +0100 Subject: [PATCH] bump `py3.8` and Ruff cleaning --- .github/workflows/check-package.yml | 2 +- .github/workflows/ci-testing.yml | 2 +- .github/workflows/ci-use-checks.yaml | 2 +- .pre-commit-config.yaml | 20 +------------ docs/source/conf.py | 8 +++--- pyproject.toml | 33 +++++++++------------- setup.py | 3 +- src/lightning_utilities/core/imports.py | 4 +-- src/lightning_utilities/docs/__init__.py | 4 ++- src/lightning_utilities/docs/formatting.py | 2 -- src/lightning_utilities/docs/retriever.py | 6 ++-- tests/unittests/docs/test_retriever.py | 4 +-- 12 files changed, 31 insertions(+), 59 deletions(-) diff --git a/.github/workflows/check-package.yml b/.github/workflows/check-package.yml index 095b10cc..e978b0da 100644 --- a/.github/workflows/check-package.yml +++ b/.github/workflows/check-package.yml @@ -47,7 +47,7 @@ on: default: | { "os": ["ubuntu-20.04", "macos-11", "windows-2022"], - "python-version": ["3.7", "3.9"] + "python-version": ["3.8", "3.9"] } defaults: diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml index b35658b6..84c19c27 100644 --- a/.github/workflows/ci-testing.yml +++ b/.github/workflows/ci-testing.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-22.04", "macos-12", "windows-2022"] - python-version: ["3.7", "3.10", "3.12"] + python-version: ["3.8", "3.10", "3.12"] requires: ["oldest", "latest"] exclude: - { requires: "oldest", python-version: "3.12" } diff --git a/.github/workflows/ci-use-checks.yaml b/.github/workflows/ci-use-checks.yaml index 115115e9..dac10d60 100644 --- a/.github/workflows/ci-use-checks.yaml +++ b/.github/workflows/ci-use-checks.yaml @@ -47,7 +47,7 @@ jobs: testing-matrix: | { "os": ["ubuntu-22.04", "macos-12", "windows-2022"], - "python-version": ["3.7", "3.12"] + "python-version": ["3.8", "3.12"] } check-package-extras: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85056cd8..247c58d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,13 +21,6 @@ repos: - id: check-docstring-first - id: detect-private-key - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: ["--py37-plus"] - name: Upgrade code - - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: @@ -59,19 +52,8 @@ repos: # https://prettier.io/docs/en/options.html#print-width args: ["--print-width=120"] - - repo: https://github.com/asottile/yesqa - rev: v1.5.0 - hooks: - - id: yesqa - additional_dependencies: - - pep8-naming - - flake8-pytest-style - - flake8-bandit - - flake8-builtins - - flake8-bugbear - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.3.0 hooks: - id: ruff-format args: ["--preview"] diff --git a/docs/source/conf.py b/docs/source/conf.py index a51f1a72..91426a99 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -9,10 +9,10 @@ import os import re import sys - -import pt_lightning_sphinx_theme +from typing import Optional import lightning_utilities +import pt_lightning_sphinx_theme from lightning_utilities.docs import fetch_external_assets # -- Path setup -------------------------------------------------------------- @@ -265,7 +265,7 @@ def setup(app): # Ignoring Third-party packages # https://stackoverflow.com/questions/15889621/sphinx-how-to-exclude-imports-in-automodule -def _package_list_from_file(file): +def _package_list_from_file(file: str) -> list[str]: list_pkgs = [] with open(file) as fp: lines = fp.readlines() @@ -293,7 +293,7 @@ def _package_list_from_file(file): # Resolve function # This function is used to populate the (source) links in the API def linkcode_resolve(domain, info): - def find_source(): + def find_source() -> Optional[str]: # try to find the file and line number, based on code from numpy: # https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286 obj = sys.modules[info["module"]] diff --git a/pyproject.toml b/pyproject.toml index 5573c616..868e0ba7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,16 +70,19 @@ disallow_untyped_defs = true ignore_missing_imports = true [tool.ruff] - line-length = 120 - select = [ +line-length = 120 +target-version = "py38" +lint.select = [ "E", "W", # see: https://pypi.org/project/pycodestyle "F", # see: https://pypi.org/project/pyflakes "I", #see: https://pypi.org/project/isort/ "D", # see: https://pypi.org/project/pydocstyle "N", # see: https://pypi.org/project/pep8-naming "S", # see: https://pypi.org/project/flake8-bandit + "UP", # see: https://docs.astral.sh/ruff/rules/#pyupgrade-up + "RUF100", # see: https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf ] -extend-select = [ +lint.extend-select = [ "A", # see: https://pypi.org/project/flake8-builtins "B", # see: https://pypi.org/project/flake8-bugbear "C4", # see: https://pypi.org/project/flake8-comprehensions @@ -97,23 +100,13 @@ extend-select = [ "PIE", # see: https://pypi.org/project/flake8-pie "PLE", # see: https://pypi.org/project/pylint/ ] - ignore = [ +lint.ignore = [ "E731", ] - exclude = [ - ".eggs", - ".git", - ".mypy_cache", - ".ruff_cache", - "__pypackages__", - "_build", - "build", - "dist", - "docs" - ] - ignore-init-module-imports = true +lint.ignore-init-module-imports = true -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] +"docs/source/conf.py" = ["D100", "D103", "A001", "ANN001", "ANN201"] "setup.py" = ["ANN202", "D100", "SIM115"] "__about__.py" = ["D100"] "__init__.py" = ["D100"] @@ -145,9 +138,9 @@ extend-select = [ "B028", # No explicit `stacklevel` keyword argument found ] -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] # Use Google-style docstrings. convention = "google" - [tool.ruff.mccabe] - max-complexity = 10 +[tool.ruff.lint.mccabe] +max-complexity = 10 diff --git a/setup.py b/setup.py index 3ede80f7..5aaefef1 100755 --- a/setup.py +++ b/setup.py @@ -62,7 +62,7 @@ def _requirement_extras(path_req: str = _PATH_REQUIRE) -> dict: include_package_data=True, zip_safe=False, keywords=["Utilities", "DevOps", "CI/CD"], - python_requires=">=3.7", + python_requires=">=3.8", setup_requires=[], install_requires=requirements, extras_require=_requirement_extras(), @@ -83,7 +83,6 @@ def _requirement_extras(path_req: str = _PATH_REQUIRE) -> dict: # 'License :: OSI Approved :: BSD License', "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/src/lightning_utilities/core/imports.py b/src/lightning_utilities/core/imports.py index 55e74e49..461ea934 100644 --- a/src/lightning_utilities/core/imports.py +++ b/src/lightning_utilities/core/imports.py @@ -26,7 +26,7 @@ import importlib_metadata as metadata # type: ignore -@lru_cache() +@lru_cache def package_available(package_name: str) -> bool: """Check if a package is available in your environment. @@ -42,7 +42,7 @@ def package_available(package_name: str) -> bool: return False -@lru_cache() +@lru_cache def module_available(module_path: str) -> bool: """Check if a module path is available in your environment. diff --git a/src/lightning_utilities/docs/__init__.py b/src/lightning_utilities/docs/__init__.py index 0389f4ad..7b2e41cc 100644 --- a/src/lightning_utilities/docs/__init__.py +++ b/src/lightning_utilities/docs/__init__.py @@ -1 +1,3 @@ -from lightning_utilities.docs.retriever import fetch_external_assets +"""General tools for Docs.""" + +from lightning_utilities.docs.retriever import fetch_external_assets # noqa: F401 diff --git a/src/lightning_utilities/docs/formatting.py b/src/lightning_utilities/docs/formatting.py index 740862a3..3bd2f06d 100644 --- a/src/lightning_utilities/docs/formatting.py +++ b/src/lightning_utilities/docs/formatting.py @@ -1,10 +1,8 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # http://www.apache.org/licenses/LICENSE-2.0 # -import glob import inspect import os -import re import sys from typing import Tuple diff --git a/src/lightning_utilities/docs/retriever.py b/src/lightning_utilities/docs/retriever.py index 7c42575a..99e3b425 100644 --- a/src/lightning_utilities/docs/retriever.py +++ b/src/lightning_utilities/docs/retriever.py @@ -17,7 +17,7 @@ def _download_file(file_url: str, folder: str) -> str: if os.path.isfile(file_path): logging.warning(f'given file "{file_path}" already exists and will be overwritten with {file_url}') # see: https://stackoverflow.com/a/34957875 - rq = requests.get(file_url) + rq = requests.get(file_url, timeout=10) with open(file_path, "wb") as outfile: outfile.write(rq.content) return fname @@ -40,9 +40,7 @@ def _search_all_occurrences(list_files: List[str], pattern: str) -> List[str]: return collected -def _replace_remote_with_local( - file_path: str, docs_folder: str, pairs_url_path: List[Tuple[str, str]], base_depth: int = 2 -) -> None: +def _replace_remote_with_local(file_path: str, docs_folder: str, pairs_url_path: List[Tuple[str, str]]) -> None: """Replace all URL with local files in a given file. Args: diff --git a/tests/unittests/docs/test_retriever.py b/tests/unittests/docs/test_retriever.py index f8cc6919..3c56bbc1 100644 --- a/tests/unittests/docs/test_retriever.py +++ b/tests/unittests/docs/test_retriever.py @@ -1,10 +1,10 @@ import os.path import shutil -from unittests import _PATH_ROOT - from lightning_utilities.docs import fetch_external_assets +from unittests import _PATH_ROOT + def test_retriever_s3(): path_docs = os.path.join(_PATH_ROOT, "docs", "source")