Skip to content

Commit

Permalink
Add ansible-dev-tools install into venv (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
cidrblock authored May 1, 2024
1 parent 6db8cd3 commit a16081e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/ansible_dev_environment/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ def parse() -> argparse.Namespace:
help="Install editable.",
)

install.add_argument(
"-adt",
"--ansible-dev-tools",
action="store_true",
dest="adt",
help="Install ansible-dev-tools in the virtual environment.",
)

_uninstall = subparsers.add_parser(
"uninstall",
formatter_class=CustomHelpFormatter,
Expand Down
28 changes: 27 additions & 1 deletion src/ansible_dev_environment/subcommands/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def run(self: Installer) -> None:
err = "Multiple optional dependencies are not supported at this time."
self._output.critical(err)

self._install_core()
if self._config.args.adt:
self._install_dev_tools()
else:
self._install_core()

if self._config.args.requirement or self._config.args.cpi:
self._install_galaxy_requirements()
if self._config.args.collection_specifier:
Expand Down Expand Up @@ -116,6 +120,28 @@ def _install_core(self: Installer) -> None:
err = f"Failed to install ansible-core: {exc}"
self._output.critical(err)

def _install_dev_tools(self: Installer) -> None:
"""Install ansible developer tools."""
msg = "Installing ansible-dev-tools."
self._output.info(msg)

adt = self._config.venv_bindir / "adt"
if adt.exists():
return
msg = "Installing ansible-dev-tools."
self._output.debug(msg)
command = f"{self._config.venv_interpreter} -m pip install ansible-dev-tools"
try:
subprocess_run(
command=command,
verbose=self._config.args.verbose,
msg=msg,
output=self._output,
)
except subprocess.CalledProcessError as exc:
err = f"Failed to install ansible-dev-tools: {exc}"
self._output.critical(err)

def _install_galaxy_collections(
self: Installer,
collections: list[Collection],
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,65 @@ def test_copy_using_ls(tmp_path: Path, output: Output) -> None:
installer._copy_repo_files(local_repo_path=source, destination_path=dest)
moved = dest.glob("**/*")
assert sorted([m.name for m in list(moved)]) == ["file1.txt", "file2.txt"]


def test_no_adt_install(
tmpdir: Path,
output: Output,
) -> None:
"""Test only core is installed.
Args:
tmpdir: A temporary directory.
output: The output fixture.
"""
venv = tmpdir / "test_venv"
args = Namespace(
venv=venv,
verbose=0,
adt=False,
system_site_packages=False,
collection_specifier=None,
requirement=None,
cpi=None,
)

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

installer = Installer(output=output, config=config)
installer.run()
assert venv.exists()
assert (venv / "bin" / "ansible").exists()
assert not (venv / "bin" / "adt").exists()


def test_adt_install(
tmpdir: Path,
output: Output,
) -> None:
"""Test adt is installed.
Args:
tmpdir: A temporary directory.
output: The output fixture.
"""
venv = tmpdir / "test_venv"
args = Namespace(
venv=venv,
verbose=0,
adt=True,
system_site_packages=False,
collection_specifier=None,
requirement=None,
cpi=None,
)

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

installer = Installer(output=output, config=config)
installer.run()
assert venv.exists()
assert (venv / "bin" / "ansible").exists()
assert (venv / "bin" / "adt").exists()

0 comments on commit a16081e

Please sign in to comment.