Skip to content

Commit 38d91d9

Browse files
committed
fix: avoid unnecessary creation of .ansible folders
Related: AAP-60425 Fixes: #4533
1 parent efe2751 commit 38d91d9

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ test/local-content
7979
test/schemas/node_modules
8080
node_modules
8181
.direnv
82-
.ansible
82+
83+
# ignore it only at repository root as we want to discover if these are
84+
# created accidentally in other folders.
85+
/.ansible
86+
# used during testing as presence of examples/.config/ansible-lint.yml makes
87+
# linter determine that project root is /examples
88+
/examples/.ansible

examples/playbooks/.ansible-lint-only-builtins-allow

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json
22
# Mock modules or roles in order to pass ansible-playbook --syntax-check
3+
project_dir: ../..
34
mock_modules:
45
- fake_namespace.fake_collection.fake_module
6+
- zuul_return
57

68
only_builtins_allow_collections:
79
- fake_namespace.fake_collection

src/ansiblelint/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self, options: Options):
4848

4949
# Without require_module, our _set_collections_basedir may fail
5050
self.runtime = Runtime(
51+
project_dir=Path(options.project_dir),
5152
isolated=True,
5253
require_module=True,
5354
verbosity=options.verbosity,

src/ansiblelint/rules/only_builtins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def test_only_builtins_allow() -> None:
9090
result = run_ansible_lint(
9191
f"--config-file={conf_path}",
9292
"--strict",
93+
"--offline",
94+
"--nocolor",
9395
"--warn-list=",
9496
"--enable-list",
9597
"only-builtins",

test/test_main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,23 @@ def test_list_tags() -> None:
183183
assert isinstance(item, str)
184184

185185

186-
def test_ro_venv() -> None:
186+
def test_ro_venv(tmp_path: Path) -> None:
187187
"""Tests behavior when the virtual environment is read-only."""
188188
tox_work_dir = os.environ.get("TOX_WORK_DIR", ".tox")
189189
venv_path = f"{tox_work_dir}/ro"
190-
prerelease_flag = "" if sys.version_info < (3, 14) else "--pre "
191190
commands = [
192191
f"mkdir -p {venv_path}",
193192
f"chmod -R a+w {venv_path}",
194193
f"rm -rf {venv_path}",
195-
f"python -m venv --symlinks {venv_path}",
196-
f"{venv_path}/bin/python -m pip install {prerelease_flag}-q -e .",
194+
f"uv venv --seed --no-project {venv_path}",
195+
f"VIRTUAL_ENV={venv_path} uv pip install -q -e .",
197196
f"chmod -R a-w {venv_path}",
198197
# running with a ro venv and default cwd
199198
f"{venv_path}/bin/ansible-lint --version",
200199
# running from a read-only cwd:
201200
f"cd / && {abspath(venv_path)}/bin/ansible-lint --version", # noqa: PTH100
202201
# running with a ro venv and a custom project path in forced non-online mode, so it will need to install requirements
203-
f"{venv_path}/bin/ansible-lint -vv --no-offline --project-dir ./examples/reqs_v2/ ./examples/reqs_v2/",
202+
f"{venv_path}/bin/ansible-lint -vv --nocolor --no-offline --project-dir {tmp_path.as_posix()} ./examples/reqs_v2/",
204203
]
205204
for cmd in commands:
206205
result = subprocess.run(

test/test_utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import pytest
3131
from ansible.utils.sentinel import Sentinel
32-
from ansible_compat.runtime import Runtime
3332
from packaging.version import Version
3433

3534
from ansiblelint import cli, constants, utils
@@ -54,8 +53,6 @@
5453

5554
from ansiblelint.rules import RulesCollection
5655

57-
runtime = Runtime(require_module=True)
58-
5956

6057
@pytest.mark.parametrize(
6158
("string", "expected_args", "expected_kwargs"),

0 commit comments

Comments
 (0)