Skip to content

Commit

Permalink
Made yamllint a direct dependency (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 13, 2022
1 parent 464fd99 commit 36e1b1e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 34 deletions.
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,33 +125,34 @@ repos:
- tenacity
- typing_extensions
- wcmatch
- yamllint
- # keep at bottom as these are slower
repo: local
hooks:
- id: pip-compile
name: pip-compile
entry: python3.9 -m piptools compile -q --no-annotate --output-file=constraints.txt setup.cfg --extra test --extra yamllint --strip-extras
entry: python3.9 -m piptools compile -q --no-annotate --output-file=constraints.txt setup.cfg --extra test --strip-extras
language: system
files: ^(setup\.cfg|=constraints\.txt)$
pass_filenames: false
stages: [manual]
- id: pip-compile-docs
name: pip-compile-docs
entry: python3.9 -m piptools compile -q --no-annotate --output-file=docs/requirements.txt --extra yamllint --strip-extras docs/requirements.in setup.cfg
entry: python3.9 -m piptools compile -q --no-annotate --output-file=docs/requirements.txt --strip-extras docs/requirements.in setup.cfg
language: system
files: ^(docs\/requirements\.(txt|in)|)$
pass_filenames: false
stages: [manual]
- id: pip-compile-upgrade
name: pip-compile-upgrade
entry: python3.9 -m piptools compile -q --upgrade --no-annotate --output-file=constraints.txt setup.cfg --extra test --extra yamllint --strip-extras
entry: python3.9 -m piptools compile -q --upgrade --no-annotate --output-file=constraints.txt setup.cfg --extra test --strip-extras
language: system
files: ^(setup\.cfg|=constraints\.txt)$
pass_filenames: false
stages: [manual]
- id: pip-compile-docs-upgrade
name: pip-compile-docs-upgrade
entry: python3.9 -m piptools compile -q --upgrade --no-annotate --extra yamllint --output-file=docs/requirements.txt --strip-extras docs/requirements.in setup.cfg
entry: python3.9 -m piptools compile -q --upgrade --no-annotate --output-file=docs/requirements.txt --strip-extras docs/requirements.in setup.cfg
language: system
files: ^(docs\/requirements\.(txt|in)|)$
pass_filenames: false
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
# if you want to use only the base ansible version for linting,
# replace 'community' extra with 'core' or just mention the exact
# version of Ansible you want to install as a dependency.
- .[community,yamllint]
- .[community]
2 changes: 1 addition & 1 deletion constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --extra=test --extra=yamllint --no-annotate --output-file=constraints.txt --strip-extras setup.cfg
# pip-compile --extra=test --no-annotate --output-file=constraints.txt --strip-extras setup.cfg
#
attrs==21.4.0
bracex==2.2.1
Expand Down
9 changes: 4 additions & 5 deletions docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ using ``--user`` or fixing potential conflicts if not using virtualenvs.

.. code-block:: bash
# Assuming you already installed Ansible and you also want the optional
# yamllint support:
pip3 install "ansible-lint[yamllint]"
# Assuming you already installed Ansible
pip3 install "ansible-lint"
# If you want to install and use the latest Ansible (w/o community collections)
pip3 install "ansible-lint[core,yamllint]"
pip3 install "ansible-lint[core]"
# If you want to install and use the latest Ansible with community collections
pip3 install "ansible-lint[community,yamllint]"
pip3 install "ansible-lint[community]"
# If you want to install an older version of Ansible 2.9
pip3 install ansible-lint "ansible>=2.9,<2.10"
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --extra=yamllint --no-annotate --output-file=docs/requirements.txt --strip-extras docs/requirements.in setup.cfg
# pip-compile --no-annotate --output-file=docs/requirements.txt --strip-extras docs/requirements.in setup.cfg
#
alabaster==0.7.12
ansible-core==2.12.2
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ install_requires =
tenacity
typing-extensions; python_version < "3.8"
wcmatch>=7.0 # MIT
yamllint >= 1.25.0 # GPLv3

[options.entry_points]
console_scripts =
Expand All @@ -97,9 +98,6 @@ core =
; Disabled due to https://github.com/pypa/twine/issues/726
; devel =
; ansible-core @ git+https://github.com/ansible/ansible.git # GPLv3+
# yamllint must remain optional
yamllint =
yamllint >= 1.25.0 # GPLv3
test =
coverage >= 6.2, < 6.3 # 6.3 dropped py37 support
tomli >= 1.2.3, < 2.0.0 # 2.0.0 dropped py37 support (needed by coverage))
Expand Down
20 changes: 3 additions & 17 deletions src/ansiblelint/rules/YamllintRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import sys
from typing import TYPE_CHECKING, List

from ansiblelint.config import options
from yamllint.config import YamlLintConfig
from yamllint.linter import run as run_yamllint

from ansiblelint.file_utils import Lintable
from ansiblelint.rules import AnsibleLintRule
from ansiblelint.skip_utils import get_rule_skips_from_line
Expand All @@ -13,18 +15,6 @@

_logger = logging.getLogger(__name__)

# yamllint is a soft-dependency (not installed by default)
try:
from yamllint.config import YamlLintConfig
from yamllint.linter import run as run_yamllint
except ImportError:
# missing library is ignored unless yaml is exclitely added to enable_list
if "yaml" in options.enable_list:
raise RuntimeError(
"Failed to load yamllint library and ansible-linted was configured to require it."
)


YAMLLINT_CONFIG = """
extends: default
rules:
Expand All @@ -48,10 +38,6 @@
Specific tag identifiers that are printed at the end of rule name,
like 'trailing-spaces' or 'indentation' can also be be skipped, allowing
you to have a more fine control.
By default this rule is not used when yamllint library is missing. If you want
to make its absence a runtime failure, please add 'yaml' to 'enable_list'
inside the configuration file.
"""


Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description =
devel: ansible devel branch
core: ansible-core 2.11+
deps =
--editable .[yamllint,test]
--editable .[test]
core: ansible-core
py: ansible-core>=2.11
devel: ansible-core @ git+https://github.com/ansible/ansible.git # GPLv3+
Expand Down Expand Up @@ -104,7 +104,7 @@ commands =
description = Builds docs
basepython = python3
deps =
--editable .[yamllint]
--editable .
-r{toxinidir}/docs/requirements.in
setenv =
PIP_CONSTRAINT = {toxinidir}/docs/requirements.txt
Expand Down

0 comments on commit 36e1b1e

Please sign in to comment.