From 00ff7e33c4c44adb9d75f92a1590cb3e3dc45729 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 13:17:39 -0400 Subject: [PATCH 1/4] Let Ruff scan doc/source/conf.py And other .py files in doc/, if there ever were any. This may have been turned off before either for performance or out of a concern than some flake8 plugin would catch something in the docs themselves, but that's no longer an issue. The doc/build directory, which should still not be scanned, is already excluded in other ways (and does not need to be excluded for pre-commit to improve performance, since it is untracked). --- .pre-commit-config.yaml | 2 +- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60bbe3518..f269678e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: exclude: ^git/ext/ - id: ruff args: ["--fix"] - exclude: ^doc|^git/ext/ + exclude: ^git/ext/ - repo: https://github.com/shellcheck-py/shellcheck-py rev: v0.9.0.5 diff --git a/pyproject.toml b/pyproject.toml index eb57cc7b7..e8f3d720e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,6 @@ line-length = 120 # Exclude a variety of commonly ignored directories. exclude = [ "git/ext/", - "doc", "build", "dist", ] From 4814775bfee418d7e0cc9ffb0ac30a4e44a48d75 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 13:32:28 -0400 Subject: [PATCH 2/4] Comment all Ruff rule codes; tweak formatting This adds comments to all specific Ruff rules suppressed in pyproject.toml (most of which are global but one is for the tests only). Some already had such comments but now all do. This also harmonizes the toml formatting style with the rest of pyproject.toml. --- pyproject.toml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e8f3d720e..57ae01058 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,24 +54,28 @@ exclude = [ # Enable Pyflakes `E` and `F` codes by default. lint.select = [ "E", - "W", # see: https://pypi.org/project/pycodestyle - "F", # see: https://pypi.org/project/pyflakes -# "I", #see: https://pypi.org/project/isort/ -# "S", # see: https://pypi.org/project/flake8-bandit -# "UP", # see: https://docs.astral.sh/ruff/rules/#pyupgrade-up + "W", # See: https://pypi.org/project/pycodestyle + "F", # See: https://pypi.org/project/pyflakes + # "I", # See: https://pypi.org/project/isort/ + # "S", # See: https://pypi.org/project/flake8-bandit + # "UP", # See: https://docs.astral.sh/ruff/rules/#pyupgrade-up ] 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 - "TCH004", # see: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/ + # "A", # See: https://pypi.org/project/flake8-builtins + "B", # See: https://pypi.org/project/flake8-bugbear + "C4", # See: https://pypi.org/project/flake8-comprehensions + "TCH004", # See: https://docs.astral.sh/ruff/rules/runtime-import-in-type-checking-block/ ] lint.ignore = [ - "E203", - "E731", # Do not assign a `lambda` expression, use a `def` + "E203", # Whitespace before ':' + "E731", # Do not assign a `lambda` expression, use a `def` ] lint.ignore-init-module-imports = true -lint.unfixable = ["F401"] +lint.unfixable = [ + "F401", # Module imported but unused +] [tool.ruff.lint.per-file-ignores] -"test/**" = ["B018"] +"test/**" = [ + "B018", # useless-expression +] From a8a73ff739785a01a528b2a274c8252456a1ebc2 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 13:44:57 -0400 Subject: [PATCH 3/4] Update requirements-dev.txt (as long as we have it) Although it seems likely that the requirements-dev.txt file will be removed when the project definition is made declarative (discussed in #1716 comments), if not before, for now it exists and might be in use, so this updates it with tools that are currently used but not listed in any extras or other requirements files: - ruff: This has replaced flake8 and its plugins (#1862) as well as black (#1865). Currently there is no separate extra for tooling that is not part of unit testing, with some such tools listed in test-requirements.txt. The `ruff` package belongs here rather than there for now because it should not be installed just to run unit tests, since Ruff has to be built from source on some rarer platforms like Cygwin, which would take a long time and/or fail. - shellcheck: The PyPI package for this is a convenience for installing it in projects that are already using pip (shellcheck is neither written in Python nor a tool to scan Python code). It installs pre-built binaries, which are not available for all platforms. These packages remain listed: - pytest-icdiff: This seems not to have been promoted to be in the test-requirements.txt file and the `test` extra because it does not work as well for diffs from tests that the pytest runner runs but that are written for the unittest framework. - pytest-profiling [commented out]: I am not sure what the status of this is, perhaps it has just not been experimented with enough to know if it would be useful for profiling in GitPython. This requirements-dev.txt file has a few limitations that suggest it should be removed altogether sometime soon: - It is not updated regularly. - It is not always clear why something is there. Originally I believe it was for tools where the desire to use the tool was established but the tool did not yet work or worked but performed checks for which code had to be fixed. That purpose has drifted. - It uses a different naming convention from the test-requirements.txt file in active use. - It cannot be readily used to create an extra in the current project definition in setup.py because the simple parsing done there will not recognize the `-r` lines and will not skip the comments, and neither enhancement should be done in setup.py since that would move things farther away from a declarative project definition. - It will naturally go away when the project definition is made declarative, since it will then be feasible to define as many extras as desired without proliferating separate requirements files (while still allowing their contents to be statically available to tools). Since it may go away soon and is not regularly updated, I have kept the explanations for why particular packages are there out of it. But as long as it exists it may as well list the tools that really are being used yet are not explicitly listed as dependencies. --- requirements-dev.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 69a79d13d..f626644af 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,8 @@ -r requirements.txt -r test-requirements.txt -# libraries for additional local testing/linting - to be added to test-requirements.txt when all pass - +# For additional local testing/linting - to be added elsewhere eventually. +ruff +shellcheck pytest-icdiff # pytest-profiling From ff1ebf8fe05f2b5bace15dc7edbc6bdc4aea2222 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Mar 2024 14:11:16 -0400 Subject: [PATCH 4/4] Bump pre-commit hook versions The changes, per hook repository, are: - ruff-pre-commit: Uses the newest stable version of Ruff. See: * https://github.com/astral-sh/ruff-pre-commit/releases/tag/v0.3.2 - shellcheck-py: Makes ShellCheck installable on ARM64 Windows machines. See: * https://github.com/shellcheck-py/shellcheck-py/compare/v0.9.0.5...v0.9.0.6 * https://github.com/shellcheck-py/shellcheck-py/commit/e39ba22d34cf877af3e6529a253a6cfd3e9f8ea7 - pre-commit-hooks: Offers no relevant changes for the few hooks currently being used from that repository, but I went ahead and included this while bumping the others. This may be a small benefit if more hooks are added from it sometime soon and because we don't currently have a mechanism for keeping track of updates that are skipped as unneeded. --- .pre-commit-config.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f269678e4..585b4f04d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,6 @@ repos: - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.3.2 hooks: - id: ruff-format exclude: ^git/ext/ @@ -10,14 +9,14 @@ repos: exclude: ^git/ext/ - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.9.0.5 + rev: v0.9.0.6 hooks: - id: shellcheck args: [--color] exclude: ^test/fixtures/polyglot$|^git/ext/ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-toml - id: check-yaml