Skip to content

Commit be41323

Browse files
tdsteinclaude
andcommitted
fix: Find the notebook's project environment for deploy notebook --static
#920 added project environment discovery relative to the content directory, but the static path called which_python without one, so it searched from the current working directory instead of the notebook's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 79a8dc6 commit be41323

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎rsconnect/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ def deploy_notebook(
22372237
if static:
22382238
# The notebook is rendered locally and the bundle holds only the HTML, so Connect
22392239
# never builds an environment for it. Only an interpreter to run nbconvert is needed.
2240-
python_interpreter = which_python(python)
2240+
python_interpreter = which_python(python, base_dir)
22412241
else:
22422242
requirements_file = resolve_requirements_file(base_dir, requirements_file, force_generate)
22432243
environment = Environment.create_python_environment(

‎tests/test_main.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,35 @@ def test_deploy_notebook_static_renders_with_python_option(self, tmp_path):
371371
assert bundle_args[0] is make_notebook_html_bundle
372372
assert bundle_args[2] == str(python)
373373

374+
def test_deploy_notebook_static_renders_with_notebook_project_venv(self, tmp_path, monkeypatch):
375+
project = tmp_path / "project"
376+
notebook = project / "nb.ipynb"
377+
project.mkdir()
378+
shutil.copy(get_dir(join("pip1", "dummy.ipynb")), notebook)
379+
# Never run: make_bundle is mocked. Discovery only needs an executable file.
380+
python = project / ".venv" / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
381+
python.parent.mkdir(parents=True)
382+
python.write_text("")
383+
python.chmod(0o755)
384+
elsewhere = tmp_path / "elsewhere"
385+
elsewhere.mkdir()
386+
monkeypatch.chdir(elsewhere)
387+
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
388+
monkeypatch.delenv("CONDA_PREFIX", raising=False)
389+
390+
with mock.patch("rsconnect.main.RSConnectExecutor") as mock_executor:
391+
args = apply_common_args(
392+
["deploy", "notebook", str(notebook), "--static", "--no-verify"],
393+
server="http://fake_server",
394+
key="FAKE_API_KEY",
395+
)
396+
result = CliRunner().invoke(cli, args)
397+
398+
assert result.exit_code == 0, result.output
399+
bundle_args = mock_executor.return_value.make_bundle.call_args.args
400+
assert bundle_args[0] is make_notebook_html_bundle
401+
assert bundle_args[2] == str(python)
402+
374403
@pytest.mark.parametrize(
375404
("contents", "diagnostic", "missing_nbconvert"),
376405
[

0 commit comments

Comments
 (0)