Skip to content

Commit

Permalink
Remove flake8 and pyupgrade (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Apr 17, 2023
1 parent aaab279 commit b262e72
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 137 deletions.
2 changes: 0 additions & 2 deletions .config/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
83 changes: 0 additions & 83 deletions .flake8

This file was deleted.

18 changes: 0 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
)
Expand Down
8 changes: 2 additions & 6 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/role_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 5 additions & 6 deletions src/ansiblelint/schemas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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...")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
6 changes: 2 additions & 4 deletions test/schemas/src/rebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
vars_files
vars_prompt
""".split(),
)
),
)


Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion test/schemas/test/molecule/cluster/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ lint: |
set -e
yamllint -c molecule/yaml-lint.yml .
ansible-lint
flake8
platforms:
- name: instance-1
Expand Down
1 change: 0 additions & 1 deletion test/schemas/test/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ lint: |
set -e
yamllint .
ansible-lint
flake8
driver:
name: podman
Expand Down
1 change: 0 additions & 1 deletion test/schemas/test/molecule/vagrant/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ lint: |
set -e
yamllint .
ansible-lint
flake8
driver:
name: vagrant
Expand Down

0 comments on commit b262e72

Please sign in to comment.