Skip to content

Commit

Permalink
Remove self type and update pre-commit hooks (#4400)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 12, 2024
1 parent 444fc80 commit 8b47b64
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 96 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
name: tox

on:
push: # only publishes pushes to the main branch to TestPyPI
branches: # any integration branch but not tag
push:
branches:
- "main"
pull_request:
branches:
- "main"
schedule:
- cron: "0 0 * * *"
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
Expand Down
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ ci:
# format compatible with commitlint
autoupdate_commit_msg: "chore: pre-commit autoupdate"
autoupdate_schedule: monthly
autofix_commit_msg: |
chore: auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_commit_msg: "chore: auto fixes from pre-commit.com hooks"
skip:
# https://github.com/pre-commit-ci/issues/issues/55
- pip-compile
Expand All @@ -33,11 +30,6 @@ repos:
- repo: meta
hooks:
- id: check-useless-excludes
# https://github.com/pappasam/toml-sort/issues/69
# - repo: https://github.com/pappasam/toml-sort
# rev: v0.23.1
# hooks:
# - id: toml-sort-fix
- repo: https://github.com/pre-commit/mirrors-prettier
# keep it before yamllint
rev: v4.0.0-alpha.8
Expand Down Expand Up @@ -70,7 +62,7 @@ repos:
- [email protected]
- [email protected]
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.15.3
rev: v8.16.0
hooks:
- id: cspell
# entry: codespell --relative
Expand Down Expand Up @@ -136,16 +128,24 @@ repos:
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.3"
rev: v0.7.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
args:
- --fix
- --exit-non-zero-on-fix
types_or: [python, pyi]
# - id: ruff-format # must be after ruff
# types_or: [python, pyi]
- repo: https://github.com/psf/black # must be after ruff
rev: 24.10.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
Expand Down
128 changes: 63 additions & 65 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools >= 65.3.0", # required by pyproject+setuptools_scm integration and editable installs
"setuptools_scm[toml] >= 7.0.5", # required for "no-local-version" scheme
"setuptools_scm[toml] >= 7.0.5" # required for "no-local-version" scheme
]
build-backend = "setuptools.build_meta"

[project]
# https://peps.python.org/pep-0621/#readme
requires-python = ">=3.10"
dynamic = ["version", "dependencies", "optional-dependencies"]
name = "ansible-lint"
description = "Checks playbooks for practices and behavior that could potentially be improved"
readme = "README.md"
authors = [{ "name" = "Will Thames", "email" = "[email protected]" }]
maintainers = [{ "name" = "Ansible by Red Hat", "email" = "[email protected]" }]
license = { text = "GPLv3+" }
authors = [{"email" = "[email protected]", "name" = "Will Thames"}]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
Expand All @@ -35,26 +27,34 @@ classifiers = [
"Topic :: System :: Systems Administration",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
"Topic :: Utilities"
]
description = "Checks playbooks for practices and behavior that could potentially be improved"
dynamic = ["version", "dependencies", "optional-dependencies"]
keywords = ["ansible", "lint"]
license = {text = "GPLv3+"}
maintainers = [{"email" = "[email protected]", "name" = "Ansible by Red Hat"}]
name = "ansible-lint"
readme = "README.md"
# https://peps.python.org/pep-0621/#readme
requires-python = ">=3.10"

[project.scripts]
ansible-lint = "ansiblelint.__main__:_run_cli_entrypoint"

[project.urls]
homepage = "https://github.com/ansible/ansible-lint"
changelog = "https://github.com/ansible/ansible-lint/releases"
documentation = "https://ansible.readthedocs.io/projects/lint/"
homepage = "https://github.com/ansible/ansible-lint"
repository = "https://github.com/ansible/ansible-lint"
changelog = "https://github.com/ansible/ansible-lint/releases"

[tool.black]
target-version = ["py310"]

[tool.codespell]
skip = ".tox,.mypy_cache,build,.git,.eggs,pip-wheel-metadata"
# indention is a typo in ruamel.yaml's API
ignore-words-list = "indention"
skip = ".tox,.mypy_cache,build,.git,.eggs,pip-wheel-metadata"

# Keep this default because xml/report do not know to use load it from config file:
# data_file = ".coverage"
Expand All @@ -63,44 +63,29 @@ source = ["src", ".tox/*/site-packages"]

[tool.coverage.report]
exclude_also = ["pragma: no cover", "if TYPE_CHECKING:"]
omit = ["test/*"]
# Increase it just so it would pass on any single-python run
fail_under = 92
skip_covered = true
skip_empty = true
# During development we might remove code (files) with coverage data, and we dont want to fail:
ignore_errors = true
omit = ["test/*"]
show_missing = true
skip_covered = true
skip_empty = true

[tool.coverage.run]
source = ["src"]
concurrency = ["multiprocessing", "thread"]
# Do not use branch until bug is fixes:
# https://github.com/nedbat/coveragepy/issues/605
# branch = true
parallel = true
concurrency = ["multiprocessing", "thread"]

[tool.isort]
profile = "black"
# add_imports = "from __future__ import annotations"
known_first_party = "ansiblelint"
known_third_party = "ansible,pytest,ruamel,setuptools,yaml"
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
source = ["src"]

[tool.mypy]
python_version = "3.10"
strict = true
color_output = true
error_summary = true
disallow_any_generics = true
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_any_generics = true
error_summary = true
# disallow_any_unimported = True
# warn_redundant_casts = True
# warn_return_any = True
Expand All @@ -109,17 +94,19 @@ disallow_any_generics = true
exclude = "(build|dist|test/local-content|site-packages|~/.pyenv|examples/playbooks/collections|plugins/modules)"
# https://github.com/python/mypy/issues/12664
incremental = false
python_version = "3.10"
strict = true

[[tool.mypy.overrides]]
ignore_errors = true
ignore_missing_imports = true
module = [
"ansible.*",
"ansiblelint._version", # generated
"license_expression",
"ruamel.yaml",
"yamllint.*",
"yamllint.*"
]
ignore_missing_imports = true
ignore_errors = true

[tool.pylint.IMPORTS]
preferred-modules = ["py:pathlib", "unittest:pytest"]
Expand All @@ -131,16 +118,14 @@ extension-pkg-allow-list = ["black.parsing"]
bad-names = [
# spell-checker:ignore linenumber
"linenumber", # use lineno instead
"line_number", # use lineno instead
"line_number" # use lineno instead
]
# pylint defaults + f,fh,v,id
good-names = ["i", "j", "k", "Run", "_", "f", "fh", "v", "id", "T"]
# Ignore as being generated:
ignore-paths = "^src/ansiblelint/_version.*$"

[tool.pylint."MESSAGES CONTROL"]
# increase from default is 50 which is too aggressive
max-statements = 60
disable = [
# Disabled on purpose:
"line-too-long", # covered by black
Expand All @@ -152,11 +137,13 @@ disable = [
# https://github.com/PyCQA/pylint/issues/850
"cyclic-import",
# https://github.com/PyCQA/pylint/issues/8453
"preferred-module",
"preferred-module"
]
enable = [
"useless-suppression", # Identify unneeded pylint disable statements
"useless-suppression" # Identify unneeded pylint disable statements
]
# increase from default is 50 which is too aggressive
max-statements = 60

[tool.pylint.REPORTING]
output-format = "colorized"
Expand All @@ -166,9 +153,9 @@ output-format = "colorized"
score = "n"

[tool.pyright]
include = ["src"]
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
pythonVersion = "3.10"
include = ["src"]
# https://github.com/microsoft/pyright/issues/777
"stubPath" = ""

Expand All @@ -194,7 +181,7 @@ filterwarnings = [
# https://github.com/ansible/ansible/issues/81906
"ignore:'importlib.abc.TraversableResources' is deprecated and slated for removal in Python 3.14:DeprecationWarning",
# https://github.com/ansible/ansible/pull/80968
"ignore:Attribute s is deprecated and will be removed in Python 3.14; use value instead:DeprecationWarning",
"ignore:Attribute s is deprecated and will be removed in Python 3.14; use value instead:DeprecationWarning"
]
junit_duration_report = "call"
# Our github annotation parser from .github/workflows/tox.yml requires xunit1 format. Ref:
Expand All @@ -215,31 +202,37 @@ norecursedirs = [
"collections",
"dist",
"docs",
"src/ansible_lint.egg-info",
"src/ansible_lint.egg-info"
]
python_files = [
"test_*.py",
# Ref: https://docs.pytest.org/en/latest/reference.html#confval-python_files
# Needed to discover legacy nose test modules:
"Test*.py",
# Needed to discover embedded Rule tests
"rules/*.py",
"rules/*.py"
]
# Using --pyargs instead of testpath as we embed some tests
# See: https://github.com/pytest-dev/pytest/issues/6451#issuecomment-687043537
# testpaths =
xfail_strict = true

[tool.ruff]
target-version = "py310"
cache-dir = "./.cache/.ruff"
fix = true
# Same as Black.
line-length = 88
lint.ignore = [
target-version = "py310"

[tool.ruff.lint]
ignore = [
"COM812", # conflicts with ISC001 on format
"D203", # incompatible with D211
"D213", # incompatible with D212
"E501", # we use black
"ERA001", # auto-removal of commented out code affects development and vscode integration
"INP001", # "is part of an implicit namespace package", all false positives
"ISC001", # conflicts with COM812 on format
"PLW2901", # PLW2901: Redefined loop variable
"RET504", # Unnecessary variable assignment before `return` statement
# temporary disabled until we fix them:
Expand All @@ -252,9 +245,9 @@ lint.ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"PERF203",
"PD011", # We are not using pandas, any .values attributes are unrelated
"PLW0603", # global lock file in cache dir
"PLW0603" # global lock file in cache dir
]
lint.select = ["ALL"]
select = ["ALL"]

[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = ["id"]
Expand All @@ -263,45 +256,50 @@ builtins-ignorelist = ["id"]
parametrize-values-type = "tuple"

[tool.ruff.lint.isort]
known-first-party = ["ansiblelint"]
known-first-party = ["src"]

[tool.ruff.lint.mccabe]
# Implicit 10 is too low for our codebase, even black uses 18 as default.
max-complexity = 20

[tool.ruff.lint.per-file-ignores]
"test/**/*.py" = ["S"]
"src/ansiblelint/rules/*.py" = ["S"]
"src/ansiblelint/testing/*.py" = ["S"]
# Temporary disabled until we fix them:
"src/ansiblelint/{utils,file_utils,runner,loaders,constants,config,cli,_mockings}.py" = [
"PTH",
"PTH"
]
"test/**/*.py" = ["S"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.setuptools.dynamic]
dependencies = { file = [".config/requirements.in"] }
optional-dependencies.docs = { file = [".config/requirements-docs.in"] }
optional-dependencies.test = { file = [".config/requirements-test.in"] }
dependencies = {file = [".config/requirements.in"]}
optional-dependencies.docs = {file = [".config/requirements-docs.in"]}
optional-dependencies.test = {file = [".config/requirements-test.in"]}

[tool.setuptools_scm]
local_scheme = "no-local-version"
tag_regex = "^(?P<prefix>v)?(?P<version>[0-9.]+)(?P<suffix>.*)?$"
write_to = "src/ansiblelint/_version.py"
# To prevent accidental pick of mobile version tags such 'v6'
git_describe_command = [
"git",
"describe",
"--dirty",
"--tags",
"--long",
"--tags",
"--match",
"v*.*",
"v*.*"
]
local_scheme = "no-local-version"
tag_regex = "^(?P<prefix>v)?(?P<version>[0-9.]+)(?P<suffix>.*)?$"
write_to = "src/ansiblelint/_version.py"

[tool.tomlsort]
in_place = true
sort_inline_tables = true
sort_table_keys = true

[tool.uv.pip]
annotation-style = "line"
no-emit-package = ["ansible-core", "pip", "resolvelib", "typing_extensions", "uv"]
custom-compile-command = "tox run deps"
no-emit-package = ["ansible-core", "pip", "resolvelib", "typing_extensions", "uv"]
1 change: 1 addition & 0 deletions src/ansiblelint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""Main ansible-lint package."""

from __future__ import annotations

from ansiblelint.version import __version__
Expand Down
Loading

0 comments on commit 8b47b64

Please sign in to comment.