Skip to content

Commit 50abdcc

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into staging
* upstream/develop: refactor: use uv optionally Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2 parents 9760391 + 24e45ba commit 50abdcc

File tree

5 files changed

+62
-20
lines changed

5 files changed

+62
-20
lines changed

bench/app.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ def install_resolved_apps(self, *args, **kwargs):
268268

269269
@step(title="Uninstalling App {repo}", success="App {repo} Uninstalled")
270270
def uninstall(self):
271-
self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.name}")
271+
if os.environ.get("BENCH_USE_UV"):
272+
self.bench.run(f"uv pip uninstall {self.name} --python {self.bench.python}")
273+
else:
274+
self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.name}")
272275

273276
def _get_dependencies(self):
274277
from bench.utils.app import get_required_deps, required_apps_from_hooks
@@ -921,9 +924,14 @@ def install_app(
921924
"PKG_CONFIG_PATH": get_mariadb_pkgconfig_path(),
922925
}
923926

924-
bench.run(
925-
f"{bench.python} -m pip install {quiet_flag} --upgrade -e {app_path} {cache_flag}", env=env
926-
)
927+
if os.environ.get("BENCH_USE_UV"):
928+
bench.run(
929+
f"uv pip install {quiet_flag} --upgrade -e {app_path} {cache_flag} --python {bench.python}", env=env
930+
)
931+
else:
932+
bench.run(
933+
f"{bench.python} -m pip install {quiet_flag} --upgrade -e {app_path} {cache_flag}", env=env
934+
)
927935

928936
if conf.get("developer_mode"):
929937
install_python_dev_dependencies(apps=app, bench_path=bench_path, verbose=verbose)

bench/bench.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ def reload(self, web=False, supervisor=True, systemd=True, _raise=True):
159159
def get_installed_apps(self) -> List:
160160
"""Returns list of installed apps on bench, not in excluded_apps.txt"""
161161
try:
162-
installed_packages = get_cmd_output(f"{self.python} -m pip freeze", cwd=self.name)
162+
if os.environ.get("BENCH_USE_UV"):
163+
installed_packages = get_cmd_output(f"uv pip freeze --python {self.python}", cwd=self.name)
164+
else:
165+
installed_packages = get_cmd_output(f"{self.python} -m pip freeze", cwd=self.name)
163166
except Exception:
164167
installed_packages = []
165168

@@ -361,8 +364,11 @@ def env(self, python="python3"):
361364
quiet_flag = "" if verbose else "--quiet"
362365

363366
if not os.path.exists(self.bench.python):
364-
venv = get_venv_path(verbose=verbose, python=python)
365-
self.run(f"{venv} env", cwd=self.bench.name)
367+
if os.environ.get("BENCH_USE_UV"):
368+
self.run("uv venv env", cwd=self.bench.name)
369+
else:
370+
venv = get_venv_path(verbose=verbose, python=python)
371+
self.run(f"{venv} env", cwd=self.bench.name)
366372

367373
self.pip()
368374
self.wheel()
@@ -379,10 +385,16 @@ def env(self, python="python3"):
379385
"PKG_CONFIG_PATH": get_mariadb_pkgconfig_path(),
380386
}
381387

382-
self.run(
383-
f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {frappe}",
384-
cwd=self.bench.name, env=env,
385-
)
388+
if os.environ.get("BENCH_USE_UV"):
389+
self.run(
390+
f"uv pip install {quiet_flag} --upgrade -e {frappe} --python {self.bench.python}",
391+
cwd=self.bench.name, env=env,
392+
)
393+
else:
394+
self.run(
395+
f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {frappe}",
396+
cwd=self.bench.name, env=env,
397+
)
386398

387399
@step(title="Setting Up Bench Config", success="Bench Config Set Up")
388400
def config(self, redis=True, procfile=True, additional_config=None):
@@ -503,7 +515,10 @@ def python(self, apps=None):
503515
"PKG_CONFIG_PATH": get_mariadb_pkgconfig_path(),
504516
}
505517

506-
self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {app_path}", env=env)
518+
if os.environ.get("BENCH_USE_UV"):
519+
self.run(f"uv pip install {quiet_flag} --upgrade -e {app_path} --python {self.bench.python}", env=env)
520+
else:
521+
self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {app_path}", env=env)
507522

508523
def node(self, apps=None):
509524
"""Install and upgrade Node dependencies for specified / all apps on given Bench"""

bench/commands/make.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,15 @@ def include_app_for_update(app_name):
248248
def pip(ctx, args):
249249
"Run pip commands in bench env"
250250
import os
251+
import shutil
251252

252253
from bench.utils.bench import get_env_cmd
253254

254-
env_py = get_env_cmd("python")
255-
os.execv(env_py, (env_py, "-m", "pip") + args)
255+
if os.environ.get("BENCH_USE_UV") and (env_uv := shutil.which("uv")):
256+
os.execv(env_uv, (env_uv, "pip") + args)
257+
else:
258+
env_py = get_env_cmd("python")
259+
os.execv(env_py, (env_py, "-m", "pip") + args)
256260

257261

258262
@click.command(

bench/utils/bench.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,20 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):
9999
if os.path.exists(pyproject_path):
100100
pyproject_deps = _generate_dev_deps_pattern(pyproject_path)
101101
if pyproject_deps:
102-
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade {pyproject_deps}")
102+
if os.environ.get("BENCH_USE_UV"):
103+
bench.run(f"uv pip install {quiet_flag} --upgrade {pyproject_deps} --python {bench.python}")
104+
else:
105+
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade {pyproject_deps}")
103106

104107
if not pyproject_deps and os.path.exists(dev_requirements_path):
105-
bench.run(
106-
f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}"
107-
)
108+
if os.environ.get("BENCH_USE_UV"):
109+
bench.run(
110+
f"uv pip install {quiet_flag} --upgrade -r {dev_requirements_path} --python {bench.python}"
111+
)
112+
else:
113+
bench.run(
114+
f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}"
115+
)
108116

109117

110118
def _generate_dev_deps_pattern(pyproject_path):
@@ -240,11 +248,17 @@ def migrate_env(python, backup=False):
240248
# Create virtualenv using specified python
241249
def _install_app(app):
242250
app_path = f"-e {os.path.join('apps', app)}"
243-
exec_cmd(f"{pvenv}/bin/python -m pip install --upgrade {app_path}")
251+
if os.environ.get("BENCH_USE_UV"):
252+
exec_cmd(f"uv pip install --upgrade {app_path} --python {pyenv}/bin/python")
253+
else:
254+
exec_cmd(f"{pyenv}/bin/python -m pip install --upgrade {app_path}")
244255

245256
try:
246257
logger.log(f"Setting up a New Virtual {python} Environment")
247-
exec_cmd(f"{python} -m venv {pvenv}")
258+
if os.environ.get("BENCH_USE_UV"):
259+
exec_cmd(f"uv venv {pvenv}")
260+
else:
261+
exec_cmd(f"{python} -m venv {pvenv}")
248262

249263
# Install frappe first
250264
_install_app("frappe")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies = [
2828
"semantic-version~=2.10.0",
2929
"setuptools>=71.0.0",
3030
"tomli;python_version<'3.11'",
31+
"uv~=0.7.12"
3132
]
3233
dynamic = [
3334
"version",

0 commit comments

Comments
 (0)