diff --git a/.config/requirements-test.txt b/.config/requirements-test.txt index 4d4c868f24..58c8feb8f4 100644 --- a/.config/requirements-test.txt +++ b/.config/requirements-test.txt @@ -1,8 +1,6 @@ black # IDE support coverage-enable-subprocess # see https://github.com/nedbat/coveragepy/issues/1341#issuecomment-1228942657 coverage[toml] >= 6.4.4 -flake8 # IDE support -flake8-future-annotations # IDE support jmespath mypy # IDE support netaddr # needed by ipwrap filter diff --git a/.config/requirements.txt b/.config/requirements.txt index d46a94a6e5..0897f72c59 100644 --- a/.config/requirements.txt +++ b/.config/requirements.txt @@ -27,8 +27,6 @@ dill==0.3.6 exceptiongroup==1.1.1 execnet==1.9.0 filelock==3.11.0 -flake8==6.0.0 -flake8-future-annotations==1.1.0 ghp-import==2.1.0 griffe==0.26.0 htmlmin2==0.1.13 @@ -72,9 +70,7 @@ platformdirs==3.2.0 pluggy==1.0.0 ply==3.11 psutil==5.9.4 -pycodestyle==2.10.0 pycparser==2.21 -pyflakes==3.0.1 pygments==2.14.0 pylint==2.17.2 pymdown-extensions==9.10 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 966d510788..0000000000 --- a/.flake8 +++ /dev/null @@ -1,83 +0,0 @@ -# spell-checker:ignore testmon tmontmp -[flake8] - -# Don't even try to analyze these: -extend-exclude = - # No need to traverse egg info dir - *.egg-info, - # GitHub configs - .github, - # Cache files of MyPy - .mypy_cache, - # Cache files of pytest - .pytest_cache, - # Temp dir of pytest-testmon - .tmontmp, - # Occasional virtualenv dir - .venv - # VS Code - .vscode, - # Temporary build dir - build, - # This contains sdists and wheels of ansible-lint that we don't want to check - dist, - # Occasional virtualenv dir - env, - # Metadata of `pip wheel` cmd is autogenerated - pip-wheel-metadata, - # vendored code - src/ansiblelint/_vendor/*, - -# Let's not over-complicate the code: -max-complexity = 10 - -# Accessibility/large fonts and PEP8 friendly: -#max-line-length = 79 -# Accessibility/large fonts and PEP8 unfriendly: -max-line-length = 100 - -# The only allowed ignores are related to black and isort -# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length -# "H" are generated by hacking plugin, which is not black compatible -extend-ignore = - E203, - E501, - # complexity is also measured by pylint: too-many-branches - C901, - # We use type annotations instead - DAR101, - DAR104, - # https://github.com/terrencepreilly/darglint/issues/165 - DAR301, - # duplicate of pylint W0611 (unused-import) - F401, - # duplicate of pylint E0602 (undefined-variable) - F821, - # duplicate of pylint W0612 (unused-variable) - F841, - H, - -# Allow certain violations in certain files: -per-file-ignores = - # FIXME: D102 Missing docstring in public method - src/ansiblelint/cli.py: D102 - src/ansiblelint/formatters/__init__.py: D102 - src/ansiblelint/rules/*.py: D102 - src/ansiblelint/rules/__init__.py: D102 - - # FIXME: C901 Function is too complex - # FIXME: refactor _defaults_from_yamllint_config using match case - # once python 3.10 is mandatory - # Ref: https://github.com/ansible/ansible-lint/pull/2077 - src/ansiblelint/yaml_utils.py: C901 - - # FIXME: drop these once they're fixed - # Ref: https://github.com/ansible/ansible-lint/issues/725 - test/*: D102 - -# flake8-pytest-style -# PT006: -pytest-parametrize-names-type = tuple -# PT007: -pytest-parametrize-values-type = tuple -pytest-parametrize-values-row-type = tuple diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13548e36cb..b927c39e9b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -134,24 +134,6 @@ repos: hooks: - id: black language_version: python3 - - repo: https://github.com/pycqa/flake8.git - rev: 6.0.0 - hooks: - - id: flake8 - language_version: python3 - additional_dependencies: - - flake8-2020>=1.6.0 - # - flake8-black>=0.1.1 - - flake8-docstrings>=1.5.0 - - flake8-print>=5.0 - - flake8-pytest-style>=1.2.2 - - flake8-future-annotations>=0.0.3 - - repo: https://github.com/asottile/pyupgrade - # keep it after flake8 - rev: v3.3.1 - hooks: - - id: pyupgrade - args: ["--py39-plus"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.2.0 hooks: diff --git a/conftest.py b/conftest.py index c3f1b4ba52..a8dcf52646 100644 --- a/conftest.py +++ b/conftest.py @@ -10,7 +10,7 @@ # checking if user is running pytest without installing test dependencies: missing = [] -for module in ["ansible", "black", "flake8", "mypy", "pylint"]: +for module in ["ansible", "black", "mypy", "pylint"]: if not importlib.util.find_spec(module): missing.append(module) if missing: @@ -31,7 +31,7 @@ print(f"{exc}\n{exc.stderr}\n{exc.stdout}", file=sys.stderr) sys.exit(1) -# flake8: noqa: E402 +# ruff: noqa: E402 from ansible.module_utils.common.yaml import ( # pylint: disable=wrong-import-position HAS_LIBYAML, ) diff --git a/docs/contributing.md b/docs/contributing.md index ccebf10fba..b6c46a7b4d 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -25,14 +25,11 @@ fix. ## Standards -ansible-lint is flake8 compliant with **max-line-length** set to 100. - ansible-lint works only with supported Ansible versions at the time it was released. -Automated tests will be run against all PRs for flake8 compliance and Ansible -compatibility — to check before pushing commits, just use -[tox](https://tox.wiki/en/latest/). +Automated tests will be run against all PRs, to run checks locally before +pushing commits, just use [tox](https://tox.wiki/en/latest/). % DO-NOT-REMOVE-deps-snippet-PLACEHOLDER @@ -53,7 +50,6 @@ Possible security bugs should be reported via email to As with all Ansible projects, we have a [Code of Conduct]. -[.flake8]: https://github.com/ansible/ansible-lint/blob/main/.flake8 [ansible announce]: https://groups.google.com/forum/#!forum/ansible-announce [ansible communication]: https://docs.ansible.com/ansible/latest/community/communication.html diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 7748bded7a..14be4d9639 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -121,7 +121,7 @@ def initialize_options(arguments: list[str] | None = None) -> None: options.cache_dir_lock.acquire(timeout=180) except Timeout: # pragma: no cover _logger.error( - "Timeout waiting for another instance of ansible-lint to release the lock." + "Timeout waiting for another instance of ansible-lint to release the lock.", ) sys.exit(LOCK_TIMEOUT_RC) @@ -143,7 +143,8 @@ def _do_list(rules: RulesCollection) -> int: } console.print( - _rule_format_map.get(options.format, rules_as_str)(rules), highlight=False + _rule_format_map.get(options.format, rules_as_str)(rules), + highlight=False, ) return 0 @@ -198,7 +199,7 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901 if options.version: console.print( - f"ansible-lint [repr.number]{__version__}[/] using ansible [repr.number]{ansible_version()}[/]" + f"ansible-lint [repr.number]{__version__}[/] using ansible [repr.number]{ansible_version()}[/]", ) msg = get_version_warning() if msg: @@ -214,7 +215,7 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901 if options.progressive: _logger.warning( - "Progressive mode is deprecated and will be removed in next major version, use ignore files instead: https://ansible-lint.readthedocs.io/configuring/#ignoring-rules-for-entire-files" + "Progressive mode is deprecated and will be removed in next major version, use ignore files instead: https://ansible-lint.readthedocs.io/configuring/#ignoring-rules-for-entire-files", ) if not options.offline: @@ -250,7 +251,7 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901 if result.matches and options.progressive: mark_as_success = False _logger.info( - "Matches found, running again on previous revision in order to detect regressions" + "Matches found, running again on previous revision in order to detect regressions", ) with _previous_revision(): _logger.debug("Options: %s", options) @@ -379,7 +380,6 @@ def path_inject() -> None: paths[idx] = os.path.expanduser(path) expanded = True if expanded: # pragma: no cover - # flake8: noqa: T201 print( "WARNING: PATH altered to expand ~ in it. Read https://stackoverflow.com/a/44704799/99834 and correct your system configuration.", file=sys.stderr, @@ -389,7 +389,7 @@ def path_inject() -> None: userbase_bin_path = f"{site.getuserbase()}/bin" if userbase_bin_path not in paths and os.path.exists( - f"{userbase_bin_path}/bin/ansible" + f"{userbase_bin_path}/bin/ansible", ): inject_paths.append(userbase_bin_path) @@ -399,7 +399,6 @@ def path_inject() -> None: if not os.environ.get("PYENV_VIRTUAL_ENV", None): if inject_paths: - # flake8: noqa: T201 print( f"WARNING: PATH altered to include {', '.join(inject_paths)} :: This is usually a sign of broken local setup, which can cause unexpected behaviors.", file=sys.stderr, diff --git a/src/ansiblelint/rules/role_name.py b/src/ansiblelint/rules/role_name.py index c9efeadfb5..c11e1a47ce 100644 --- a/src/ansiblelint/rules/role_name.py +++ b/src/ansiblelint/rules/role_name.py @@ -49,7 +49,6 @@ def _match_role_name_regex(role_name: str) -> bool: class RoleNames(AnsibleLintRule): - # Unable to use f-strings due to flake8 bug with AST parsing """Role name {0} does not match ``^[a-z][a-z0-9_]*$`` pattern.""" id = "role-name" diff --git a/src/ansiblelint/schemas/__main__.py b/src/ansiblelint/schemas/__main__.py index 2f1e4d385d..d23bc0f6a3 100644 --- a/src/ansiblelint/schemas/__main__.py +++ b/src/ansiblelint/schemas/__main__.py @@ -6,7 +6,7 @@ import time import urllib.request from collections import defaultdict -from functools import lru_cache +from functools import cache from pathlib import Path from typing import Any from urllib.request import Request @@ -30,7 +30,7 @@ def __missing__(self, key: str) -> Any: return value -@lru_cache(maxsize=None) +@cache def get_schema(kind: str) -> Any: """Return the schema for the given kind.""" schema_file = os.path.dirname(__file__) + "/" + kind + ".json" @@ -54,7 +54,8 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int: return 0 if not os.access(store_file, os.W_OK): # pragma: no cover _logger.debug( - "Skipping schema update due to lack of writing rights on %s", store_file + "Skipping schema update due to lack of writing rights on %s", + store_file, ) return -1 _logger.debug("Checking for updated schemas...") @@ -64,7 +65,7 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int: url = data["url"] if "#" in url: raise RuntimeError( - f"Schema URLs cannot contain # due to python-jsonschema limitation: {url}" + f"Schema URLs cannot contain # due to python-jsonschema limitation: {url}", ) path = Path(f"{os.path.relpath(os.path.dirname(__file__))}/{kind}.json") _logger.debug("Refreshing %s schema ...", kind) @@ -114,9 +115,7 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int: if __name__ == "__main__": if refresh_schemas(60 * 10): # pragma: no cover - # flake8: noqa: T201 print("Schemas were updated.") sys.exit(1) else: # pragma: no cover - # flake8: noqa: T201 print("Schemas not updated", 0) diff --git a/test/schemas/src/rebuild.py b/test/schemas/src/rebuild.py index 460ca8cb72..530070a68f 100644 --- a/test/schemas/src/rebuild.py +++ b/test/schemas/src/rebuild.py @@ -51,7 +51,7 @@ vars_files vars_prompt """.split(), - ) + ), ) @@ -77,20 +77,18 @@ def is_ref_used(obj: Any, ref: str) -> bool: invalid_var_names = sorted(list(keyword.kwlist) + play_keywords) if "__peg_parser__" in invalid_var_names: invalid_var_names.remove("__peg_parser__") - # flake8: noqa: T201 print("Updating invalid var names") with open("f/vars.json", "r+", encoding="utf-8") as f: vars_schema = json.load(f) vars_schema["anyOf"][0]["patternProperties"] = { - f"^(?!({'|'.join(invalid_var_names)})$)[a-zA-Z_][\\w]*$": {} + f"^(?!({'|'.join(invalid_var_names)})$)[a-zA-Z_][\\w]*$": {}, } f.seek(0) json.dump(vars_schema, f, indent=2) f.write("\n") f.truncate() - # flake8: noqa: T201 print("Compiling subschemas...") with open("f/ansible.json", encoding="utf-8") as f: combined_json = json.load(f) diff --git a/test/schemas/test/molecule/cluster/molecule.yml b/test/schemas/test/molecule/cluster/molecule.yml index bf40d141ae..f3e586cb05 100644 --- a/test/schemas/test/molecule/cluster/molecule.yml +++ b/test/schemas/test/molecule/cluster/molecule.yml @@ -9,7 +9,6 @@ lint: | set -e yamllint -c molecule/yaml-lint.yml . ansible-lint - flake8 platforms: - name: instance-1 diff --git a/test/schemas/test/molecule/default/molecule.yml b/test/schemas/test/molecule/default/molecule.yml index b3e290d9b9..b573e7438f 100644 --- a/test/schemas/test/molecule/default/molecule.yml +++ b/test/schemas/test/molecule/default/molecule.yml @@ -13,7 +13,6 @@ lint: | set -e yamllint . ansible-lint - flake8 driver: name: podman diff --git a/test/schemas/test/molecule/vagrant/molecule.yml b/test/schemas/test/molecule/vagrant/molecule.yml index 5630df633e..dea2c079a2 100644 --- a/test/schemas/test/molecule/vagrant/molecule.yml +++ b/test/schemas/test/molecule/vagrant/molecule.yml @@ -7,7 +7,6 @@ lint: | set -e yamllint . ansible-lint - flake8 driver: name: vagrant