From 8567a56de315efd7160cec0442bf9e31601fe7b9 Mon Sep 17 00:00:00 2001 From: Taylor Steinberg Date: Wed, 28 Oct 2026 12:01:31 -0400 Subject: [PATCH] fix: show current directory in missing requirements error --- rsconnect/environment.py | 2 +- tests/test_main.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/rsconnect/environment.py b/rsconnect/environment.py index 85bd1037..1dc792b1 100644 --- a/rsconnect/environment.py +++ b/rsconnect/environment.py @@ -337,7 +337,7 @@ def _check_requirements_file(directory: str, requirements_file: typing.Optional[ "The requirements file '%s' does not exist in '%s'.\n" "Please create the file or specify a different file with --requirements-file.\n" "To have the requirements file generated using pip freeze, pass --force-generate." - % (requirements_file, directory) + % (requirements_file, directory or ".") ) diff --git a/tests/test_main.py b/tests/test_main.py index 94a59c2f..bcd69ed9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2130,6 +2130,38 @@ def test_bad_entrypoint(self, tmp_path): assert "does not exist" in result.output +@pytest.mark.parametrize( + ("command", "filename"), + [ + (["write-manifest", "notebook"], "nb.ipynb"), + (["deploy", "notebook"], "nb.ipynb"), + (["deploy", "quarto"], "doc.qmd"), + ], +) +@pytest.mark.parametrize("path_kind", ["bare", "relative", "absolute"]) +@pytest.mark.parametrize("requirements_file", [None, "custom.txt"]) +def test_missing_requirements_reports_content_directory( + tmp_path, monkeypatch, command, filename, path_kind, requirements_file +): + monkeypatch.chdir(tmp_path) + content_dir = tmp_path if path_kind == "bare" else tmp_path / "content" + content_dir.mkdir(exist_ok=True) + content = content_dir / filename + content.write_text('{"cells":[],"metadata":{},"nbformat":4,"nbformat_minor":5}') + path = str(content) if path_kind == "absolute" else str(content.relative_to(tmp_path)) + expected_directory = str(content_dir) if path_kind == "absolute" else os.path.dirname(path) or "." + + requirements_option = ["--requirements-file", requirements_file] if requirements_file else [] + with mock.patch("rsconnect.main.which_quarto", return_value="quarto"), mock.patch( + "rsconnect.main.quarto_inspect", return_value={"engines": ["jupyter"]} + ): + result = CliRunner().invoke(cli, [*command, *requirements_option, path]) + + assert result.exit_code == 1 + expected_file = requirements_file or "requirements.txt" + assert f"The requirements file '{expected_file}' does not exist in '{expected_directory}'." in result.output + + class TestWriteManifestNodeJS: def test_help(self): runner = CliRunner()