From 3171cc307d7b0f19a42f863f3bb0063b9fa367ab Mon Sep 17 00:00:00 2001 From: dmitrij-zavrazhin-1304 Date: Thu, 11 Jul 2024 22:44:56 +0000 Subject: [PATCH 1/9] Add setting nodeps through cli and config support --- src/ansiblelint/__main__.py | 5 +++++ src/ansiblelint/cli.py | 9 +++++++++ src/ansiblelint/config.py | 9 ++------- src/ansiblelint/schemas/ansible-lint-config.json | 5 +++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 916ecdde4f..8e2336eb89 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -128,6 +128,11 @@ def initialize_options(arguments: list[str] | None = None) -> BaseFileLock | Non # persist loaded configuration inside options module for k, v in new_options.__dict__.items(): setattr(options, k, v) + + if options.nodeps is None or options.nodeps == False: + options.nodeps = bool(int(os.environ.get("ANSIBLE_LINT_NODEPS", "0"))) + if options.nodeps: + options.offline = True # rename deprecated ids/tags to newer names options.tags = [normalize_tag(tag) for tag in options.tags] diff --git a/src/ansiblelint/cli.py b/src/ansiblelint/cli.py index 41a0fdf9b2..d0a693bcd6 100644 --- a/src/ansiblelint/cli.py +++ b/src/ansiblelint/cli.py @@ -472,6 +472,14 @@ def get_cli_parser() -> argparse.ArgumentParser: const=True, help="Disable installation of requirements.yml and schema refreshing", ) + parser.add_argument( + "--nodeps", + dest="nodeps", + action="store_const", + const=True, + default=None, + help="Disable external dependency checking", + ) parser.add_argument( "--version", action="store_true", @@ -495,6 +503,7 @@ def merge_config(file_config: dict[Any, Any], cli_config: Options) -> Options: "strict", "use_default_rules", "offline", + "nodeps", ) # maps lists to their default config values lists_map = { diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 63e040f45c..11abc5432e 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -155,6 +155,7 @@ class Options: # pylint: disable=too-many-instance-attributes only_builtins_allow_modules: list[str] = field(default_factory=list) var_naming_pattern: str | None = None offline: bool = False + nodeps: bool | None = None project_dir: str = "." # default should be valid folder (do not use None here) extra_vars: dict[str, Any] | None = None enable_list: list[str] = field(default_factory=list) @@ -180,16 +181,10 @@ class Options: # pylint: disable=too-many-instance-attributes _default_supported = ["2.15.", "2.16.", "2.17."] supported_ansible_also: list[str] = field(default_factory=list) - @property - def nodeps(self) -> bool: - """Returns value of nodeps feature.""" - # We do not want this to be cached as it would affect our testings. - return bool(int(os.environ.get("ANSIBLE_LINT_NODEPS", "0"))) def __post_init__(self) -> None: """Extra initialization logic.""" - if self.nodeps: - self.offline = True + pass @property def supported_ansible(self) -> list[str]: diff --git a/src/ansiblelint/schemas/ansible-lint-config.json b/src/ansiblelint/schemas/ansible-lint-config.json index ae26bf0153..829af00930 100644 --- a/src/ansiblelint/schemas/ansible-lint-config.json +++ b/src/ansiblelint/schemas/ansible-lint-config.json @@ -87,6 +87,11 @@ "title": "Offline", "type": "boolean" }, + "nodeps": { + "default": null, + "title": "Nodeps", + "type": ["boolean", "null"] + }, "only_builtins_allow_collections": { "items": { "type": "string" From 080af75a1069acf7fe43ce26ac6f7baa87f55a66 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:02:16 +0000 Subject: [PATCH 2/9] chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/ansiblelint/__main__.py | 2 +- src/ansiblelint/config.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 8e2336eb89..ae8a58afce 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -128,7 +128,7 @@ def initialize_options(arguments: list[str] | None = None) -> BaseFileLock | Non # persist loaded configuration inside options module for k, v in new_options.__dict__.items(): setattr(options, k, v) - + if options.nodeps is None or options.nodeps == False: options.nodeps = bool(int(os.environ.get("ANSIBLE_LINT_NODEPS", "0"))) if options.nodeps: diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index 11abc5432e..1ff8baba6b 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -181,10 +181,8 @@ class Options: # pylint: disable=too-many-instance-attributes _default_supported = ["2.15.", "2.16.", "2.17."] supported_ansible_also: list[str] = field(default_factory=list) - def __post_init__(self) -> None: """Extra initialization logic.""" - pass @property def supported_ansible(self) -> list[str]: From db610c3eef9327de8c1120b226dd661becc62913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dmitrij=20Zavra=C5=BEin?= <112724233+dmitrij-zavrazhin-1304@users.noreply.github.com> Date: Sat, 13 Jul 2024 12:28:00 +0000 Subject: [PATCH 3/9] Fix lint == --- src/ansiblelint/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index ae8a58afce..bf4c33e72c 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -129,7 +129,7 @@ def initialize_options(arguments: list[str] | None = None) -> BaseFileLock | Non for k, v in new_options.__dict__.items(): setattr(options, k, v) - if options.nodeps is None or options.nodeps == False: + if options.nodeps is None or options.nodeps is False: options.nodeps = bool(int(os.environ.get("ANSIBLE_LINT_NODEPS", "0"))) if options.nodeps: options.offline = True From a4890a6bb3960709f7f1b01ec5194648ae1f19d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dmitrij=20Zavra=C5=BEin?= <112724233+dmitrij-zavrazhin-1304@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:46:21 +0000 Subject: [PATCH 4/9] Add flag test --- test/test_main.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_main.py b/test/test_main.py index 57f4700d1f..cffa890590 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -122,6 +122,13 @@ def test_get_version_warning_offline(mocker: MockerFixture) -> None: def test_nodeps(lintable: str) -> None: """Asserts ability to be called w/ or w/o venv activation.""" env = os.environ.copy() + proc = subprocess.run( + [str(py_path / "ansible-lint"), '--nodeps=true', lintable], + check=False, + capture_output=True, + text=True, + env=env, + ) env["ANSIBLE_LINT_NODEPS"] = "1" py_path = Path(sys.executable).parent proc = subprocess.run( From 0ef8db4969a40a01170ae86941a248e16fee2601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dmitrij=20Zavra=C5=BEin?= <112724233+dmitrij-zavrazhin-1304@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:46:51 +0000 Subject: [PATCH 5/9] Update test_main.py --- test/test_main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_main.py b/test/test_main.py index cffa890590..a0aff1d7e6 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -129,6 +129,7 @@ def test_nodeps(lintable: str) -> None: text=True, env=env, ) + assert proc.returncode == 0, proc env["ANSIBLE_LINT_NODEPS"] = "1" py_path = Path(sys.executable).parent proc = subprocess.run( From edc8146c1d7b3fadca0e1753d54cb81e8bd1612a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dmitrij=20Zavra=C5=BEin?= <112724233+dmitrij-zavrazhin-1304@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:47:14 +0000 Subject: [PATCH 6/9] Update test_main.py --- test/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_main.py b/test/test_main.py index a0aff1d7e6..bbafc0ad3d 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -122,6 +122,7 @@ def test_get_version_warning_offline(mocker: MockerFixture) -> None: def test_nodeps(lintable: str) -> None: """Asserts ability to be called w/ or w/o venv activation.""" env = os.environ.copy() + py_path = Path(sys.executable).parent proc = subprocess.run( [str(py_path / "ansible-lint"), '--nodeps=true', lintable], check=False, @@ -131,7 +132,6 @@ def test_nodeps(lintable: str) -> None: ) assert proc.returncode == 0, proc env["ANSIBLE_LINT_NODEPS"] = "1" - py_path = Path(sys.executable).parent proc = subprocess.run( [str(py_path / "ansible-lint"), lintable], check=False, From e87ab922d5938134a08b0bdc50ab20e7080bc2d9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:47:25 +0000 Subject: [PATCH 7/9] chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_main.py b/test/test_main.py index bbafc0ad3d..c3c6cb6d21 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -124,7 +124,7 @@ def test_nodeps(lintable: str) -> None: env = os.environ.copy() py_path = Path(sys.executable).parent proc = subprocess.run( - [str(py_path / "ansible-lint"), '--nodeps=true', lintable], + [str(py_path / "ansible-lint"), "--nodeps=true", lintable], check=False, capture_output=True, text=True, From 22f3cae7fb1d48432cd3a3f72673f0b8ea107046 Mon Sep 17 00:00:00 2001 From: dmitrij-zavrazhin-1304 Date: Tue, 30 Jul 2024 10:02:06 +0000 Subject: [PATCH 8/9] Remove =true --- test/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_main.py b/test/test_main.py index c3c6cb6d21..ef345baed2 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -124,7 +124,7 @@ def test_nodeps(lintable: str) -> None: env = os.environ.copy() py_path = Path(sys.executable).parent proc = subprocess.run( - [str(py_path / "ansible-lint"), "--nodeps=true", lintable], + [str(py_path / "ansible-lint"), "--nodeps", lintable], check=False, capture_output=True, text=True, From d1e570afaf3ab9794ccb78cd0b2d2fd95a841d68 Mon Sep 17 00:00:00 2001 From: dmitrij-zavrazhin-1304 Date: Wed, 31 Jul 2024 10:39:16 +0000 Subject: [PATCH 9/9] Fix transformer test --- test/test_transformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_transformer.py b/test/test_transformer.py index 6ce2e0ca58..1e94753f93 100644 --- a/test/test_transformer.py +++ b/test/test_transformer.py @@ -200,7 +200,7 @@ def fixture_runner_result( pytest.param( "examples/playbooks/4114/transform-with-missing-role-and-modules.yml", 1, - True, + False, True, id="4114", ),