Skip to content

Commit

Permalink
Merge branch 'main' into feat/write_exclude_list
Browse files Browse the repository at this point in the history
  • Loading branch information
frq-asgard-josi authored Jul 22, 2024
2 parents d8becbb + 251aed4 commit 3157021
Show file tree
Hide file tree
Showing 38 changed files with 344 additions and 265 deletions.
35 changes: 18 additions & 17 deletions .config/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
#
# pip-compile --all-extras --no-annotate --output-file=.config/constraints.txt --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib --unsafe-package=wcmatch pyproject.toml
#
ansible-compat==24.6.1
ansible-core==2.17.1
astroid==3.2.2
ansible-compat==24.7.0
ansible-core==2.17.2
astroid==3.2.3
attrs==23.2.0
babel==2.15.0
backports-strenum==1.3.1
beautifulsoup4==4.12.3
black==24.4.2
boolean-py==4.0
bracex==2.4
cachetools==5.3.3
cachetools==5.4.0
cairocffi==1.7.1
cairosvg==2.7.1
certifi==2024.7.4
Expand All @@ -22,20 +23,20 @@ chardet==5.2.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
coverage==7.5.4
coverage==7.6.0
coverage-enable-subprocess==1.0
cryptography==42.0.8
cryptography==43.0.0
csscompressor==0.9.5
cssselect2==0.7.0
defusedxml==0.7.1
dill==0.3.8
distlib==0.3.8
dnspython==2.6.1
exceptiongroup==1.2.1
exceptiongroup==1.2.2
execnet==2.1.1
filelock==3.15.4
ghp-import==2.1.0
griffe==0.47.0
griffe==0.48.0
htmlmin2==0.1.13
idna==3.7
importlib-metadata==8.0.0
Expand All @@ -44,7 +45,7 @@ isort==5.13.2
jinja2==3.1.4
jmespath==1.0.1
jsmin==3.0.1
jsonschema==4.22.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
license-expression==30.3.0
linkchecker==10.4.0
Expand All @@ -63,21 +64,21 @@ mkdocs-gen-files==0.5.0
mkdocs-get-deps==0.2.0
mkdocs-htmlproofer-plugin==1.2.1
mkdocs-macros-plugin==1.0.5
mkdocs-material==9.5.28
mkdocs-material==9.5.29
mkdocs-material-extensions==1.3.1
mkdocs-minify-plugin==0.8.0
mkdocs-monorepo-plugin==1.1.0
mkdocstrings==0.25.1
mkdocstrings-python==1.10.5
mypy==1.10.1
mypy==1.11.0
mypy-extensions==1.0.0
netaddr==1.3.0
packaging==24.1
paginate==0.5.6
pathspec==0.12.1
pillow==10.4.0
pip==24.1.1
pipdeptree==2.23.0
pip==24.1.2
pipdeptree==2.23.1
platformdirs==4.2.2
pluggy==1.5.0
psutil==6.0.0
Expand All @@ -86,7 +87,7 @@ pygments==2.18.0
pylint==3.2.5
pymdown-extensions==10.8.1
pyproject-api==1.7.1
pytest==8.2.2
pytest==8.3.1
pytest-mock==3.14.0
pytest-plus==0.7.0
pytest-xdist==3.6.1
Expand All @@ -98,7 +99,7 @@ referencing==0.35.1
regex==2024.5.15
requests==2.32.3
rich==13.7.1
rpds-py==0.18.1
rpds-py==0.19.0
ruamel-yaml==0.18.6
six==1.16.0
soupsieve==2.5
Expand All @@ -107,9 +108,9 @@ termcolor==2.4.0
text-unidecode==1.3
tinycss2==1.3.0
tomli==2.0.1
tomlkit==0.12.5
tomlkit==0.13.0
tox==4.16.0
types-jsonschema==4.22.0.20240610
types-jsonschema==4.23.0.20240712
types-pyyaml==6.0.12.20240311
typing-extensions==4.12.2
urllib3==2.2.2
Expand Down
10 changes: 5 additions & 5 deletions .config/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#
# pip-compile --no-annotate --output-file=.config/requirements-lock.txt --strip-extras --unsafe-package=resolvelib --unsafe-package=ruamel-yaml-clib pyproject.toml
#
ansible-compat==24.6.1
ansible-core==2.17.1
ansible-compat==24.7.0
ansible-core==2.17.2
attrs==23.2.0
black==24.4.2
bracex==2.4
cffi==1.16.0
click==8.1.7
cryptography==42.0.8
cryptography==43.0.0
filelock==3.15.4
importlib-metadata==8.0.0
jinja2==3.1.4
jsonschema==4.22.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
markdown-it-py==3.0.0
markupsafe==2.1.5
Expand All @@ -29,7 +29,7 @@ pygments==2.18.0
pyyaml==6.0.1
referencing==0.35.1
rich==13.7.1
rpds-py==0.18.1
rpds-py==0.19.0
ruamel-yaml==0.18.6
subprocess-tee==0.4.2
tomli==2.0.1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 884
PYTEST_REQPASS: 886
steps:
- uses: actions/checkout@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ repos:
- [email protected]
- [email protected]
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.8.2
rev: v8.10.1
hooks:
- id: cspell
# entry: codespell --relative
args: [--relative, --no-progress, --no-summary]
name: Spell check with cspell
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.4
rev: 0.29.0
hooks:
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks.git
Expand Down Expand Up @@ -137,7 +137,7 @@ repos:
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.7"
rev: "v0.5.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -147,7 +147,7 @@ repos:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.10.1
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
Expand Down Expand Up @@ -178,7 +178,7 @@ repos:
plugins/.*
)$
- repo: https://github.com/pycqa/pylint
rev: v3.2.2
rev: v3.2.5
hooks:
- id: pylint
args:
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ inputs:
description: The directory where to run ansible-lint from. Default is `github.workspace`.
required: false
default: ""
requirements_file:
description: Path to the requirements YAML file to install role and collection dependencies.
required: false
default: ""
runs:
using: composite
steps:
Expand Down Expand Up @@ -65,6 +69,12 @@ runs:
pip install "ansible-lint[lock] @ git+https://github.com/ansible/ansible-lint@$GH_ACTION_REF"
ansible-lint --version
- name: Install role and collection dependencies from requirements file
if: inputs.requirements_file != ''
shell: bash
working-directory: ${{ steps.inputs.outputs.working_directory }}
run: ansible-galaxy install -r ${{ inputs.requirements_file }}

- name: Run ansible-lint
shell: bash
working-directory: ${{ steps.inputs.outputs.working_directory }}
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def pytest_configure(config: pytest.Config) -> None:
# we need to be sure that we have the requirements installed as some tests
# might depend on these. This approach is compatible with GHA caching.
try:
subprocess.check_output(
["./tools/install-reqs.sh"], # noqa: S603
subprocess.check_output( # noqa: S603
["./tools/install-reqs.sh"],
stderr=subprocess.PIPE,
text=True,
)
Expand Down
13 changes: 6 additions & 7 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ create a new rule by following the steps below:
- If the rule is task specific, it may be best to include a test to verify its
use inside blocks as well.
- Optionally run only the rule specific tests with a command like:
{command}`tox -e py -- -k NewRule`
- Run {command}`tox` in order to run all ansible-lint tests. Adding a new rule
can break some other tests. Update them if needed.
- Run {command}`ansible-lint -L` and check that the rule description renders
correctly.
- Build the docs using {command}`tox -e docs` and check that the new rule is
displayed correctly in them.
`tox -e py -- -k NewRule`
- Run `tox` in order to run all ansible-lint tests. Adding a new rule can break
some other tests. Update them if needed.
- Run `ansible-lint -L` and check that the rule description renders correctly.
- Build the docs using `tox -e docs` and check that the new rule is displayed
correctly in them.

[metatagvalidrule]:
https://github.com/ansible/ansible-lint/blob/main/src/ansiblelint/rules/meta_no_tags.py
Expand Down
22 changes: 13 additions & 9 deletions docs/custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ Each rule definition should also invoke one of the following methods:
The following is an example rule that uses the `match` method:

```python
from typing import Union
from ansiblelint.rules import AnsibleLintRule


class DeprecatedVariableRule(AnsibleLintRule):
"""Deprecated variable declarations."""

id = 'EXAMPLE002'
description = 'Check for lines that have old style ${var} ' + \
'declarations'
tags = { 'deprecations' }
tags = ['deprecations']

def match(self, line: str) -> Union[bool, str]:
return '${' in line
Expand All @@ -51,32 +53,34 @@ class DeprecatedVariableRule(AnsibleLintRule):
The following is an example rule that uses the `matchtask` method:

```python
from typing import TYPE_CHECKING, Any, Dict, Union
from __future__ import annotations
from typing import TYPE_CHECKING, Union

import ansiblelint.utils
from ansiblelint.rules import AnsibleLintRule

if TYPE_CHECKING:
from ansiblelint.file_utils import Lintable
from ansiblelint.utils import Task


class TaskHasTag(AnsibleLintRule):
"""Tasks must have tag."""

id = 'EXAMPLE001'
description = 'Tasks must have tag'
tags = ['productivity']

def matchtask(self, task: Task, file: 'Lintable' | None = None) -> Union[bool,str]:
def matchtask(self,
task: Task,
file: Lintable
| None = None) -> Union[bool, str]:
# If the task include another task or make the playbook fail
# Don't force to have a tag
if not set(task.keys()).isdisjoint(['include','fail']):
if not set(task.keys()).isdisjoint(['include', 'fail']):
return False

# Task should have tags
if not task.has_key('tags'):
return True

if not task.get("tags"):
return True
return False
```

Expand Down
2 changes: 1 addition & 1 deletion docs/installing.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@v6
uses: ansible/ansible-lint@main
```
Due to limitations on how GitHub Actions are processing arguments, we do not
Expand Down
10 changes: 10 additions & 0 deletions examples/playbooks/bug-4095.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Test task
hosts: localhost
connection: local
tasks:
- name: Reproduce bug related bug 4095
ansible.builtin.include_role:
name: local.testcollection.bug4095
vars:
var1: val1
5 changes: 1 addition & 4 deletions examples/rules/task_has_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ def matchtask(
return False

# Task should have tags
if "tags" not in task:
return True

return False
return "tags" not in task
4 changes: 1 addition & 3 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ def to_bool(value: Any) -> bool: # pragma: no cover
return bool(value)
if isinstance(value, str):
value = value.lower()
if value in ("yes", "on", "1", "true", 1):
return True
return False
return value in ("yes", "on", "1", "true", 1)


def should_do_markup(stream: TextIO = sys.stdout) -> bool: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/avoid_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_template_instead_of_copy_positive() -> None:
collection.register(AvoidImplicitRule())
success = "examples/playbooks/rule-avoid-implicit-pass.yml"
good_runner = Runner(success, rules=collection)
assert [] == good_runner.run()
assert good_runner.run() == []

def test_template_instead_of_copy_negative() -> None:
"""Negative test for avoid-implicit."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/deprecated_bare_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_use_bare_positive() -> None:
collection.register(UsingBareVariablesIsDeprecatedRule())
success = "examples/playbooks/rule-deprecated-bare-vars-pass.yml"
good_runner = Runner(success, rules=collection)
assert [] == good_runner.run()
assert good_runner.run() == []

def test_use_bare_negative() -> None:
"""Negative test for deprecated-bare-vars."""
Expand Down
5 changes: 1 addition & 4 deletions src/ansiblelint/rules/deprecated_local_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def matchtask(
) -> bool | str:
"""Return matches for a task."""
raw_task = task["__raw_task__"]
if "local_action" in raw_task:
return True

return False
return "local_action" in raw_task

def transform(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_galaxy_collection_version_positive() -> None:
collection.register(GalaxyRule())
success = "examples/.collection/galaxy.yml"
good_runner = Runner(success, rules=collection)
assert [] == good_runner.run()
assert good_runner.run() == []

def test_galaxy_collection_version_negative() -> None:
"""Negative test for collection version in galaxy."""
Expand Down
Loading

0 comments on commit 3157021

Please sign in to comment.