Skip to content

Commit

Permalink
Fix pre-commit issues (#2967)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtmckee authored Jul 25, 2023
1 parent 15c861a commit aa08625
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/bash

sudo apt-get update
sudo apt-get install -y libaspell-dev

Expand Down
22 changes: 9 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ repos:
hooks:
- id: no-commit-to-branch
args: [--branch, main]
- id: check-toml
- id: check-yaml
args: [--unsafe]
- id: debug-statements
Expand All @@ -48,45 +47,42 @@ repos:
- id: check-case-conflict
- id: check-toml
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.29.0
rev: v1.32.0
hooks:
- id: yamllint
args:
- --no-warnings
- -d
- '{extends: relaxed, rules: {line-length: {max: 90}}}'
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
rev: v0.0.280

This comment has been minimized.

Copy link
@DimitriPapadopoulos

DimitriPapadopoulos Aug 9, 2023

Collaborator

@kurtmckee What does rev: v0.0.280 mean exactly?

The current specification is v0.0.282 but pre-commit CI jobs run v0.0.283. See #3014.

This comment has been minimized.

Copy link
@kurtmckee

kurtmckee Aug 9, 2023

Author Contributor

The rev line indicates what version of ruff will run. pre-commit is running v0.0.282, as specified in the current version of this file.

#3014 is reporting a failure caused by a separate, unnecessary ruff call running from within the Makefile, and the failure is caused by an uncontrolled ruff dev dependency specified in pyproject.toml:

codespell/pyproject.toml

Lines 32 to 41 in f94af94

[project.optional-dependencies]
dev = [
"build",
"chardet",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-dependency",
"Pygments",
"ruff",

The latest version of ruff is installed and then run in CI:

pip install -e ".[dev]" # install the codespell dev packages
- run: codespell --help
- run: codespell --version
- run: make check

This is an ongoing risk that cannot be avoided unless:

  • dev dependencies are pinned (to prevent new versions with unknown bugs)
  • Duplicate checks are removed (to avoid drift between duplicated linting tool versions)

I recommend pinning all dev dependencies to known-working versions, and then removing duplicate checks in the Makefile which are handled automatically by pre-commit.

This comment has been minimized.

Copy link
@DimitriPapadopoulos

DimitriPapadopoulos Aug 9, 2023

Collaborator

Ah, my wrong then. I thought all checks had been moved to pre-commit by #2969. But we need to replace this rule too, which is triggerred by make check:

ruff:
	ruff .

I'll change it to:

ruff:
	pre-commit run --all-files ruff
hooks:
- id: ruff
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.1
rev: v2.2.0
hooks:
- id: autoflake
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.5
hooks:
- id: codespell
args: [--toml, pyproject-codespell.precommit-toml]
additional_dependencies:
- tomli
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.1
rev: v0.13
hooks:
- id: validate-pyproject
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.4.1
hooks:
- id: mypy
args: [--no-warn-unused-ignores, --config-file, pyproject.toml, --disable-error-code,
import]
args: ["--config-file", "pyproject.toml"]
additional_dependencies:
- chardet
- pytest
- pytest-cov
- pytest-dependency
- tomli
- types-chardet
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ pytest:

clean:
rm -rf codespell.1

mypy:
mypy .
2 changes: 1 addition & 1 deletion codespell_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._codespell import _script_main, main
from ._version import __version__
from ._version import __version__ # type: ignore

__all__ = ["_script_main", "main", "__version__"]
12 changes: 6 additions & 6 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from typing import Dict, List, Match, Optional, Pattern, Sequence, Set, Tuple

# autogenerated by setuptools_scm
from ._version import __version__ as VERSION # noqa: N812
from ._version import __version__ as VERSION # type: ignore # noqa: N812

word_regex_def = "[\\w\\-'’`]+"
# While we want to treat characters like ( or " as okay for a starting break,
Expand Down Expand Up @@ -550,18 +550,18 @@ def parse_options(
toml_files.append(options.toml)
tomllib_raise_error = True
if toml_files:
try:
import tomllib # type: ignore[import]
except ModuleNotFoundError:
if sys.version_info >= (3, 11):
import tomllib
else:
try:
import tomli as tomllib
import tomli as tomllib # type: ignore[no-redef]
except ImportError as e:
if tomllib_raise_error:
raise ImportError(
f"tomllib or tomli are required to read pyproject.toml "
f"but could not be imported, got: {e}"
) from None
tomllib = None
tomllib = None # type: ignore[assignment]
if tomllib is not None:
for toml_file in toml_files:
with open(toml_file, "rb") as f:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ expand-star-imports = true
pretty = true
show_error_codes = true
strict = true
warn_unused_ignores = false

[tool.pytest.ini_options]
addopts = "--cov=codespell_lib -rs --cov-report= --tb=short --junit-xml=junit-results.xml"
Expand Down

0 comments on commit aa08625

Please sign in to comment.