Skip to content

Commit

Permalink
Fix issue where path/to/venv is ignored and an existing venv is used (
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonLWhite authored Aug 15, 2024
1 parent 0ced665 commit e32fdac
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def in_project_venv(self) -> Path:
def use_in_project_venv(self) -> bool:
return True

def in_project_venv_exists(self) -> bool:
"""
Coerce this call to always return True so that we avoid the path in the base
EnvManager.get that detects an existing env residing at the centralized Poetry
virtualenvs_path location.
"""
return True

def create_venv_at_path(
self, path: Path, executable: Path | None, force: bool
) -> Env:
Expand Down
44 changes: 43 additions & 1 deletion tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.repository import Repository
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.env import EnvManager
from poetry.utils.env import MockEnv
from poetry.utils.env import VirtualEnv

from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler


if TYPE_CHECKING:
from poetry.config.config import Config
from poetry.poetry import Poetry
from poetry.utils.env import VirtualEnv
from pytest_mock import MockerFixture


Expand Down Expand Up @@ -353,3 +354,44 @@ def test_bundler_editable_deps(

editable_installs = list(filter(lambda package: package.develop, dep_installs))
assert len(editable_installs) == 0


def test_bundler_should_build_a_venv_at_specified_path_if_centralized_venv_exists(
io: BufferedIO,
tmpdir: str,
tmp_venv: VirtualEnv,
poetry: Poetry,
mocker: MockerFixture,
) -> None:
"""
Test coverage for [Issue #112](https://github.com/python-poetry/poetry-plugin-bundle/issues/112), which involves
a pre-existing "centralized" venv at the path specified in the Poetry configuration.
The test is intended to verify that the VenvBundler will build a new venv at the specified path if a centralized
venv already exists.
"""
mocker.patch("poetry.installation.executor.Executor._execute_operation")

poetry.config.config["virtualenvs"]["in-project"] = False
poetry.config.config["virtualenvs"]["path"] = tmp_venv.path

env_manager = EnvManager(poetry)
env_manager.activate(sys.executable)

bundler_venv_path = Path(tmpdir) / "bundler"
bundler = VenvBundler()
bundler.set_path(bundler_venv_path)

assert bundler.bundle(poetry, io)

bundler_venv = VirtualEnv(bundler_venv_path)
assert bundler_venv.is_sane()

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

0 comments on commit e32fdac

Please sign in to comment.