Skip to content

Commit 8dfd9cc

Browse files
committed
Add uv to runtime, modify scratch install
1 parent cc34056 commit 8dfd9cc

3 files changed

Lines changed: 15 additions & 28 deletions

File tree

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-ins
4444
libnss-ldapd \
4545
&& apt-get dist-clean
4646

47+
# Install uv to allow setup-scratch to run
48+
COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /uvx /bin/
49+
4750
# For this pod to understand finding user information from LDAP
4851
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
4952

src/blueapi/cli/scratch.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def setup_scratch(
4747
for repo in config.repositories:
4848
local_directory = config.root / repo.name
4949
ensure_repo(repo.remote_url, local_directory)
50-
scratch_install(local_directory, timeout=install_timeout)
50+
scratch_install(repo.name, local_directory, timeout=install_timeout)
5151

5252

5353
def ensure_repo(remote_url: str, local_directory: Path) -> None:
@@ -76,7 +76,9 @@ def ensure_repo(remote_url: str, local_directory: Path) -> None:
7676
)
7777

7878

79-
def scratch_install(path: Path, timeout: float = _DEFAULT_INSTALL_TIMEOUT) -> None:
79+
def scratch_install(
80+
name: str, path: Path, timeout: float = _DEFAULT_INSTALL_TIMEOUT
81+
) -> None:
8082
"""
8183
Install a scratch package. Make blueapi aware of a repository checked out in
8284
the scratch area. Make it automatically follow code changes to that repository
@@ -91,17 +93,7 @@ def scratch_install(path: Path, timeout: float = _DEFAULT_INSTALL_TIMEOUT) -> No
9193
_validate_directory(path)
9294

9395
logging.info(f"Installing {path}")
94-
process = Popen(
95-
[
96-
"python",
97-
"-m",
98-
"pip",
99-
"install",
100-
"--no-deps",
101-
"-e",
102-
str(path),
103-
]
104-
)
96+
process = Popen(["uv", "add", "--locked", "--editable", f"{name} @ {path}"])
10597
process.wait(timeout=timeout)
10698
if process.returncode != 0:
10799
raise RuntimeError(f"Failed to install {path}: Exit Code: {process.returncode}")

tests/unit_tests/cli/test_scratch.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,21 @@ def test_scratch_install_installs_path(
6262
mock_process.returncode = 0
6363
mock_popen.return_value = mock_process
6464

65-
scratch_install(directory_path_with_sgid, timeout=1.0)
65+
scratch_install("foo", directory_path_with_sgid, timeout=1.0)
6666

6767
mock_popen.assert_called_once_with(
68-
[
69-
"python",
70-
"-m",
71-
"pip",
72-
"install",
73-
"--no-deps",
74-
"-e",
75-
str(directory_path_with_sgid),
76-
]
68+
["uv", "add", "--locked", "--editable", f"foo @ {directory_path_with_sgid}"]
7769
)
7870

7971

8072
def test_scratch_install_fails_on_file(file_path: Path):
8173
with pytest.raises(KeyError):
82-
scratch_install(file_path, timeout=1.0)
74+
scratch_install("foo", file_path, timeout=1.0)
8375

8476

8577
def test_scratch_install_fails_on_nonexistant_path(nonexistant_path: Path):
8678
with pytest.raises(KeyError):
87-
scratch_install(nonexistant_path, timeout=1.0)
79+
scratch_install("foo", nonexistant_path, timeout=1.0)
8880

8981

9082
@patch("blueapi.cli.scratch.Popen")
@@ -99,7 +91,7 @@ def test_scratch_install_fails_on_non_zero_exit_code(
9991
mock_popen.return_value = mock_process
10092

10193
with pytest.raises(RuntimeError):
102-
scratch_install(directory_path_with_sgid, timeout=1.0)
94+
scratch_install("foo", directory_path_with_sgid, timeout=1.0)
10395

10496

10597
@patch("blueapi.cli.scratch.Repo")
@@ -270,8 +262,8 @@ def test_setup_scratch_iterates_repos(
270262

271263
mock_scratch_install.assert_has_calls(
272264
[
273-
call(directory_path_with_sgid / "foo", timeout=120.0),
274-
call(directory_path_with_sgid / "bar", timeout=120.0),
265+
call("foo", directory_path_with_sgid / "foo", timeout=120.0),
266+
call("bar", directory_path_with_sgid / "bar", timeout=120.0),
275267
]
276268
)
277269

0 commit comments

Comments
 (0)