Skip to content

Commit ad79bff

Browse files
authored
Make git a runtime dependency (#2860)
As we received numerous bug reports which proved to be caused by the missing git, we make git a permanent runtime dependency. This will make the tool behavior more consistent as before that behavior would have being different if git was missing.
1 parent 0ca5d95 commit ad79bff

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

.config/ansible-lint.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BuildRequires: python%{python3_pkgversion}-pytest-xdist
2525
BuildRequires: python%{python3_pkgversion}-libselinux
2626
BuildRequires: git-core
2727
%endif
28+
Requires: git-core
2829

2930

3031
%description

.pre-commit-config.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,18 @@ repos:
163163
args: [--strict]
164164
additional_dependencies:
165165
- ansible-compat>=2.2.6
166-
- ansible-core>=2.14.0
167166
- black>=22.10.0
167+
- cryptography
168168
- filelock
169+
- jinja2
169170
- pytest>=7.2.0
170-
- pyyaml
171171
- rich>=11.0.0
172172
- ruamel.yaml
173-
- sphinx>=4.4.0
174-
- types-dataclasses
175-
- types-docutils
173+
- types-PyYAML
176174
- types-jsonschema>=4.4.2
177175
- types-pkg_resources
178-
- types-pyyaml>=6.0.4
176+
- types-setuptools
179177
- wcmatch
180-
- yamllint
181178
exclude: >
182179
(?x)^(
183180
test/local-content/.*|

src/ansiblelint/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ def path_inject() -> None:
397397
# We do know that finding ansible in PATH does not guarantee that it is
398398
# functioning or that is in fact the same version that was installed as
399399
# our dependency, but addressing this would be done by ansible-compat.
400-
if not shutil.which("ansible"):
401-
raise RuntimeError("Failed to find ansible executable in PATH")
400+
for cmd in ("ansible", "git"):
401+
if not shutil.which(cmd):
402+
raise RuntimeError(f"Failed to find runtime dependency '{cmd}' in PATH")
402403

403404

404405
# Based on Ansible implementation

test/test_main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests related to ansiblelint.__main__ module."""
22
import os
3+
import shutil
34
import subprocess
45
import sys
56
import time
@@ -19,19 +20,23 @@
1920
def test_call_from_outside_venv(expected_warning: bool) -> None:
2021
"""Asserts ability to be called w/ or w/o venv activation."""
2122
env = None
23+
24+
git_location = shutil.which("git")
25+
assert git_location
2226
if expected_warning:
23-
env = {"HOME": Path.home()}
27+
env = {"HOME": str(Path.home()), "PATH": str(os.path.dirname(git_location))}
2428
py_path = os.path.dirname(sys.executable)
2529
# Passing custom env prevents the process from inheriting PATH or other
2630
# environment variables from the current process, so we emulate being
2731
# called from outside the venv.
2832
proc = subprocess.run(
2933
[f"{py_path}/ansible-lint", "--version"],
30-
check=True,
34+
check=False,
3135
capture_output=True,
3236
text=True,
3337
env=env,
3438
)
39+
assert proc.returncode == 0, proc
3540
warning_found = "PATH altered to include" in proc.stderr
3641
assert warning_found is expected_warning
3742

0 commit comments

Comments
 (0)