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
7 changes: 1 addition & 6 deletions rsconnect/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def create_python_environment(
requirements_file: typing.Optional[str] = "requirements.txt",
python: typing.Optional[str] = None,
override_python_version: typing.Optional[str] = None,
app_file: typing.Optional[str] = None,
package_manager: typing.Optional[PackageInstaller] = None,
) -> "Environment":
"""Given a project directory and a Python executable, return Environment information.
Expand All @@ -128,14 +127,10 @@ def create_python_environment(
capture the environment via pip freeze.
:param python: the Python executable of the environment to use for inspection.
:param override_python_version: the Python version required by the project.
:param app_file: the main application file to use for inspection.

:return: a tuple containing the Python executable of the environment and the Environment object.
"""
if app_file is None:
module_file = fake_module_file_from_directory(directory)
else:
module_file = app_file
module_file = fake_module_file_from_directory(directory)

_warn_on_ignored_manifest(directory)
_warn_if_environment_directory(directory)
Expand Down
5 changes: 1 addition & 4 deletions rsconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,6 @@ def deploy_notebook(
environment = Environment.create_python_environment(
base_dir,
requirements_file=requirements_file,
app_file=file,
python=python,
override_python_version=override_python_version,
package_manager=package_installer,
Expand Down Expand Up @@ -3981,7 +3980,6 @@ def write_manifest_notebook(
requirements_file=requirements_file,
python=python,
override_python_version=override_python_version,
app_file=file,
package_manager=package_installer,
)
r_environment = None if exclude_renv else REnvironment.create(base_dir)
Expand Down Expand Up @@ -4104,7 +4102,7 @@ def write_manifest_voila(
set_verbosity(verbose)
output_params(ctx, locals().items())
with cli_feedback("Checking arguments"):
base_dir = dirname(path)
base_dir = path if isdir(path) else dirname(path)
manifest_path = join(base_dir, "manifest.json")

if exists(manifest_path) and not overwrite:
Expand All @@ -4117,7 +4115,6 @@ def write_manifest_voila(
requirements_file=requirements_file,
override_python_version=override_python_version,
python=python,
app_file=path,
package_manager=package_installer,
)
r_environment = None if exclude_renv else REnvironment.create(base_dir)
Expand Down
57 changes: 57 additions & 0 deletions tests/test_write_manifest_voila.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import json
from pathlib import Path

import pytest
from click.testing import CliRunner

from rsconnect.bundle import file_checksum
from rsconnect.main import cli


@pytest.fixture
def project(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
monkeypatch.chdir(tmp_path)
project_dir = tmp_path / "proj"
project_dir.mkdir()
(project_dir / "report.ipynb").write_text('{"cells":[],"metadata":{},"nbformat":4,"nbformat_minor":5}')
(project_dir / "requirements.txt").write_text("voila\n")
return project_dir


@pytest.mark.parametrize("path", ["proj", "proj/", "proj/report.ipynb"])
@pytest.mark.parametrize("parent_requirements", [False, True])
def test_write_manifest_voila_uses_project_requirements(project: Path, path: str, parent_requirements: bool):
if parent_requirements:
Path("requirements.txt").write_text("pandas\n")

result = CliRunner().invoke(cli, ["write-manifest", "voila", path])

assert result.exit_code == 0, result.output
manifest = json.loads((project / "manifest.json").read_text())
assert manifest["files"]["requirements.txt"]["checksum"] == file_checksum(project / "requirements.txt")


def test_write_manifest_voila_checks_project_manifest_for_overwrite(project: Path):
manifest_path = project / "manifest.json"
manifest_path.write_text("{}")

result = CliRunner().invoke(cli, ["write-manifest", "voila", "proj"])

assert result.exit_code != 0
assert "manifest.json already exists" in result.output
assert manifest_path.read_text() == "{}"

result = CliRunner().invoke(cli, ["write-manifest", "voila", "--overwrite", "proj"])

assert result.exit_code == 0, result.output
assert json.loads(manifest_path.read_text())["metadata"]["appmode"] == "jupyter-voila"


def test_write_manifest_voila_ignores_parent_manifest(project: Path):
Path("manifest.json").write_text("{}")

result = CliRunner().invoke(cli, ["write-manifest", "voila", "proj"])

assert result.exit_code == 0, result.output
assert (project / "manifest.json").exists()
assert Path("manifest.json").read_text() == "{}"
Loading