Skip to content

Commit

Permalink
Merge branch 'main' into fix/update_become_method_detection
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka authored May 31, 2023
2 parents d767daa + d54b51c commit 9909503
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pygments==2.15.1
pyrsistent==0.19.3
pyyaml==6.0
rich==13.3.5
ruamel-yaml==0.17.27
ruamel-yaml==0.17.31
subprocess-tee==0.4.1
tomli==2.0.1
typing-extensions==4.6.2
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pytest >= 7.2.2
pytest-mock
pytest-plus >= 0.2 # for PYTEST_REQPASS
pytest-xdist >= 2.1.0
ruamel.yaml>=0.17.26,<0.18 # only the latest is expected to pass our tests
ruamel.yaml>=0.17.31,<0.18 # only the latest is expected to pass our tests
ruamel-yaml-clib # needed for mypy
spdx-tools >= 0.7.1 # Apache
types-jsonschema # IDE support
Expand Down
2 changes: 1 addition & 1 deletion .config/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jsonschema>=4.10.0 # MIT, version needed for improved errors
packaging>=21.3 # Apache-2.0,BSD-2-Clause
pyyaml>=5.4.1 # MIT (centos 9 has 5.3.1)
rich>=12.0.0 # MIT
ruamel.yaml>=0.17.0,<0.18 # MIT, next version is planned to have breaking changes
ruamel.yaml>=0.17.0,<0.18,!=0.17.29,!=0.17.30 # MIT, next version is planned to have breaking changes
subprocess-tee>=0.4.1 # MIT, used by ansible-compat
yamllint >= 1.30.0 # GPLv3
wcmatch>=8.1.2 # MIT
2 changes: 1 addition & 1 deletion .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ rdflib==6.3.2
regex==2023.5.5
requests==2.30.0
rich==13.3.5
ruamel-yaml==0.17.27
ruamel-yaml==0.17.31
six==1.16.0
soupsieve==2.4.1
spdx-tools==0.7.1
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ repos:
- pytest-mock
- pytest>=7.2.2
- rich>=13.2.0
- ruamel-yaml>=0.17.26
- ruamel-yaml>=0.17.31
- ruamel-yaml-clib>=0.2.7
- spdx-tools
- subprocess-tee
Expand Down Expand Up @@ -185,7 +185,7 @@ repos:
- pytest>=7.2.2
- pyyaml
- rich>=13.2.0
- ruamel-yaml>=0.17.26
- ruamel-yaml>=0.17.31
- ruamel-yaml-clib>=0.2.7
- spdx-tools
- typing_extensions
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ ignore-paths = "^src/ansiblelint/_version.*$"
# increase from default is 50 which is too aggressive
max-statements = 60
disable = [
# On purpose disabled as we rely on black
"line-too-long",
# Disabled on purpose:
"line-too-long", # covered by black
"too-many-branches", # covered by ruff C901
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
"duplicate-code",
# unable to disable it inside tests
Expand Down Expand Up @@ -243,6 +244,10 @@ target-version = "py39"
# Same as Black.
line-length = 88

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

[tool.ruff.flake8-builtins]
builtins-ignorelist = ["id"]

Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def support_banner() -> None:
)


# pylint: disable=too-many-branches,too-many-statements,too-many-locals
def main(argv: list[str] | None = None) -> int: # noqa: C901
# pylint: disable=too-many-statements,too-many-locals
def main(argv: list[str] | None = None) -> int:
"""Linter CLI entry point."""
# alter PATH if needed (venv support)
path_inject()
Expand Down Expand Up @@ -318,7 +318,7 @@ def _run_cli_entrypoint() -> None:
raise SystemExit(exc) from exc


def path_inject() -> None: # noqa: C901
def path_inject() -> None:
"""Add python interpreter path to top of PATH to fix outside venv calling."""
# This make it possible to call ansible-lint that was installed inside a
# virtualenv without having to pre-activate it. Otherwise subprocess will
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/_mockings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def _write_module_stub(
f.write(body)


# pylint: disable=too-many-branches
def _perform_mockings() -> None:
"""Mock modules and roles."""
path: Path
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, options: Options):
# Without require_module, our _set_collections_basedir may fail
self.runtime = Runtime(isolated=True, require_module=True)

def render_matches(self, matches: list[MatchError]) -> None: # noqa: C901
def render_matches(self, matches: list[MatchError]) -> None:
"""Display given matches (if they are not fixed)."""
matches = [match for match in matches if not match.fixed]

Expand Down Expand Up @@ -245,7 +245,7 @@ def report_outcome(
return RC.SUCCESS
return RC.VIOLATIONS_FOUND

def report_summary( # pylint: disable=too-many-branches,too-many-locals # noqa: C901
def report_summary( # pylint: disable=too-many-locals
self,
summary: SummarizedResults,
changed_files_count: int,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class Lintable:
"""

# pylint: disable=too-many-arguments
def __init__( # noqa: C901
def __init__(
self,
name: str | Path,
content: str | None = None,
Expand Down
7 changes: 3 additions & 4 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def matchlines(self, file: Lintable) -> list[MatchError]:
matches.append(matcherror)
return matches

# pylint: disable=too-many-branches
def matchtasks(self, file: Lintable) -> list[MatchError]: # noqa: C901
def matchtasks(self, file: Lintable) -> list[MatchError]:
"""Call matchtask for each task inside file and return aggregate results.
Most rules will never need to override matchtasks because its main
Expand Down Expand Up @@ -325,7 +324,7 @@ def transform(self, match, lintable, data):


# pylint: disable=too-many-nested-blocks
def load_plugins( # : max-complexity: 11
def load_plugins(
dirs: list[str],
) -> Iterator[AnsibleLintRule]:
"""Yield a rule class."""
Expand Down Expand Up @@ -438,7 +437,7 @@ def extend(self, more: list[AnsibleLintRule]) -> None:
"""Combine rules."""
self.rules.extend(more)

def run( # : max-complexity: 12
def run(
self,
file: Lintable,
tags: set[str] | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class ArgsRule(AnsibleLintRule):
"args[module]": description,
}

def matchtask( # noqa: C901
def matchtask(
self,
task: Task,
file: Lintable | None = None,
) -> list[MatchError]:
# pylint: disable=too-many-branches,too-many-locals,too-many-return-statements
# pylint: disable=too-many-locals,too-many-return-statements
results: list[MatchError] = []
module_name = task["action"]["__ansible_module_original__"]
failed_msg = None
Expand Down
8 changes: 4 additions & 4 deletions src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def _msg(self, tag: str, value: str, reformatted: str) -> str:
"""Generate error message."""
return self._tag2msg[tag].format(value=value, reformatted=reformatted)

# pylint: disable=too-many-branches,too-many-locals
def matchtask( # noqa: C901
# pylint: disable=too-many-locals
def matchtask(
self,
task: Task,
file: Lintable | None = None,
Expand Down Expand Up @@ -249,8 +249,8 @@ def unlex(self, tokens: list[Token]) -> str:
last_value = value
return result

# pylint: disable=too-many-branches,too-many-statements,too-many-locals
def check_whitespace( # noqa: C901
# pylint: disable=too-many-statements,too-many-locals
def check_whitespace(
self,
text: str,
key: str,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/role_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def matchtask(
def matchdir(self, lintable: Lintable) -> list[MatchError]:
return self.matchyaml(lintable)

def matchyaml(self, file: Lintable) -> list[MatchError]: # noqa: C901
def matchyaml(self, file: Lintable) -> list[MatchError]:
result: list[MatchError] = []

if file.kind not in ("meta", "role", "playbook"):
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class AnsibleSyntaxCheckRule(AnsibleLintRule):
_order = 0

@staticmethod
# pylint: disable=too-many-locals,too-many-branches
def _get_ansible_syntax_check_matches( # noqa: C901
# pylint: disable=too-many-locals
def _get_ansible_syntax_check_matches(
lintable: Lintable,
) -> list[MatchError]:
"""Run ansible syntax check and return a list of MatchError(s)."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/var_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:

return results

def matchtask( # noqa: C901
def matchtask(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def run(self) -> list[MatchError]:
)
return matches

def _run(self) -> list[MatchError]: # noqa: C901
def _run(self) -> list[MatchError]:
"""Run the linting (inner loop)."""
files: list[Lintable] = []
matches: list[MatchError] = []
Expand Down
3 changes: 1 addition & 2 deletions src/ansiblelint/schemas/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def get_schema(kind: str) -> Any:
_schema_cache = SchemaCacheDict()


# pylint: disable=too-many-branches
def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int: # noqa: C901
def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int:
"""Refresh JSON schemas by downloading latest versions.
Returns number of changed schemas.
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/skip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def load_data(file_text: str) -> Any:
return yaml.load_all(file_text)


def _append_skipped_rules( # noqa: max-complexity: 12
def _append_skipped_rules(
pyyaml_data: AnsibleBaseYAMLObject,
lintable: Lintable,
) -> AnsibleBaseYAMLObject | None:
Expand Down Expand Up @@ -252,7 +252,7 @@ def get_nested_tasks(task: Any) -> Generator[Any, None, None]:
yield task


def _get_rule_skips_from_yaml( # noqa: max-complexity: 12
def _get_rule_skips_from_yaml(
yaml_input: Sequence[Any],
lintable: Lintable,
) -> Sequence[Any]:
Expand All @@ -262,7 +262,7 @@ def _get_rule_skips_from_yaml( # noqa: max-complexity: 12
if isinstance(yaml_input, str):
return []

def traverse_yaml(obj: Any) -> None: # noqa: C901
def traverse_yaml(obj: Any) -> None:
for _, entry in obj.ca.items.items():
for v in entry:
if isinstance(v, CommentToken):
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _set_collections_basedir(basedir: Path) -> None:
AnsibleCollectionConfig.playbook_paths = str(basedir.resolve())


def find_children(lintable: Lintable) -> list[Lintable]: # noqa: C901
def find_children(lintable: Lintable) -> list[Lintable]:
"""Traverse children of a single file or folder."""
if not lintable.path.exists():
return []
Expand Down Expand Up @@ -830,7 +830,7 @@ def __iter__(self) -> Generator[str, None, None]:
yield from (f for f in self.normalized_task)


def task_in_list( # noqa: C901
def task_in_list(
data: AnsibleBaseYAMLObject,
file: Lintable,
kind: str,
Expand Down Expand Up @@ -906,7 +906,7 @@ def get_action_tasks(data: AnsibleBaseYAMLObject, file: Lintable) -> list[Any]:


@cache
def parse_yaml_linenumbers( # noqa: max-complexity: 12
def parse_yaml_linenumbers(
lintable: Lintable,
) -> AnsibleBaseYAMLObject:
"""Parse yaml as ansible.utils.parse_yaml but with linenumbers.
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _get_path_to_task_in_playbook(
return []


def _get_path_to_task_in_tasks_block( # noqa: C901
def _get_path_to_task_in_tasks_block(
lineno: int, # 1-based
tasks_block: CommentedSeq,
last_lineno: int | None = None, # 1-based
Expand Down Expand Up @@ -852,7 +852,7 @@ def __init__(
# self.Representer.add_representer(

@staticmethod
def _defaults_from_yamllint_config() -> dict[str, bool | int | str]: # noqa: C901
def _defaults_from_yamllint_config() -> dict[str, bool | int | str]:
"""Extract FormattedYAML-relevant settings from yamllint config if possible."""
config = {
"explicit_start": True,
Expand Down

0 comments on commit 9909503

Please sign in to comment.