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
12 changes: 11 additions & 1 deletion src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,22 @@ def locked_packages(self) -> dict[Package, TransitivePackageInfo]:
source_type="file",
source_url=str(wheel),
)
installer.executor.execute([Install(package)])
return_code = installer.executor.execute([Install(package)])
except ModuleOrPackageNotFoundError:
warnings.append(
"The root package was not installed because no matching module or"
" package was found."
)
else:
if return_code:
self._write(
io,
self._get_message(poetry, self._path, error=True)
+ ": <error>Failed</> at step <b>Installing"
f" {poetry.package.pretty_name}"
f" ({poetry.package.pretty_version})</b>",
)
return False

self._write(io, self._get_message(poetry, self._path, done=True))

Expand Down
28 changes: 28 additions & 0 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,34 @@ def test_bundler_should_fail_when_installation_fails(
assert expected == io.fetch_output()


def test_bundler_should_fail_when_root_package_installation_fails(
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture
) -> None:
def execute_operation(operation: Install) -> int:
if operation.package.name == "simple-project":
raise RuntimeError
return 0

mocker.patch(
"poetry.installation.executor.Executor._do_execute_operation",
side_effect=execute_operation,
)

bundler = VenvBundler()
bundler.set_path(Path(tmpdir))

assert not bundler.bundle(poetry, io)

expected = f"""\
• Bundling simple-project (1.2.3) into {tmpdir}
• Bundling simple-project (1.2.3) into {tmpdir}: Creating a virtual environment using Poetry-determined Python
• Bundling simple-project (1.2.3) into {tmpdir}: Installing dependencies
• Bundling simple-project (1.2.3) into {tmpdir}: Installing simple-project (1.2.3)
• Bundling simple-project (1.2.3) into {tmpdir}: Failed at step Installing simple-project (1.2.3)
"""
assert expected == io.fetch_output()


def test_bundler_should_display_a_warning_for_projects_with_no_module(
io: BufferedIO, tmp_venv: VirtualEnv, mocker: MockerFixture, config: Config
) -> None:
Expand Down
Loading