Skip to content

Commit 577a8d3

Browse files
committed
taking a stab...
1 parent 74a5b03 commit 577a8d3

File tree

7 files changed

+380
-40
lines changed

7 files changed

+380
-40
lines changed

dev.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# A script for running pyperformance out of the repo in dev-mode.
22

33
import os.path
4+
import shutil
5+
import subprocess
46
import sys
57

68
REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
@@ -29,20 +31,35 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
2931
readyfile = os.path.join(sys.prefix, "READY")
3032
isready = os.path.exists(readyfile)
3133
else:
32-
import venv
33-
3434
if not venvroot:
3535
venvroot = resolve_venv_root(kind, venvsdir)
3636
# Make sure the venv exists.
3737
readyfile = os.path.join(venvroot, "READY")
3838
isready = os.path.exists(readyfile)
3939
if not isready:
4040
relroot = os.path.relpath(venvroot)
41-
if not os.path.exists(venvroot):
42-
print(f"creating venv at {relroot}...")
41+
uv = shutil.which("uv")
42+
if not uv:
43+
sys.exit(
44+
"ERROR: uv executable not found. "
45+
"Install uv from https://astral.sh/uv and retry."
46+
)
47+
if os.path.exists(venvroot):
48+
print(f"uv env {relroot} not ready, re-creating...")
49+
shutil.rmtree(venvroot)
4350
else:
44-
print(f"venv {relroot} not ready, re-creating...")
45-
venv.create(venvroot, with_pip=True, clear=True)
51+
print(f"creating uv env at {relroot}...")
52+
result = subprocess.run(
53+
[
54+
uv,
55+
"venv",
56+
"--python",
57+
sys.executable,
58+
venvroot,
59+
]
60+
)
61+
if result.returncode != 0:
62+
sys.exit("ERROR: uv venv creation failed")
4663
else:
4764
assert os.path.exists(os.path.join(venvroot, "pyvenv.cfg"))
4865
# Return the venv's Python executable.
@@ -52,18 +69,31 @@ def ensure_venv_ready(venvroot=None, kind="dev", venvsdir=VENVS):
5269

5370
# Now make sure the venv has pyperformance installed.
5471
if not isready:
55-
import subprocess
56-
5772
relroot = os.path.relpath(venvroot)
58-
print(f"venv {relroot} not ready, installing dependencies...")
73+
print(f"uv env {relroot} not ready, installing dependencies...")
74+
uv = shutil.which("uv")
75+
if not uv:
76+
sys.exit(
77+
"ERROR: uv executable not found. "
78+
"Install uv from https://astral.sh/uv and retry."
79+
)
5980
proc = subprocess.run(
60-
[python, "-m", "pip", "install", "--upgrade", "--editable", REPO_ROOT],
81+
[
82+
uv,
83+
"pip",
84+
"install",
85+
"--python",
86+
python,
87+
"--upgrade",
88+
"--editable",
89+
f"{REPO_ROOT}[dev]",
90+
],
6191
)
6292
if proc.returncode != 0:
63-
sys.exit("ERROR: install failed")
93+
sys.exit("ERROR: uv pip install failed")
6494
with open(readyfile, "w"):
6595
pass
66-
print("...venv {relroot} ready!")
96+
print(f"...uv env {relroot} ready!")
6797

6898
return venvroot, python
6999

pyperformance/_venv.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import os.path
5+
import shutil
56
import sys
67
import types
78

@@ -111,11 +112,24 @@ def create_venv(
111112
):
112113
"""Create a new venv at the given root, optionally installing pip."""
113114
already_existed = os.path.exists(root)
114-
if withpip:
115-
args = ["-m", "venv", root]
115+
uv = shutil.which("uv")
116+
if not uv:
117+
print("ERROR: uv executable not found. Install uv from https://astral.sh/uv.")
118+
raise VenvCreationFailedError(root, 127, already_existed)
119+
120+
if isinstance(python, str) or python is None:
121+
target_python = python or sys.executable
116122
else:
117-
args = ["-m", "venv", "--without-pip", root]
118-
ec, _, _ = _utils.run_python(*args, python=python, env=env)
123+
try:
124+
target_python = python.sys.executable
125+
except AttributeError as exc:
126+
raise TypeError(f"expected python str, got {python!r}") from exc
127+
128+
argv = [uv, "venv"]
129+
if target_python:
130+
argv.extend(["--python", target_python])
131+
argv.append(root)
132+
ec, _, _ = _utils.run_cmd(argv, env=env)
119133
if ec != 0:
120134
if cleanonfail and not already_existed:
121135
_utils.safe_rmtree(root)

pyperformance/requirements/requirements.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.11
3-
# by the following command:
4-
#
5-
# pip-compile --output-file=pyperformance/requirements/requirements.txt requirements.in
6-
#
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile -o requirements.txt requirements.in
73
packaging==23.1
84
# via -r requirements.in
95
psutil==5.9.5

pyperformance/tests/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ def cleanup():
7575
def cleanup():
7676
return None
7777

78-
run_cmd(
79-
python or sys.executable,
80-
"-m",
81-
"venv",
82-
root,
83-
capture=not verbose,
84-
onfail="raise",
85-
verbose=verbose,
86-
)
87-
return root, _resolve_venv_python(root), cleanup
78+
uv = shutil.which("uv")
79+
if not uv:
80+
raise RuntimeError("uv executable is required to provision test environments")
81+
argv = [uv, "venv"]
82+
if python:
83+
argv.extend(["--python", python])
84+
argv.append(root)
85+
run_cmd(*argv, capture=not verbose, onfail="raise", verbose=verbose)
86+
venv_root = os.path.realpath(root)
87+
return venv_root, _resolve_venv_python(venv_root), cleanup
8888

8989

9090
class CleanupFile:

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Update dependencies:
22
#
3-
# - python3 -m pip install --user --upgrade pip-tools build
43
# - git clean -fdx # remove all untracked files!
5-
# - (pip-compile --upgrade -o requirements.txt requirements.in)
4+
# - uv pip compile --upgrade -o requirements.txt requirements.in
65
#
76
# Prepare a release:
87
#
@@ -28,8 +27,8 @@
2827
# - git tag VERSION
2928
# - git push --tags
3029
# - Remove untracked files/dirs: git clean -fdx
31-
# - python -m build
32-
# - twine upload dist/*
30+
# - uv run python -m build
31+
# - uvx twine upload dist/*
3332
#
3433
# After the release:
3534
#
@@ -65,8 +64,9 @@ classifiers = [
6564
]
6665
dynamic = [ "version" ]
6766
dependencies = [
68-
"packaging",
69-
"pyperf",
67+
"packaging==23.1",
68+
"psutil==5.9.5",
69+
"pyperf==2.9",
7070
"tomli; python_version<'3.11'",
7171
]
7272

requirements.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
pyperf
1313

1414
# for benchmark metadata:
15-
packaging
15+
packaging==23.1
1616
tomli; python_version < '3.11'
1717

1818

@@ -22,4 +22,4 @@ tomli; python_version < '3.11'
2222
# The list of optional dependencies is hardcoded in pyperformance/venv.py
2323

2424
# XXX Do we still need this?
25-
psutil
25+
psutil==5.9.5

0 commit comments

Comments
 (0)