Skip to content

Commit 3ae8fd4

Browse files
authored
clean up uv util
1 parent 7b764ba commit 3ae8fd4

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

airbyte/_util/uv_util.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,35 @@
77
from pathlib import Path
88

99

10-
def run_uv_command(args: list[str], env: dict | None = None, check: bool = False) -> subprocess.CompletedProcess:
10+
def run_uv_command(
11+
args: list[str],
12+
env: dict | None = None,
13+
raise_on_error: bool = True,
14+
) -> subprocess.CompletedProcess:
1115
"""Run a UV command and return the result.
1216
1317
Args:
1418
args: Command arguments to pass to UV
1519
env: Optional environment variables
16-
check: Whether to raise an exception on non-zero return code
20+
raise_on_error: Whether to raise an exception on non-zero return code
1721
1822
Returns:
1923
CompletedProcess instance with command output
2024
"""
21-
return subprocess.run(
25+
result = subprocess.run(
2226
["uv", *args],
2327
capture_output=True,
2428
text=True,
2529
env=env,
26-
check=check,
30+
check=False,
2731
)
32+
if raise_on_error and result.returncode != 0:
33+
raise exc.AirbyteSubprocessFailedError(
34+
run_args=args,
35+
exit_code=result.returncode,
36+
log_text=result.stderr.decode("utf-8"),
37+
)
38+
return result
2839

2940

3041
def create_venv(venv_path: Path, with_pip: bool = True) -> None:
@@ -38,7 +49,7 @@ def create_venv(venv_path: Path, with_pip: bool = True) -> None:
3849
if with_pip:
3950
args.append("--seed")
4051
args.append(str(venv_path))
41-
run_uv_command(args, check=True)
52+
run_uv_command(args)
4253

4354

4455
def install_package(venv_path: Path, pip_url: str) -> None:
@@ -52,10 +63,14 @@ def install_package(venv_path: Path, pip_url: str) -> None:
5263
run_uv_command(
5364
["pip", "install", pip_url],
5465
env=venv_env,
55-
check=True,
5666
)
5767

5868

69+
def get_venv_bin_path(venv_path: Path) -> Path:
70+
"""Get the path of the executable 'bin' folder for a virtual env."""
71+
return venv_path / ("Scripts" if os.name == "nt" else "bin")
72+
73+
5974
def get_venv_env(venv_path: Path) -> dict:
6075
"""Get environment variables for a virtual environment.
6176
@@ -67,7 +82,7 @@ def get_venv_env(venv_path: Path) -> dict:
6782
"""
6883
env = os.environ.copy()
6984
env["VIRTUAL_ENV"] = str(venv_path)
70-
env["PATH"] = f"{venv_path}/bin:{os.environ['PATH']}"
85+
env["PATH"] = f"{get_venv_bin_path(venv_path)}:{os.environ['PATH']}"
7186
return env
7287

7388

@@ -81,6 +96,5 @@ def get_executable_path(venv_path: Path, executable: str) -> Path:
8196
Returns:
8297
Path to the executable
8398
"""
84-
bin_dir = "Scripts" if os.name == "nt" else "bin"
8599
suffix = ".exe" if os.name == "nt" else ""
86-
return venv_path / bin_dir / f"{executable}{suffix}"
100+
return get_venv_bin_path(venv_path) / f"{executable}{suffix}"

0 commit comments

Comments
 (0)