Skip to content

Commit

Permalink
Merge branch 'main' into relax-yamllint-space-inside-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 29, 2022
2 parents 82108aa + e52dfe3 commit 0437aae
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 42 deletions.
5 changes: 0 additions & 5 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ filterwarnings =
# Ref: https://github.com/ansible-community/ansible-lint/pull/734
ignore:the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses:DeprecationWarning:ansible.plugins.loader

# TODO: delete the following ignores once Ansible gets rid of direct
# imports from `collections`
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working:DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working:DeprecationWarning
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working:DeprecationWarning
junit_duration_report = call
# Our github annotation parser from .github/workflows/tox.yml requires xunit1 format. Ref:
# https://github.com/shyim/junit-report-annotations-action/issues/3#issuecomment-663241378
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.3
commonmark==0.9.1
coverage==6.2
coverage==6.3.2
cryptography==37.0.1
dill==0.3.4
docutils==0.16
Expand Down Expand Up @@ -81,7 +81,7 @@ sphinxcontrib-programoutput2==2.0a1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
subprocess-tee==0.3.5
tomli==1.2.3
tomli==2.0.1
typing-extensions==4.2.0
urllib3==1.26.9
wcmatch==8.3
Expand Down
12 changes: 5 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ name = ansible-lint
url = https://github.com/ansible-community/ansible-lint
project_urls =
Bug Tracker = https://github.com/ansible-community/ansible-lint/issues
CI: GitHub = https://github.com/ansible-community/ansible-lint/actions?query=workflow:gh+branch:main+event:push
Release Management = https://github.com/ansible-community/ansible-lint/releases
CI: GitHub = https://github.com/ansible-community/ansible-lint/actions?query=workflow:tox+branch:main+event:push
Code of Conduct = https://docs.ansible.com/ansible/latest/community/code_of_conduct.html
Documentation = https://ansible-lint.readthedocs.io/en/latest/
Mailing lists = https://docs.ansible.com/ansible-community/latest/community/communication.html#mailing-list-information
Mailing lists = https://docs.ansible.com/ansible/latest/community/communication.html#asking-questions-over-email
Source Code = https://github.com/ansible-community/ansible-lint
description = Checks playbooks for practices and behavior that could potentially be improved
long_description = file: README.rst
Expand Down Expand Up @@ -35,8 +36,6 @@ classifiers =

Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand Down Expand Up @@ -74,7 +73,6 @@ install_requires =
# The next version is planned to have breaking changes
ruamel.yaml >= 0.15.34, < 0.18
# NOTE: per issue #509 0.15.34 included in debian backports
typing-extensions; python_version < "3.8"
wcmatch>=7.0 # MIT
yamllint >= 1.25.0 # GPLv3

Expand All @@ -93,8 +91,8 @@ docs =
sphinxcontrib-programoutput2 >= 2.0a1
yamllint >= 1.26.3
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))
coverage >= 6.3
tomli >= 2.0.0
flaky >= 3.7.0
pytest >= 6.0.1
pytest-cov >= 2.10.1
Expand Down
15 changes: 1 addition & 14 deletions src/ansiblelint/constants.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
"""Constants used by AnsibleLint."""
import os.path
import sys

# mypy/pylint idiom for py36-py38 compatibility
# https://github.com/python/typeshed/issues/3500#issuecomment-560958608
if sys.version_info >= (3, 8):
from typing import Literal # pylint: disable=no-name-in-module
else:
from typing_extensions import Literal
from typing import Literal

DEFAULT_RULESDIR = os.path.join(os.path.dirname(__file__), "rules")
CUSTOM_RULESDIR_ENVVAR = "ANSIBLE_LINT_CUSTOM_RULESDIR"
Expand Down Expand Up @@ -71,12 +64,6 @@ def main():
# odict is the base class used to represent data model of Ansible
# playbooks and tasks.
odict = dict # pylint: disable=invalid-name
if sys.version_info[:2] < (3, 7):
try:
# pylint: disable=unused-import
from collections import OrderedDict as odict # noqa: 401
except ImportError:
pass

# Deprecated tags/ids and their newer names
RENAMED_TAGS = {
Expand Down
10 changes: 1 addition & 9 deletions src/ansiblelint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@ def __init__(self, base_dir: Union[str, Path], display_relative_path: bool) -> N
if base_dir: # can be None
base_dir = base_dir.absolute()

# Required 'cause os.path.relpath() does not accept Path before 3.6
if isinstance(base_dir, Path):
base_dir = str(base_dir) # Drop when Python 3.5 is no longer supported

self._base_dir = base_dir if display_relative_path else None

def _format_path(self, path: Union[str, Path]) -> str:
# Required 'cause os.path.relpath() does not accept Path before 3.6
if isinstance(path, Path):
path = str(path) # Drop when Python 3.5 is no longer supported

def _format_path(self, path: Union[str, Path]) -> Union[str, Path]:
if not self._base_dir or not path:
return path
# Use os.path.relpath 'cause Path.relative_to() misbehaves
Expand Down
12 changes: 7 additions & 5 deletions test/test_formatter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def test_base_formatter_when_base_dir(
output_path = base_formatter._format_path(path) # pylint: disable=protected-access

# Then
assert isinstance(output_path, str)
assert isinstance(output_path, (str, Path))
# pylint: disable=protected-access
assert base_formatter._base_dir is None or isinstance(base_formatter._base_dir, str)
assert output_path == str(path)
assert base_formatter._base_dir is None or isinstance(
base_formatter._base_dir, (str, Path)
)
assert output_path == path


@pytest.mark.parametrize(
Expand All @@ -54,9 +56,9 @@ def test_base_formatter_when_base_dir_is_given_and_relative_is_true(
output_path = base_formatter._format_path(path)

# Then
assert isinstance(output_path, str)
assert isinstance(output_path, (str, Path))
# pylint: disable=protected-access
assert isinstance(base_formatter._base_dir, str)
assert isinstance(base_formatter._base_dir, (str, Path))
assert output_path == Path(path).name


Expand Down

0 comments on commit 0437aae

Please sign in to comment.