Skip to content

Use current python interpreter to run builder #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/ansible_dev_environment/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,15 @@ def collect_manifests( # noqa: C901
def builder_introspect(config: Config, output: Output) -> None:
"""Introspect a collection.

Use the sys executable to run builder, since it is a direct dependency
it should be accessible to the current interpreter.

Args:
config: The configuration object.
output: The output object.
"""
command = (
f"ansible-builder introspect {config.site_pkg_path}"
f"{sys.executable} -m ansible_builder introspect {config.site_pkg_path}"
f" --write-pip {config.discovered_python_reqs}"
f" --write-bindep {config.discovered_bindep_reqs}"
" --sanitize"
Expand Down Expand Up @@ -316,7 +319,7 @@ def builder_introspect(config: Config, output: Output) -> None:
)
except subprocess.CalledProcessError as exc:
err = f"Failed to discover requirements: {exc} {exc.stderr}"
logger.critical(err)
output.critical(err)

if not config.discovered_python_reqs.exists():
config.discovered_python_reqs.touch()
Expand Down
42 changes: 41 additions & 1 deletion tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from ansible_dev_environment.config import Config
from ansible_dev_environment.output import Output
from ansible_dev_environment.utils import TermFeatures
from ansible_dev_environment.utils import TermFeatures, builder_introspect


term_features = TermFeatures(color=False, links=False)
Expand Down Expand Up @@ -123,3 +123,43 @@ def test_parse_collection_request(scenario: tuple[str, Collection | None]) -> No
parse_collection_request(string=string, config=config, output=output)
else:
assert parse_collection_request(string=string, config=config, output=output) == spec


def test_builder_found(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that builder is found.

Args:
tmp_path: A temporary path
monkeypatch: The pytest Monkeypatch fixture

Raises:
AssertionError: if either file is not found
"""

@property # type: ignore[misc]
def cache_dir(_self: Config) -> Path:
"""Return a temporary cache directory.

Args:
_self: The Config object

Returns:
A temporary cache directory.
"""
return tmp_path

monkeypatch.setattr(Config, "cache_dir", cache_dir)

args = Namespace(venv=str(tmp_path / ".venv"), system_site_packages=False, verbose=0)

cfg = Config(
args=args,
term_features=term_features,
output=output,
)
cfg.init()

builder_introspect(cfg, output)

assert cfg.discovered_bindep_reqs.exists() is True
assert cfg.discovered_python_reqs.exists() is True
Loading