From ebb43142ab2c3f9fcbf4468297b2e2991d625bdb Mon Sep 17 00:00:00 2001 From: BrandonLWhite Date: Thu, 13 Jun 2024 15:49:32 -0500 Subject: [PATCH] Lint --- .../bundlers/venv_bundler.py | 23 +++++++++++++------ tests/bundlers/test_venv_bundler.py | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/poetry_plugin_bundle/bundlers/venv_bundler.py b/src/poetry_plugin_bundle/bundlers/venv_bundler.py index 08a31ef..39e8191 100644 --- a/src/poetry_plugin_bundle/bundlers/venv_bundler.py +++ b/src/poetry_plugin_bundle/bundlers/venv_bundler.py @@ -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 @@ -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): @@ -62,6 +63,7 @@ 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 @@ -69,7 +71,9 @@ def in_project_venv(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) @@ -93,16 +97,21 @@ def create_venv_at_path(self, path: Path, executable: Path | None, force: bool) else: self._write( io, - f"{message}: Creating a virtual environment using Poetry-determined Python" + f"{message}: 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}: Replacing existing virtual environment due to incompatible Python version" + io, + f"{message}: Replacing existing virtual environment due to incompatible Python version", + ) + 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}: Installing dependencies") diff --git a/tests/bundlers/test_venv_bundler.py b/tests/bundlers/test_venv_bundler.py index 4f6427b..8ef2198 100644 --- a/tests/bundlers/test_venv_bundler.py +++ b/tests/bundlers/test_venv_bundler.py @@ -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 @@ -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