Skip to content

Commit 6944f07

Browse files
committed
switch from uv run python to sys.executable
To ensure that the same python interpreter is used to spawn pytask as is running the test we currently rely on `uv` to spawn the instance of python. This relies on us having spawned the test process from `uv` in the first place and requires that `uv` be used by anyone attempting to test the software. This switches the pattern `uv run python` to call (`sys.executable`)[https://docs.python.org/3/library/sys.html#sys.executable] which gives the absolute path of the interpreter being used.
1 parent 48d0286 commit 6944f07

6 files changed

Lines changed: 12 additions & 16 deletions

File tree

tests/test_capture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def task_show_capture():
8787
"""
8888
tmp_path.joinpath("workflow.py").write_text(textwrap.dedent(source))
8989

90-
result = run_in_subprocess(("uv", "run", "python", "workflow.py"), cwd=tmp_path)
90+
result = run_in_subprocess((sys.executable, "workflow.py"), cwd=tmp_path)
9191

9292
assert result.exit_code == ExitCode.FAILED
9393

@@ -128,7 +128,7 @@ def test_wrong_capture_method(tmp_path):
128128
"""
129129
tmp_path.joinpath("workflow.py").write_text(textwrap.dedent(source))
130130

131-
result = run_in_subprocess(("uv", "run", "python", "workflow.py"), cwd=tmp_path)
131+
result = run_in_subprocess((sys.executable, "workflow.py"), cwd=tmp_path)
132132
assert result.exit_code == ExitCode.CONFIGURATION_FAILED
133133
assert "Value 'a' is not a valid" in result.stdout
134134
assert "Traceback" not in result.stdout
@@ -255,7 +255,7 @@ def task_unicode():
255255
tmp_path.joinpath("workflow.py").write_text(
256256
textwrap.dedent(source), encoding="utf-8"
257257
)
258-
result = run_in_subprocess(("uv", "run", "python", "workflow.py"), cwd=tmp_path)
258+
result = run_in_subprocess((sys.executable, "workflow.py"), cwd=tmp_path)
259259
assert result.exit_code == ExitCode.OK
260260
assert "1 Succeeded" in result.stdout
261261

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_paths_are_relative_to_configuration_file(tmp_path):
114114
session = build(paths=[Path("src")])
115115
"""
116116
tmp_path.joinpath("script.py").write_text(textwrap.dedent(source))
117-
result = run_in_subprocess(("uv", "run", "python", "script.py"), cwd=tmp_path)
117+
result = run_in_subprocess((sys.executable, "script.py"), cwd=tmp_path)
118118
assert result.exit_code == ExitCode.OK
119119
assert "1 Succeeded" in result.stdout
120120

tests/test_dag_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def main():
9292
tmp_path.joinpath("input.txt").touch()
9393

9494
result = subprocess.run(
95-
("uv", "run", "python", "task_example.py"),
95+
(sys.executable, "task_example.py"),
9696
cwd=tmp_path,
9797
check=True,
9898
capture_output=True,

tests/test_execute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
def test_python_m_pytask(tmp_path):
2727
tmp_path.joinpath("task_module.py").write_text("def task_example(): pass")
2828
result = run_in_subprocess(
29-
("uv", "run", "python", "-m", "pytask", tmp_path.as_posix())
29+
(sys.executable, "-m", "pytask", tmp_path.as_posix())
3030
)
3131
assert result.exit_code == ExitCode.OK
3232

@@ -602,7 +602,7 @@ def create_file(
602602
"""
603603
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
604604
result = subprocess.run(
605-
("uv", "run", "python", tmp_path.joinpath("task_module.py").as_posix()),
605+
(sys.executable, tmp_path.joinpath("task_module.py").as_posix()),
606606
check=False,
607607
)
608608
assert result.returncode == ExitCode.OK
@@ -632,7 +632,7 @@ def task2() -> None: pass
632632
"""
633633
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
634634
result = run_in_subprocess(
635-
("uv", "run", "python", tmp_path.joinpath("task_module.py").as_posix())
635+
(sys.executable, tmp_path.joinpath("task_module.py").as_posix())
636636
)
637637
assert result.exit_code == ExitCode.OK
638638

tests/test_hook_module.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import subprocess
4+
import sys
45
import textwrap
56

67
import pytest
@@ -25,9 +26,7 @@ def pytask_extend_command_line_interface(cli):
2526

2627
if module_name:
2728
args = (
28-
"uv",
29-
"run",
30-
"python",
29+
sys.executable,
3130
"-m",
3231
"pytask",
3332
"build",
@@ -70,10 +69,7 @@ def pytask_extend_command_line_interface(cli):
7069

7170
if module_name:
7271
args = (
73-
"uv",
74-
"run",
75-
"--no-project",
76-
"python",
72+
sys.executable,
7773
"-m",
7874
"pytask",
7975
"build",

tests/test_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def task_second():
667667
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
668668

669669
result = subprocess.run(
670-
("uv", "run", "python", "task_example.py"),
670+
(sys.executable, "task_example.py"),
671671
cwd=tmp_path,
672672
capture_output=True,
673673
check=False,

0 commit comments

Comments
 (0)