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

bump py3.8 and Ruff cleaning #234

Merged
merged 1 commit into from
Mar 6, 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
2 changes: 1 addition & 1 deletion .github/workflows/check-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-use-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 1 addition & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------------
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"]]
Expand Down
33 changes: 13 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/lightning_utilities/core/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion src/lightning_utilities/docs/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions src/lightning_utilities/docs/formatting.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 2 additions & 4 deletions src/lightning_utilities/docs/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/docs/test_retriever.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Loading