Skip to content

Commit 24978f6

Browse files
committed
feat: execute uv lock before packing
1 parent 0b0d72c commit 24978f6

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

src/uipath/_cli/cli_pack.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# type: ignore
22
import json
33
import os
4+
import subprocess
5+
import sys
46
import uuid
57
import zipfile
68
from string import Template
@@ -52,6 +54,80 @@ def check_config(directory):
5254
}
5355

5456

57+
def is_uv_available():
58+
"""Check if uv command is available in the system."""
59+
try:
60+
subprocess.run(["uv", "--version"], capture_output=True, check=True)
61+
return True
62+
except (subprocess.CalledProcessError, FileNotFoundError):
63+
return False
64+
65+
66+
def is_uv_project(directory):
67+
"""Check if this is a uv project by looking for the uv.lock file."""
68+
uv_lock_path = os.path.join(directory, "uv.lock")
69+
70+
# If uv.lock exists, it's definitely a uv project
71+
if os.path.exists(uv_lock_path):
72+
return True
73+
74+
return False
75+
76+
77+
def is_in_virtual_env():
78+
"""Check if we're currently running in a virtual environment."""
79+
return (
80+
hasattr(sys, "real_prefix")
81+
or (hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix)
82+
or os.environ.get("VIRTUAL_ENV") is not None
83+
)
84+
85+
86+
def run_uv_sync(directory):
87+
"""Run uv sync in the specified directory."""
88+
try:
89+
subprocess.run(
90+
["uv", "sync"], cwd=directory, capture_output=True, text=True, check=True
91+
)
92+
return True
93+
except subprocess.CalledProcessError as e:
94+
console.warning(f"uv sync failed: {e.stderr}")
95+
return False
96+
except FileNotFoundError:
97+
console.warning("uv command not found. Skipping dependency sync.")
98+
return False
99+
100+
101+
def run_uv_lock(directory):
102+
"""Run uv lock to update the lock file."""
103+
try:
104+
subprocess.run(
105+
["uv", "lock"], cwd=directory, capture_output=True, text=True, check=True
106+
)
107+
return True
108+
except subprocess.CalledProcessError as e:
109+
console.warning(f"uv lock failed: {e.stderr}")
110+
return False
111+
except FileNotFoundError:
112+
console.warning("uv command not found. Skipping lock file update.")
113+
return False
114+
115+
116+
def handle_uv_operations(directory):
117+
"""Handle uv operations if uv is detected and available."""
118+
if not is_uv_available():
119+
return
120+
121+
if not is_uv_project(directory):
122+
return
123+
124+
# If we're in a virtual environment
125+
if is_in_virtual_env():
126+
run_uv_sync(directory)
127+
# Always run uv lock to ensure lock file is up to date
128+
run_uv_lock(directory)
129+
130+
55131
def generate_operate_file(entryPoints):
56132
project_id = str(uuid.uuid4())
57133

@@ -403,6 +479,10 @@ def pack(root):
403479

404480
with console.spinner("Packaging project ..."):
405481
try:
482+
# Handle uv operations before packaging
483+
# Makes sure uv.lock is up to date
484+
handle_uv_operations(root)
485+
406486
pack_fn(
407487
config["project_name"],
408488
config["description"],

0 commit comments

Comments
 (0)