Skip to content

Commit b6c6981

Browse files
authored
2-4x installation speedup using uv
1 parent 145ac98 commit b6c6981

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

src/setup_windows.py

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ def manual_installation_confirmation():
6161
if not manual_installation_confirmation():
6262
sys.exit(1)
6363

64+
start_time = time.time()
65+
66+
subprocess.run([sys.executable, "-m", "pip", "install", "uv==0.2.32"], check=True)
67+
print("\033[92mInstalled uv package manager.\033[0m")
68+
6469
def upgrade_pip_setuptools_wheel(max_retries=5, delay=3):
6570
upgrade_commands = [
66-
[sys.executable, "-m", "pip", "install", "--upgrade", "pip", "--no-cache-dir"],
67-
[sys.executable, "-m", "pip", "install", "--upgrade", "setuptools", "--no-cache-dir"],
68-
[sys.executable, "-m", "pip", "install", "--upgrade", "wheel", "--no-cache-dir"]
71+
[sys.executable, "-m", "uv", "pip", "install", "--upgrade", "pip", "--no-cache-dir"],
72+
[sys.executable, "-m", "uv", "pip", "install", "--upgrade", "setuptools", "--no-cache-dir"],
73+
[sys.executable, "-m", "uv", "pip", "install", "--upgrade", "wheel", "--no-cache-dir"]
6974
]
7075

7176
for command in upgrade_commands:
@@ -93,28 +98,33 @@ def upgrade_pip_setuptools_wheel(max_retries=5, delay=3):
9398

9499
def pip_install_with_retry(library, max_retries=5, delay=3):
95100
if library.startswith("torch=="):
96-
pip_args = ["pip", "install", "torch==2.2.2", "torchvision==0.17.2", "torchaudio==2.2.2",
97-
"--index-url", "https://download.pytorch.org/whl/cu121", "--no-deps"]
101+
pip_args_list = [
102+
["uv", "pip", "install", "https://download.pytorch.org/whl/cu121/torch-2.2.2%2Bcu121-cp311-cp311-win_amd64.whl#sha256=efbcfdd4399197d06b32f7c0e1711c615188cdd65427b933648c7478fb880b3f"],
103+
["uv", "pip", "install", "https://download.pytorch.org/whl/cu121/torchvision-0.17.2%2Bcu121-cp311-cp311-win_amd64.whl#sha256=10ad542aab6b47dbe73c441381986d50a7ed5021cbe01d593a14477ec1f067a0"],
104+
["uv", "pip", "install", "https://download.pytorch.org/whl/cu121/torchaudio-2.2.2%2Bcu121-cp311-cp311-win_amd64.whl#sha256=c7dee68cd3d2b889bab71d4a0c345bdc3ea2fe79a62b921a6b49292c605b6071"]
105+
]
98106
elif "@" in library or "git+" in library:
99-
pip_args = ["pip", "install", library, "--no-deps"]
107+
pip_args_list = [["uv", "pip", "install", library, "--no-deps"]]
100108
else:
101-
pip_args = ["pip", "install", library, "--no-deps"]
102-
103-
for attempt in range(max_retries):
104-
try:
105-
print(f"\nAttempt {attempt + 1} of {max_retries}: Installing {library}")
106-
print(f"Running command: {' '.join(pip_args)}")
107-
result = subprocess.run(pip_args, check=True, capture_output=True, text=True, timeout=180)
108-
print(f"Successfully installed {library}")
109-
return attempt + 1
110-
except subprocess.CalledProcessError as e:
111-
print(f"Attempt {attempt + 1} failed. Error: {e.stderr.strip()}")
112-
if attempt < max_retries - 1:
113-
print(f"Retrying in {delay} seconds...")
114-
time.sleep(delay)
115-
else:
116-
print(f"Failed to install {library} after {max_retries} attempts.")
117-
return 0
109+
pip_args_list = [["uv", "pip", "install", library, "--no-deps"]]
110+
111+
for pip_args in pip_args_list:
112+
for attempt in range(max_retries):
113+
try:
114+
print(f"\nAttempt {attempt + 1} of {max_retries}: Installing {pip_args[3]}")
115+
print(f"Running command: {' '.join(pip_args)}")
116+
result = subprocess.run(pip_args, check=True, capture_output=True, text=True, timeout=180)
117+
print(f"Successfully installed {pip_args[3]}")
118+
break
119+
except subprocess.CalledProcessError as e:
120+
print(f"Attempt {attempt + 1} failed. Error: {e.stderr.strip()}")
121+
if attempt < max_retries - 1:
122+
print(f"Retrying in {delay} seconds...")
123+
time.sleep(delay)
124+
else:
125+
print(f"Failed to install {pip_args[3]} after {max_retries} attempts.")
126+
return 0
127+
return 1
118128

119129
def install_libraries(libraries):
120130
failed_installations = []
@@ -294,7 +304,7 @@ def install_libraries(libraries):
294304
]
295305

296306
def pip_install_with_deps(library, max_retries=5, delay=3):
297-
pip_args = ["pip", "install", library]
307+
pip_args = ["uv", "pip", "install", library]
298308

299309
for attempt in range(max_retries):
300310
try:
@@ -363,4 +373,11 @@ def install_libraries_with_deps(libraries):
363373

364374
replace_pdf_file()
365375
replace_instructor_file()
366-
replace_sentence_transformer_file()
376+
replace_sentence_transformer_file()
377+
378+
end_time = time.time()
379+
total_time = end_time - start_time
380+
hours, rem = divmod(total_time, 3600)
381+
minutes, seconds = divmod(rem, 60)
382+
383+
print(f"\033[92m\nTotal installation time: {int(hours):02d}:{int(minutes):02d}:{seconds:05.2f}\033[0m")

0 commit comments

Comments
 (0)