diff --git a/src/poetry_plugin_bundle/bundlers/venv_bundler.py b/src/poetry_plugin_bundle/bundlers/venv_bundler.py index 37ca710..6714a3c 100644 --- a/src/poetry_plugin_bundle/bundlers/venv_bundler.py +++ b/src/poetry_plugin_bundle/bundlers/venv_bundler.py @@ -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) + + ": Failed at step Installing" + f" {poetry.package.pretty_name}" + f" ({poetry.package.pretty_version})", + ) + return False self._write(io, self._get_message(poetry, self._path, done=True)) diff --git a/tests/bundlers/test_venv_bundler.py b/tests/bundlers/test_venv_bundler.py index 4a0a992..977ff90 100644 --- a/tests/bundlers/test_venv_bundler.py +++ b/tests/bundlers/test_venv_bundler.py @@ -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: