Skip to content

Commit e32fdac

Browse files
Fix issue where path/to/venv is ignored and an existing venv is used (#114)
1 parent 0ced665 commit e32fdac

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/poetry_plugin_bundle/bundlers/venv_bundler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ def in_project_venv(self) -> Path:
7979
def use_in_project_venv(self) -> bool:
8080
return True
8181

82+
def in_project_venv_exists(self) -> bool:
83+
"""
84+
Coerce this call to always return True so that we avoid the path in the base
85+
EnvManager.get that detects an existing env residing at the centralized Poetry
86+
virtualenvs_path location.
87+
"""
88+
return True
89+
8290
def create_venv_at_path(
8391
self, path: Path, executable: Path | None, force: bool
8492
) -> Env:

tests/bundlers/test_venv_bundler.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
from poetry.puzzle.exceptions import SolverProblemError
1717
from poetry.repositories.repository import Repository
1818
from poetry.repositories.repository_pool import RepositoryPool
19+
from poetry.utils.env import EnvManager
1920
from poetry.utils.env import MockEnv
21+
from poetry.utils.env import VirtualEnv
2022

2123
from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler
2224

2325

2426
if TYPE_CHECKING:
2527
from poetry.config.config import Config
2628
from poetry.poetry import Poetry
27-
from poetry.utils.env import VirtualEnv
2829
from pytest_mock import MockerFixture
2930

3031

@@ -353,3 +354,44 @@ def test_bundler_editable_deps(
353354

354355
editable_installs = list(filter(lambda package: package.develop, dep_installs))
355356
assert len(editable_installs) == 0
357+
358+
359+
def test_bundler_should_build_a_venv_at_specified_path_if_centralized_venv_exists(
360+
io: BufferedIO,
361+
tmpdir: str,
362+
tmp_venv: VirtualEnv,
363+
poetry: Poetry,
364+
mocker: MockerFixture,
365+
) -> None:
366+
"""
367+
Test coverage for [Issue #112](https://github.com/python-poetry/poetry-plugin-bundle/issues/112), which involves
368+
a pre-existing "centralized" venv at the path specified in the Poetry configuration.
369+
The test is intended to verify that the VenvBundler will build a new venv at the specified path if a centralized
370+
venv already exists.
371+
"""
372+
mocker.patch("poetry.installation.executor.Executor._execute_operation")
373+
374+
poetry.config.config["virtualenvs"]["in-project"] = False
375+
poetry.config.config["virtualenvs"]["path"] = tmp_venv.path
376+
377+
env_manager = EnvManager(poetry)
378+
env_manager.activate(sys.executable)
379+
380+
bundler_venv_path = Path(tmpdir) / "bundler"
381+
bundler = VenvBundler()
382+
bundler.set_path(bundler_venv_path)
383+
384+
assert bundler.bundle(poetry, io)
385+
386+
bundler_venv = VirtualEnv(bundler_venv_path)
387+
assert bundler_venv.is_sane()
388+
389+
path = bundler_venv_path
390+
expected = f"""\
391+
• Bundling simple-project (1.2.3) into {path}
392+
• Bundling simple-project (1.2.3) into {path}: Creating a virtual environment using Poetry-determined Python
393+
• Bundling simple-project (1.2.3) into {path}: Installing dependencies
394+
• Bundling simple-project (1.2.3) into {path}: Installing simple-project (1.2.3)
395+
• Bundled simple-project (1.2.3) into {path}
396+
"""
397+
assert expected == io.fetch_output()

0 commit comments

Comments
 (0)