Skip to content

Commit e00102a

Browse files
cidrblockQalthos
authored andcommitted
Switch to python -m
1 parent 43199fd commit e00102a

File tree

2 files changed

+5
-45
lines changed

2 files changed

+5
-45
lines changed

Diff for: src/ansible_dev_environment/utils.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import time
1212

1313
from dataclasses import dataclass
14-
from pathlib import Path
1514
from typing import TYPE_CHECKING
1615

1716
import subprocess_tee
1817
import yaml
1918

2019

2120
if TYPE_CHECKING:
21+
from pathlib import Path
2222
from types import TracebackType
2323

2424
from .config import Config
@@ -280,25 +280,15 @@ def collect_manifests( # noqa: C901
280280
def builder_introspect(config: Config, output: Output) -> None:
281281
"""Introspect a collection.
282282
283-
Default to the path of ansible-builder adjacent to the python executable.
284-
Since ansible-builder is a dependency of ade, it should be in the same bin directory
285-
as the python interpreter that spawned the ade process.
286-
If not found, we cannot introspect.
283+
Use the sys executable to run builder, since it is a direct dependency
284+
it should be accessible to the current interpreter.
287285
288286
Args:
289287
config: The configuration object.
290288
output: The output object.
291289
"""
292-
builder_path = Path(sys.executable).parent / "ansible-builder"
293-
if not builder_path.exists():
294-
output.critical(
295-
"Failed to find ansible-builder. Please check the installation"
296-
" of ade as it should have been installed by default.",
297-
)
298-
return # pragma: no cover
299-
300290
command = (
301-
f"{builder_path} introspect {config.site_pkg_path}"
291+
f"{sys.executable} -m ansible_builder introspect {config.site_pkg_path}"
302292
f" --write-pip {config.discovered_python_reqs}"
303293
f" --write-bindep {config.discovered_bindep_reqs}"
304294
" --sanitize"
@@ -329,7 +319,7 @@ def builder_introspect(config: Config, output: Output) -> None:
329319
)
330320
except subprocess.CalledProcessError as exc:
331321
err = f"Failed to discover requirements: {exc} {exc.stderr}"
332-
logger.critical(err)
322+
output.critical(err)
333323

334324
if not config.discovered_python_reqs.exists():
335325
config.discovered_python_reqs.touch()

Diff for: tests/unit/test_utils.py

-30
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,3 @@ def cache_dir(_self: Config) -> Path:
163163

164164
assert cfg.discovered_bindep_reqs.exists() is True
165165
assert cfg.discovered_python_reqs.exists() is True
166-
167-
168-
def test_builder_not_found(monkeypatch: pytest.MonkeyPatch) -> None:
169-
"""Test builder not found raises a system exit.
170-
171-
Args:
172-
monkeypatch: The pytest Monkeypatch fixture
173-
174-
Raises:
175-
AssertionError: When the exit code is not 1
176-
"""
177-
178-
def exists(_self: Path) -> bool:
179-
"""Mock path exists.
180-
181-
Args:
182-
_self: The path object
183-
184-
Returns:
185-
False indicating the path does not exist
186-
187-
"""
188-
return False
189-
190-
monkeypatch.setattr(Path, "exists", exists)
191-
192-
with pytest.raises(SystemExit) as exc_info:
193-
builder_introspect(config, output)
194-
195-
assert exc_info.value.code == 1

0 commit comments

Comments
 (0)