From 0cd8571435baec7c1206be6dcfb4f2e960e8caf2 Mon Sep 17 00:00:00 2001 From: Taylor Steinberg Date: Mon, 23 Nov 2026 13:24:12 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20use=20the=20server=E2=80=99s=20default?= =?UTF-8?q?=20installer=20for=20uv.lock=20bundles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsconnect/subprocesses/inspect_environment.py | 3 +- tests/test_environment.py | 6 +-- tests/test_package_installer.py | 48 +++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/rsconnect/subprocesses/inspect_environment.py b/rsconnect/subprocesses/inspect_environment.py index c3a1685a..1c531f21 100644 --- a/rsconnect/subprocesses/inspect_environment.py +++ b/rsconnect/subprocesses/inspect_environment.py @@ -315,8 +315,7 @@ def uv_export(dirname: str, lock_filename: str, uv_path: str = "uv"): "filename": "requirements.txt.lock", "contents": requirements, "source": "uv_lock", - "package_manager": "uv", - "pip": None, + "package_manager": "pip", } diff --git a/tests/test_environment.py b/tests/test_environment.py index f2c7bc1a..0f772073 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -424,10 +424,7 @@ def test_uv_lock_export(tmp_path, monkeypatch, fallback, lock_location): encoding="utf-8", ) - from rsconnect.bundle import Manifest - uv_path = uv.find_uv_bin() - expected_uv_version = subprocess.check_output([uv_path, "--version"], text=True).split()[1] env_dir = project_dir / ".venv" subprocess.run([uv_path, "venv", "--python", sys.executable, str(env_dir)], check=True) python = env_dir / ("Scripts/python.exe" if os.name == "nt" else "bin/python") @@ -450,9 +447,8 @@ def test_uv_lock_export(tmp_path, monkeypatch, fallback, lock_location): assert "annotated-doc==0.0.4" in env.contents assert "annotated-types==0.7.0" in env.contents assert env.source == "uv_lock" - assert env.package_manager == "uv" + assert env.package_manager == "pip" assert env.pip is None - assert Manifest(environment=env).data["python"]["package_manager"]["version"] == expected_uv_version @pytest.mark.parametrize("default_groups", ["", '[tool.uv]\ndefault-groups = ["dev", "lint"]\n']) diff --git a/tests/test_package_installer.py b/tests/test_package_installer.py index 6a6c6e15..f2a7fe04 100644 --- a/tests/test_package_installer.py +++ b/tests/test_package_installer.py @@ -1,5 +1,8 @@ import json import pathlib +import subprocess +import sys +import tarfile import typing from unittest import mock @@ -46,6 +49,51 @@ def test_write_manifest_framework_passes_package_installer(tmp_path: pathlib.Pat assert package_manager["allow_uv"] is (installer == "uv") +@pytest.mark.parametrize("command", ["write-manifest", "deploy"]) +@pytest.mark.parametrize( + ("options", "name", "allow_uv"), + [ + pytest.param([], "pip", None, id="default"), + pytest.param(["--package-installer", "pip"], "pip", False, id="pip"), + pytest.param(["--package-installer", "uv"], "uv", True, id="uv"), + ], +) +def test_uv_lock_manifest_package_installer(tmp_path, command, options, name, allow_uv): + (tmp_path / "app.py").touch() + (tmp_path / "pyproject.toml").write_text( + "[project]\nname = 'demo'\nversion = '0.0.0'\nrequires-python = '>=3.11'\n" + ) + subprocess.run([sys.executable, "-m", "uv", "lock", "--offline"], cwd=tmp_path, check=True) + + args = [command, "api", "-r", "uv.lock", "--python", sys.executable, *options, str(tmp_path)] + runner = CliRunner() + if command == "deploy": + with mock.patch("rsconnect.main.RSConnectExecutor") as executor: + result = runner.invoke(cli, apply_common_args(args, server="http://fake_server", key="FAKE_API_KEY")) + assert result.exit_code == 0, result.output + builder, *bundle_args = executor.return_value.make_bundle.call_args.args + bundle_kwargs = executor.return_value.make_bundle.call_args.kwargs + with builder(*bundle_args, **bundle_kwargs) as bundle, tarfile.open(fileobj=bundle, mode="r:gz") as archive: + manifest_file = archive.extractfile("manifest.json") + assert manifest_file is not None + manifest = json.load(manifest_file) + else: + result = runner.invoke(cli, args) + assert result.exit_code == 0, result.output + manifest = json.loads((tmp_path / "manifest.json").read_text()) + + package_manager = manifest["python"]["package_manager"] + assert package_manager["name"] == name + assert package_manager["package_file"] == "requirements.txt.lock" + if allow_uv is None: + assert "allow_uv" not in package_manager + else: + assert package_manager["allow_uv"] is allow_uv + if name == "uv": + reported_version = subprocess.check_output([sys.executable, "-m", "uv", "--version"], text=True).split()[1] + assert package_manager["version"] == reported_version + + def test_deploy_quarto_passes_package_installer(tmp_path: pathlib.Path): (tmp_path / "doc.qmd").write_text("---\ntitle: t\n---\n") (tmp_path / "requirements.txt").write_text("jupyter\n")