Skip to content
Merged
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
8 changes: 4 additions & 4 deletions rsconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,7 @@ def write_manifest_notebook(
r_environment,
)

if environment_file_exists and not generate_env:
if environment_file_exists and not generate_env and environment.source != "uv_lock":
click.secho(
" Warning: %s already exists and will not be overwritten." % environment.filename,
fg="yellow",
Expand Down Expand Up @@ -4229,7 +4229,7 @@ def write_manifest_voila(

environment_file_exists = exists(join(base_dir, environment.filename))
generate_env = requirements_file is None
if environment_file_exists and not generate_env:
if environment_file_exists and not generate_env and environment.source != "uv_lock":
click.secho(
" Warning: %s already exists and will not be overwritten." % environment.filename,
fg="yellow",
Expand Down Expand Up @@ -4390,7 +4390,7 @@ def write_manifest_quarto(
)

environment_file_exists = exists(join(base_dir, environment.filename))
if environment_file_exists and not generate_env:
if environment_file_exists and not generate_env and environment.source != "uv_lock":
click.secho(
" Warning: %s already exists and will not be overwritten." % environment.filename,
fg="yellow",
Expand Down Expand Up @@ -4974,7 +4974,7 @@ def _write_framework_manifest(
)

generate_env = requirements_file is None
if environment_file_exists and not generate_env:
if environment_file_exists and not generate_env and environment.source != "uv_lock":
click.secho(
" Warning: %s already exists and will not be overwritten." % environment.filename,
fg="yellow",
Expand Down
61 changes: 61 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import json
import logging
import os
Expand Down Expand Up @@ -2671,6 +2672,66 @@ def test_document_commands_export_uv_lock_for_bare_and_relative_paths(tmp_path,
assert (tmp_path / "requirements.txt.lock").exists()


@pytest.mark.parametrize("command", ["notebook", "voila", "quarto", "api", "pyproject"])
@pytest.mark.parametrize("requirements_file", ["uv.lock", "requirements.txt.lock", "custom.txt"])
def test_write_manifest_requirements_overwrite(tmp_path, monkeypatch, command, requirements_file):
monkeypatch.chdir(tmp_path)
filename = {"notebook": "nb.ipynb", "voila": "nb.ipynb", "quarto": "doc.qmd"}.get(command, "app.py")
(tmp_path / filename).write_text('{"cells":[],"metadata":{},"nbformat":4,"nbformat_minor":5}')
generated = requirements_file == "uv.lock"
project = "[project]\nname='demo'\nversion='0.0.0'\n"
if command == "pyproject":
project += '\n[tool.rsconnect]\napp_mode = "python-api"\nentrypoint = "app:app"\n'
(tmp_path / "pyproject.toml").write_text(project)
if generated:
subprocess.run([sys.executable, "-m", "uv", "lock", "--offline"], check=True)
lock = tmp_path / "uv.lock"
lock.write_text(
lock.read_text()
+ '\ndependencies = [{name = "example"}]\n'
+ '\n[[package]]\nname = "example"\nversion = "1.0"\n'
+ 'source = { registry = "https://pypi.org/simple" }\n'
)
else:
supplied_contents = b"# Publisher requirements\r\nexample==1.0\r\n"
(tmp_path / requirements_file).write_bytes(supplied_contents)

args = ["write-manifest", command, "-r", requirements_file, "." if filename == "app.py" else filename]
runner = CliRunner()
with (
mock.patch("rsconnect.main.which_quarto", return_value="quarto"),
mock.patch("rsconnect.main.quarto_inspect", return_value={"engines": ["jupyter"]}),
):
result = runner.invoke(cli, args)
assert result.exit_code == 0, result.output
manifest_path = tmp_path / "manifest.json"
original_manifest = manifest_path.read_bytes()
output = tmp_path / ("requirements.txt.lock" if generated else requirements_file)
original_contents = output.read_bytes()
if generated:
assert b"example==1.0" in original_contents
lock.write_text(lock.read_text().replace('version = "1.0"', 'version = "2.0"'))

result = runner.invoke(cli, args)
assert result.exit_code != 0
assert "Use --overwrite" in result.output
assert manifest_path.read_bytes() == original_manifest
assert output.read_bytes() == original_contents

for _ in range(2):
result = runner.invoke(cli, [*args, "--overwrite"])
assert result.exit_code == 0, result.output
manifest = json.loads(manifest_path.read_bytes())
package_file = manifest["python"]["package_manager"]["package_file"]
assert package_file == output.name
contents = (tmp_path / package_file).read_bytes()
assert manifest["files"][package_file]["checksum"] == hashlib.md5(contents).hexdigest()
if generated:
assert b"example==2.0" in contents
else:
assert contents == supplied_contents


class TestWriteManifestNodeJS:
def test_help(self):
runner = CliRunner()
Expand Down
Loading