Use uv in check_requirements (#18116)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Ultralytics Assistant <135830346+UltralyticsAssistant@users.noreply.github.com>
This commit is contained in:
parent
925d739beb
commit
d8ca2231c4
@ -388,21 +388,28 @@ def check_requirements(requirements=ROOT.parent / "requirements.txt", exclude=()
|
||||
pkgs.append(r)
|
||||
|
||||
@Retry(times=2, delay=1)
|
||||
def attempt_install(packages, commands):
|
||||
"""Attempt pip install command with retries on failure."""
|
||||
return subprocess.check_output(f"pip install --no-cache-dir {packages} {commands}", shell=True).decode()
|
||||
def attempt_install(packages, commands, use_uv):
|
||||
"""Attempt package installation with uv if available, falling back to pip."""
|
||||
if use_uv:
|
||||
# Note requires --break-system-packages on ARM64 dockerfile
|
||||
cmd = f"uv pip install --system --no-cache-dir {packages} {commands} --index-strategy=unsafe-best-match --break-system-packages --prerelease=allow"
|
||||
else:
|
||||
cmd = f"pip install --no-cache-dir {packages} {commands}"
|
||||
return subprocess.check_output(cmd, shell=True).decode()
|
||||
|
||||
s = " ".join(f'"{x}"' for x in pkgs) # console string
|
||||
if s:
|
||||
if install and AUTOINSTALL: # check environment variable
|
||||
# Note uv fails on arm64 macOS and Raspberry Pi runners
|
||||
uv = not ARM64 and subprocess.run(["command", "-v", "uv"], capture_output=True, shell=True).returncode == 0
|
||||
n = len(pkgs) # number of packages updates
|
||||
LOGGER.info(f"{prefix} Ultralytics requirement{'s' * (n > 1)} {pkgs} not found, attempting AutoUpdate...")
|
||||
try:
|
||||
t = time.time()
|
||||
assert ONLINE, "AutoUpdate skipped (offline)"
|
||||
LOGGER.info(attempt_install(s, cmds))
|
||||
LOGGER.info(attempt_install(s, cmds, use_uv=uv))
|
||||
dt = time.time() - t
|
||||
LOGGER.info(f"{prefix} AutoUpdate success ✅ {dt:.1f}s, installed {n} package{'s' * (n > 1)}: {pkgs}")
|
||||
LOGGER.info(f"{prefix} AutoUpdate success ✅ {dt:.1f}s")
|
||||
LOGGER.warning(
|
||||
f"{prefix} {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user