Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonLWhite committed Jun 13, 2024
1 parent e3d3e31 commit ebb4314
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from poetry_plugin_bundle.bundlers.bundler import Bundler


if TYPE_CHECKING:
from pathlib import Path

from cleo.io.io import IO
from cleo.io.outputs.section_output import SectionOutput
from poetry.poetry import Poetry
Expand Down Expand Up @@ -51,8 +52,8 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
from poetry.core.packages.package import Package
from poetry.installation.installer import Installer
from poetry.installation.operations.install import Install
from poetry.utils.env import EnvManager
from poetry.utils.env import Env
from poetry.utils.env import EnvManager
from poetry.utils.env.exceptions import InvalidCurrentPythonVersionError

class CustomEnvManager(EnvManager):
Expand All @@ -62,14 +63,17 @@ class CustomEnvManager(EnvManager):
It works by hijacking the "in_project_venv" concept so that we can get that behavior, but with a custom
path.
"""

@property
def in_project_venv(self) -> Path:
return self._path

def use_in_project_venv(self) -> bool:
return True

def create_venv_at_path(self, path: Path, executable: Path | None, force: bool) -> Env:
def create_venv_at_path(
self, path: Path, executable: Path | None, force: bool
) -> Env:
self._path = path
return self.create_venv(name=None, executable=executable, force=force)

Expand All @@ -93,16 +97,21 @@ def create_venv_at_path(self, path: Path, executable: Path | None, force: bool)
else:
self._write(
io,
f"{message}: <info>Creating a virtual environment using Poetry-determined Python"
f"{message}: <info>Creating a virtual environment using Poetry-determined Python",
)

try:
env = manager.create_venv_at_path(self._path, executable=executable, force=self._remove)
env = manager.create_venv_at_path(
self._path, executable=executable, force=self._remove
)
except InvalidCurrentPythonVersionError:
self._write(
io, f"{message}: <info>Replacing existing virtual environment due to incompatible Python version</info>"
io,
f"{message}: <info>Replacing existing virtual environment due to incompatible Python version</info>",
)
env = manager.create_venv_at_path(
self._path, executable=executable, force=True
)
env = manager.create_venv_at_path(self._path, executable=executable, force=True)

self._write(io, f"{message}: <info>Installing dependencies</info>")

Expand Down
4 changes: 2 additions & 2 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from poetry.factory import Factory
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.repository import Repository
from poetry.utils.env import MockEnv
from poetry.repositories.repository_pool import RepositoryPool
from poetry.utils.env import MockEnv

from poetry_plugin_bundle.bundlers.venv_bundler import VenvBundler

Expand Down Expand Up @@ -53,7 +53,7 @@ def poetry(config: Config) -> Poetry:
return poetry


def _create_venv_marker_file(tempdir: str) -> Path:
def _create_venv_marker_file(tempdir: str | Path) -> Path:
marker_file = Path(tempdir) / "existing-venv-marker.txt"
marker_file.write_text("This file should get deleted as part of venv recreation.")
return marker_file
Expand Down

0 comments on commit ebb4314

Please sign in to comment.