From 6ffc213830ac340138e430495d58df1e7aac6b10 Mon Sep 17 00:00:00 2001 From: Jarrod Millman Date: Tue, 27 Jun 2023 13:44:30 -0700 Subject: [PATCH] Use ruff --- .flake8 | 16 ------------- .pre-commit-config.yaml | 34 +++++++++++---------------- lazy_loader/__init__.py | 2 +- lazy_loader/tests/test_lazy_loader.py | 6 ++--- pyproject.toml | 17 ++++++++++++++ 5 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 4994bd6..0000000 --- a/.flake8 +++ /dev/null @@ -1,16 +0,0 @@ -# See: -# -# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes (E, W) -# https://flake8.pycqa.org/en/latest/user/error-codes.html (F) -# https://github.com/PyCQA/flake8-bugbear -# -# for error codes. And -# -# https://flake8.pycqa.org/en/latest/user/violations.html#selecting-violations-with-flake8 -# -# for error classes selected below. - -[flake8] -max-line-length = 88 -select = C,E,F,W,B,B950 -ignore = E501, W503 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f4227e8..90daee7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: f71fa2c1f9cf5cb705f73dffe4b21f7c61470ba9 # v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -15,27 +15,21 @@ repos: - id: check-json - id: check-toml - id: check-added-large-files - - repo: https://github.com/psf/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - pass_filenames: true - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: https://github.com/asottile/pyupgrade - rev: v3.7.0 - hooks: - - id: pyupgrade - args: [--py37-plus] + - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.7.1 + rev: 50c5478ed9e10bf360335449280cf2a67f4edb7a # v2.7.1 hooks: - id: prettier files: \.(html|md|yml|yaml|toml) args: [--prose-wrap=preserve] + + - repo: https://github.com/psf/black + rev: bf7a16254ec96b084a6caf3d435ec18f0f245cc7 # 23.3.0 + hooks: + - id: black + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 1ac904bbe451ef0b5a437d1d3b331a244c1f272c # v0.0.275 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] diff --git a/lazy_loader/__init__.py b/lazy_loader/__init__.py index ed6f7dd..179a415 100644 --- a/lazy_loader/__init__.py +++ b/lazy_loader/__init__.py @@ -66,7 +66,7 @@ def attach(package_name, submodules=None, submod_attrs=None): attr: mod for mod, attrs in submod_attrs.items() for attr in attrs } - __all__ = list(sorted(submodules | attr_to_modules.keys())) + __all__ = sorted(submodules | attr_to_modules.keys()) def __getattr__(name): if name in submodules: diff --git a/lazy_loader/tests/test_lazy_loader.py b/lazy_loader/tests/test_lazy_loader.py index 1c8dbd3..2c9278b 100644 --- a/lazy_loader/tests/test_lazy_loader.py +++ b/lazy_loader/tests/test_lazy_loader.py @@ -15,14 +15,14 @@ def test_lazy_import_basics(): # poor-mans pytest.raises for testing errors on attribute access try: anything_not_real.pi - assert False # Should not get here + raise AssertionError() # Should not get here except ModuleNotFoundError: pass assert isinstance(anything_not_real, lazy.DelayedImportErrorModule) # see if it changes for second access try: anything_not_real.pi - assert False # Should not get here + raise AssertionError() # Should not get here except ModuleNotFoundError: pass @@ -56,7 +56,7 @@ def test_lazy_import_nonbuiltins(): if isinstance(sp, lazy.DelayedImportErrorModule): try: sp.pi - assert False + raise AssertionError() except ModuleNotFoundError: pass diff --git a/pyproject.toml b/pyproject.toml index c53dced..24e9589 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,3 +32,20 @@ Source = "https://github.com/scientific-python/lazy_loader" [tool.flit.sdist] exclude = ["tests/*"] + +[tool.ruff] +line-length = 88 +target-version = "py37" +select = [ + "C", + "E", + "F", + "W", + "B", + "I", + "UP", +] +ignore = ['B018'] +exclude = [ + "lazy_loader/tests/fake_pkg/__init__.pyi", +]