7
7
from pathlib import Path
8
8
9
9
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 :
11
15
"""Run a UV command and return the result.
12
16
13
17
Args:
14
18
args: Command arguments to pass to UV
15
19
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
17
21
18
22
Returns:
19
23
CompletedProcess instance with command output
20
24
"""
21
- return subprocess .run (
25
+ result = subprocess .run (
22
26
["uv" , * args ],
23
27
capture_output = True ,
24
28
text = True ,
25
29
env = env ,
26
- check = check ,
30
+ check = False ,
27
31
)
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
28
39
29
40
30
41
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:
38
49
if with_pip :
39
50
args .append ("--seed" )
40
51
args .append (str (venv_path ))
41
- run_uv_command (args , check = True )
52
+ run_uv_command (args )
42
53
43
54
44
55
def install_package (venv_path : Path , pip_url : str ) -> None :
@@ -52,10 +63,14 @@ def install_package(venv_path: Path, pip_url: str) -> None:
52
63
run_uv_command (
53
64
["pip" , "install" , pip_url ],
54
65
env = venv_env ,
55
- check = True ,
56
66
)
57
67
58
68
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
+
59
74
def get_venv_env (venv_path : Path ) -> dict :
60
75
"""Get environment variables for a virtual environment.
61
76
@@ -67,7 +82,7 @@ def get_venv_env(venv_path: Path) -> dict:
67
82
"""
68
83
env = os .environ .copy ()
69
84
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' ]} "
71
86
return env
72
87
73
88
@@ -81,6 +96,5 @@ def get_executable_path(venv_path: Path, executable: str) -> Path:
81
96
Returns:
82
97
Path to the executable
83
98
"""
84
- bin_dir = "Scripts" if os .name == "nt" else "bin"
85
99
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