Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions rsconnect/subprocesses/inspect_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}


Expand Down
6 changes: 1 addition & 5 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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'])
Expand Down
48 changes: 48 additions & 0 deletions tests/test_package_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import json
import pathlib
import subprocess
import sys
import tarfile
import typing
from unittest import mock

Expand Down Expand Up @@ -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")
Expand Down
Loading