Skip to content

Commit aaf4c6d

Browse files
committed
Add ansible-dev-tools install into venv
1 parent 6db8cd3 commit aaf4c6d

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

src/ansible_dev_environment/arg_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def parse() -> argparse.Namespace:
181181
help="Install editable.",
182182
)
183183

184+
install.add_argument(
185+
"-adt",
186+
"--ansible-dev-tools",
187+
action="store_true",
188+
dest="adt",
189+
help="Install ansible-dev-tools in the virtual environment.",
190+
)
191+
184192
_uninstall = subparsers.add_parser(
185193
"uninstall",
186194
formatter_class=CustomHelpFormatter,

src/ansible_dev_environment/subcommands/installer.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def run(self: Installer) -> None:
5151
err = "Multiple optional dependencies are not supported at this time."
5252
self._output.critical(err)
5353

54-
self._install_core()
54+
if self._config.args.adt:
55+
self._install_dev_tools()
56+
else:
57+
self._install_core()
58+
5559
if self._config.args.requirement or self._config.args.cpi:
5660
self._install_galaxy_requirements()
5761
if self._config.args.collection_specifier:
@@ -116,6 +120,28 @@ def _install_core(self: Installer) -> None:
116120
err = f"Failed to install ansible-core: {exc}"
117121
self._output.critical(err)
118122

123+
def _install_dev_tools(self: Installer) -> None:
124+
"""Install ansible developer tools."""
125+
msg = "Installing ansible-dev-tools."
126+
self._output.info(msg)
127+
128+
adt = self._config.venv_bindir / "adt"
129+
if adt.exists():
130+
return
131+
msg = "Installing ansible-dev-tools."
132+
self._output.debug(msg)
133+
command = f"{self._config.venv_interpreter} -m pip install ansible-dev-tools"
134+
try:
135+
subprocess_run(
136+
command=command,
137+
verbose=self._config.args.verbose,
138+
msg=msg,
139+
output=self._output,
140+
)
141+
except subprocess.CalledProcessError as exc:
142+
err = f"Failed to install ansible-dev-tools: {exc}"
143+
self._output.critical(err)
144+
119145
def _install_galaxy_collections(
120146
self: Installer,
121147
collections: list[Collection],

tests/unit/test_installer.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,65 @@ def test_copy_using_ls(tmp_path: Path, output: Output) -> None:
155155
installer._copy_repo_files(local_repo_path=source, destination_path=dest)
156156
moved = dest.glob("**/*")
157157
assert sorted([m.name for m in list(moved)]) == ["file1.txt", "file2.txt"]
158+
159+
160+
def test_no_adt_install(
161+
tmpdir: Path,
162+
output: Output,
163+
) -> None:
164+
"""Test only core is installed.
165+
166+
Args:
167+
tmpdir: A temporary directory.
168+
output: The output fixture.
169+
"""
170+
venv = tmpdir / "test_venv"
171+
args = Namespace(
172+
venv=venv,
173+
verbose=0,
174+
adt=False,
175+
system_site_packages=False,
176+
collection_specifier=None,
177+
requirement=None,
178+
cpi=None,
179+
)
180+
181+
config = Config(args=args, output=output, term_features=output.term_features)
182+
config.init()
183+
184+
installer = Installer(output=output, config=config)
185+
installer.run()
186+
assert venv.exists()
187+
assert (venv / "bin" / "ansible").exists()
188+
assert not (venv / "bin" / "adt").exists()
189+
190+
191+
def test_adt_install(
192+
tmpdir: Path,
193+
output: Output,
194+
) -> None:
195+
"""Test adt is installed.
196+
197+
Args:
198+
tmpdir: A temporary directory.
199+
output: The output fixture.
200+
"""
201+
venv = tmpdir / "test_venv"
202+
args = Namespace(
203+
venv=venv,
204+
verbose=0,
205+
adt=True,
206+
system_site_packages=False,
207+
collection_specifier=None,
208+
requirement=None,
209+
cpi=None,
210+
)
211+
212+
config = Config(args=args, output=output, term_features=output.term_features)
213+
config.init()
214+
215+
installer = Installer(output=output, config=config)
216+
installer.run()
217+
assert venv.exists()
218+
assert (venv / "bin" / "ansible").exists()
219+
assert (venv / "bin" / "adt").exists()

0 commit comments

Comments
 (0)