Skip to content

Commit ff385f6

Browse files
authored
Rename Runtime.exec to Runtime.run (#256)
1 parent 26f70be commit ff385f6

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ ignore = [
124124
"E501", # we use black
125125
"RET504", # Unnecessary variable assignment before `return` statement
126126
# Temporary disabled during adoption:
127-
"A003", # Class attribute `exec` is shadowing a python builtin
128127
"S607", # Starting a process with a partial executable path
129128

130129
]

src/ansible_compat/runtime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def clean(self) -> None:
175175
if self.cache_dir:
176176
shutil.rmtree(self.cache_dir, ignore_errors=True)
177177

178-
def exec(
178+
def run(
179179
self,
180180
args: Union[str, list[str]],
181181
*,
@@ -225,7 +225,7 @@ def version(self) -> packaging.version.Version:
225225
if self._version:
226226
return self._version
227227

228-
proc = self.exec(["ansible", "--version"])
228+
proc = self.run(["ansible", "--version"])
229229
if proc.returncode == 0:
230230
self._version = parse_ansible_version(proc.stdout)
231231
return self._version
@@ -284,7 +284,7 @@ def install_collection(
284284
cmd.append(f"{collection}")
285285

286286
_logger.info("Running from %s : %s", Path.cwd(), " ".join(cmd))
287-
run = self.exec(
287+
run = self.run(
288288
cmd,
289289
retry=True,
290290
env={**self.environ, ansible_collections_path(): ":".join(cpaths)},
@@ -314,7 +314,7 @@ def install_collection_from_disk(
314314
str(path),
315315
]
316316
_logger.info("Running %s", " ".join(cmd))
317-
run = self.exec(cmd, retry=False)
317+
run = self.run(cmd, retry=False)
318318
if run.returncode != 0:
319319
_logger.error(run.stdout)
320320
raise AnsibleCommandError(run)
@@ -364,7 +364,7 @@ def install_requirements( # noqa: C901,PLR0912
364364
else:
365365
_logger.info("Running %s", " ".join(cmd))
366366

367-
result = self.exec(cmd, retry=retry)
367+
result = self.run(cmd, retry=retry)
368368
if result.returncode != 0:
369369
_logger.error(result.stdout)
370370
raise AnsibleCommandError(result)
@@ -392,7 +392,7 @@ def install_requirements( # noqa: C901,PLR0912
392392
# pylint: disable=no-member
393393
cpaths.insert(0, dest_path)
394394
_logger.info("Running %s", " ".join(cmd))
395-
result = self.exec(
395+
result = self.run(
396396
cmd,
397397
retry=retry,
398398
env={**os.environ, "ANSIBLE_COLLECTIONS_PATH": ":".join(cpaths)},

test/test_runtime.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_runtime_version_fail_module(mocker: MockerFixture) -> None:
105105
def test_runtime_version_fail_cli(mocker: MockerFixture) -> None:
106106
"""Tests for failure to detect Ansible version."""
107107
mocker.patch(
108-
"ansible_compat.runtime.Runtime.exec",
108+
"ansible_compat.runtime.Runtime.run",
109109
return_value=CompletedProcess(
110110
["x"],
111111
returncode=123,
@@ -152,7 +152,7 @@ def test_runtime_install_role(
152152
runtime = Runtime(isolated=isolated, project_dir=project_dir)
153153
runtime.prepare_environment(install_local=True)
154154
# check that role appears as installed now
155-
result = runtime.exec(["ansible-galaxy", "list"])
155+
result = runtime.run(["ansible-galaxy", "list"])
156156
assert result.returncode == 0, result
157157
assert role_name in result.stdout
158158
if isolated:
@@ -573,7 +573,7 @@ def test_install_galaxy_role_no_checks(runtime_tmp: Runtime) -> None:
573573
""",
574574
)
575575
runtime_tmp._install_galaxy_role(runtime_tmp.project_dir, role_name_check=2)
576-
result = runtime_tmp.exec(["ansible-galaxy", "list"])
576+
result = runtime_tmp.run(["ansible-galaxy", "list"])
577577
assert "- acme.foo," in result.stdout
578578
assert result.returncode == 0, result
579579

@@ -658,7 +658,7 @@ def test_install_collection_from_disk(path: str, scenario: str) -> None:
658658
runtime.prepare_environment(install_local=True)
659659
# that molecule converge playbook can be used without molecule and
660660
# should validate that the installed collection is available.
661-
result = runtime.exec(["ansible-playbook", f"molecule/{scenario}/converge.yml"])
661+
result = runtime.run(["ansible-playbook", f"molecule/{scenario}/converge.yml"])
662662
assert result.returncode == 0, result.stdout
663663
runtime.clean()
664664

@@ -691,8 +691,8 @@ def test_prepare_environment_offline_role() -> None:
691691

692692
def test_runtime_run(runtime: Runtime) -> None:
693693
"""Check if tee and non tee mode return same kind of results."""
694-
result1 = runtime.exec(["seq", "10"])
695-
result2 = runtime.exec(["seq", "10"], tee=True)
694+
result1 = runtime.run(["seq", "10"])
695+
result2 = runtime.run(["seq", "10"], tee=True)
696696
assert result1.returncode == result2.returncode
697697
assert result1.stderr == result2.stderr
698698
assert result1.stdout == result2.stdout
@@ -701,20 +701,20 @@ def test_runtime_run(runtime: Runtime) -> None:
701701
def test_runtime_exec_cwd(runtime: Runtime) -> None:
702702
"""Check if passing cwd works as expected."""
703703
path = Path("/")
704-
result1 = runtime.exec(["pwd"], cwd=path)
705-
result2 = runtime.exec(["pwd"])
704+
result1 = runtime.run(["pwd"], cwd=path)
705+
result2 = runtime.run(["pwd"])
706706
assert result1.stdout.rstrip() == str(path)
707707
assert result1.stdout != result2.stdout
708708

709709

710710
def test_runtime_exec_env(runtime: Runtime) -> None:
711711
"""Check if passing env works."""
712-
result = runtime.exec(["printenv", "FOO"])
712+
result = runtime.run(["printenv", "FOO"])
713713
assert not result.stdout
714714

715-
result = runtime.exec(["printenv", "FOO"], env={"FOO": "bar"})
715+
result = runtime.run(["printenv", "FOO"], env={"FOO": "bar"})
716716
assert result.stdout.rstrip() == "bar"
717717

718718
runtime.environ["FOO"] = "bar"
719-
result = runtime.exec(["printenv", "FOO"])
719+
result = runtime.run(["printenv", "FOO"])
720720
assert result.stdout.rstrip() == "bar"

test/test_runtime_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def test_runtime_example() -> None:
2020
runtime.install_collection("examples/reqs_v2/community-molecule-0.1.0.tar.gz")
2121

2222
# Execute a command
23-
result = runtime.exec(["ansible-doc", "--list"])
23+
result = runtime.run(["ansible-doc", "--list"])
2424
assert result.returncode == 0

0 commit comments

Comments
 (0)