From d18ca5d2e751d5a44e48da38926662c90bcb23d1 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Wed, 24 Jan 2024 17:01:21 +0000 Subject: [PATCH 1/3] drop support for pip <19.0.0 (#8894) --- src/poetry/installation/executor.py | 16 ++-------------- src/poetry/utils/env/base_env.py | 12 ------------ src/poetry/utils/env/mock_env.py | 8 -------- src/poetry/utils/env/system_env.py | 6 ------ src/poetry/utils/env/virtual_env.py | 11 ----------- tests/utils/env/test_env.py | 6 +++--- 6 files changed, 5 insertions(+), 54 deletions(-) diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 4bd7604872e..2962e7716dc 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -696,15 +696,6 @@ def _install_directory_without_wheel_installer( package_poetry = Factory().create_poetry(pyproject.file.path.parent) if package_poetry is not None: - # Even if there is a build system specified - # some versions of pip (< 19.0.0) don't understand it - # so we need to check the version of pip to know - # if we can rely on the build system - legacy_pip = ( - self._env.pip_version - < self._env.pip_version.__class__.from_parts(19, 0, 0) - ) - builder: Builder if package.develop and not package_poetry.package.build_script: from poetry.masonry.builders.editable import EditableBuilder @@ -716,13 +707,10 @@ def _install_directory_without_wheel_installer( builder.build() return 0 - elif legacy_pip or package_poetry.package.build_script: + + if package_poetry.package.build_script: from poetry.core.masonry.builders.sdist import SdistBuilder - # We need to rely on creating a temporary setup.py - # file since the version of pip does not support - # build-systems - # We also need it for non-PEP-517 packages builder = SdistBuilder(package_poetry) with builder.setup_py(): return self.pip_install(req, upgrade=True, editable=package.develop) diff --git a/src/poetry/utils/env/base_env.py b/src/poetry/utils/env/base_env.py index 0880502cf41..5f4d558a5f0 100644 --- a/src/poetry/utils/env/base_env.py +++ b/src/poetry/utils/env/base_env.py @@ -21,7 +21,6 @@ if TYPE_CHECKING: from packaging.tags import Tag - from poetry.core.constraints.version import Version from poetry.core.version.markers import BaseMarker from virtualenv.seed.wheels.util import Wheel @@ -54,7 +53,6 @@ def __init__(self, path: Path, base: Path | None = None) -> None: self._base = base or path self._marker_env: dict[str, Any] | None = None - self._pip_version: Version | None = None self._site_packages: SitePackages | None = None self._paths: dict[str, str] | None = None self._supported_tags: list[Tag] | None = None @@ -170,13 +168,6 @@ def platform(self) -> str: def os(self) -> str: return os.name - @property - def pip_version(self) -> Version: - if self._pip_version is None: - self._pip_version = self.get_pip_version() - - return self._pip_version - @property def site_packages(self) -> SitePackages: if self._site_packages is None: @@ -288,9 +279,6 @@ def get_pip_command(self, embedded: bool = False) -> list[str]: def get_supported_tags(self) -> list[Tag]: raise NotImplementedError() - def get_pip_version(self) -> Version: - raise NotImplementedError() - def get_paths(self) -> dict[str, str]: raise NotImplementedError() diff --git a/src/poetry/utils/env/mock_env.py b/src/poetry/utils/env/mock_env.py index 225b88f69be..59fb37bc49b 100644 --- a/src/poetry/utils/env/mock_env.py +++ b/src/poetry/utils/env/mock_env.py @@ -3,8 +3,6 @@ from typing import TYPE_CHECKING from typing import Any -from poetry.core.constraints.version import Version - from poetry.utils.env.null_env import NullEnv @@ -22,7 +20,6 @@ def __init__( platform_machine: str = "amd64", os_name: str = "posix", is_venv: bool = False, - pip_version: str = "19.1", sys_path: list[str] | None = None, marker_env: dict[str, Any] | None = None, supported_tags: list[Tag] | None = None, @@ -36,7 +33,6 @@ def __init__( self._platform_machine = platform_machine self._os_name = os_name self._is_venv = is_venv - self._pip_version: Version = Version.parse(pip_version) self._sys_path = sys_path self._mock_marker_env = marker_env self._supported_tags = supported_tags @@ -53,10 +49,6 @@ def platform_machine(self) -> str: def os(self) -> str: return self._os_name - @property - def pip_version(self) -> Version: - return self._pip_version - @property def sys_path(self) -> list[str]: if self._sys_path is None: diff --git a/src/poetry/utils/env/system_env.py b/src/poetry/utils/env/system_env.py index e088e684480..8ddef7b5608 100644 --- a/src/poetry/utils/env/system_env.py +++ b/src/poetry/utils/env/system_env.py @@ -13,7 +13,6 @@ from packaging.tags import interpreter_name from packaging.tags import interpreter_version from packaging.tags import sys_tags -from poetry.core.constraints.version import Version from poetry.utils.env.base_env import Env @@ -81,11 +80,6 @@ def get_marker_env(self) -> dict[str, Any]: "interpreter_version": interpreter_version(), } - def get_pip_version(self) -> Version: - from pip import __version__ - - return Version.parse(__version__) - def is_venv(self) -> bool: return self._path != self._base diff --git a/src/poetry/utils/env/virtual_env.py b/src/poetry/utils/env/virtual_env.py index 8a573426fec..d91330c2354 100644 --- a/src/poetry/utils/env/virtual_env.py +++ b/src/poetry/utils/env/virtual_env.py @@ -13,7 +13,6 @@ from typing import Any from packaging.tags import Tag -from poetry.core.constraints.version import Version from poetry.utils.env.base_env import Env from poetry.utils.env.script_strings import GET_BASE_PREFIX @@ -72,16 +71,6 @@ def get_marker_env(self) -> dict[str, Any]: env: dict[str, Any] = json.loads(output) return env - def get_pip_version(self) -> Version: - output = self.run_pip("--version") - output = output.strip() - - m = re.match("pip (.+?)(?: from .+)?$", output) - if not m: - return Version.parse("0.0") - - return Version.parse(m.group(1)) - def get_paths(self) -> dict[str, str]: output = self.run_python_script(GET_PATHS) paths: dict[str, str] = json.loads(output) diff --git a/tests/utils/env/test_env.py b/tests/utils/env/test_env.py index da481455b55..535a979e1bf 100644 --- a/tests/utils/env/test_env.py +++ b/tests/utils/env/test_env.py @@ -2,6 +2,7 @@ import contextlib import os +import re import site import subprocess import sys @@ -82,9 +83,8 @@ def test_env_commands_with_spaces_in_their_arg_work_as_expected( venv_path = tmp_path / "Virtual Env" manager.build_venv(venv_path) venv = VirtualEnv(venv_path) - assert venv.run("python", str(venv.pip), "--version").startswith( - f"pip {venv.pip_version} from " - ) + output = venv.run("python", str(venv.pip), "--version") + assert re.match(r"pip \S+ from", output) def test_env_get_supported_tags_matches_inside_virtualenv( From 6c7e6b052ac41903ce2d14d913660e15b4557683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:59:52 +0100 Subject: [PATCH 2/3] build: make build formats dict available, handle deprecation of `poetry.core.masonry.builder` (#8877) Co-authored-by: Bartosz Sokorski --- src/poetry/console/commands/build.py | 30 +++++++++++++--- src/poetry/masonry/builders/__init__.py | 12 ++++++- tests/console/commands/test_build.py | 46 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/poetry/console/commands/build.py b/src/poetry/console/commands/build.py index 5339a865200..0d1bd15af45 100644 --- a/src/poetry/console/commands/build.py +++ b/src/poetry/console/commands/build.py @@ -1,11 +1,17 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from cleo.helpers import option from poetry.console.commands.env_command import EnvCommand from poetry.utils.env import build_environment +if TYPE_CHECKING: + from pathlib import Path + + class BuildCommand(EnvCommand): name = "build" description = "Builds a package, as a tarball and a wheel by default." @@ -20,9 +26,26 @@ class BuildCommand(EnvCommand): "poetry.core.masonry.builders.wheel", ] - def handle(self) -> int: - from poetry.core.masonry.builder import Builder + def _build( + self, + fmt: str, + executable: str | Path | None = None, + *, + target_dir: Path | None = None, + ) -> None: + from poetry.masonry.builders import BUILD_FORMATS + + if fmt in BUILD_FORMATS: + builders = [BUILD_FORMATS[fmt]] + elif fmt == "all": + builders = list(BUILD_FORMATS.values()) + else: + raise ValueError(f"Invalid format: {fmt}") + + for builder in builders: + builder(self.poetry, executable=executable).build(target_dir) + def handle(self) -> int: with build_environment(poetry=self.poetry, env=self.env, io=self.io) as env: fmt = self.option("format") or "all" package = self.poetry.package @@ -30,7 +53,6 @@ def handle(self) -> int: f"Building {package.pretty_name} ({package.version})" ) - builder = Builder(self.poetry) - builder.build(fmt, executable=env.python) + self._build(fmt, executable=env.python) return 0 diff --git a/src/poetry/masonry/builders/__init__.py b/src/poetry/masonry/builders/__init__.py index 61662422c39..4fdd87d96e0 100644 --- a/src/poetry/masonry/builders/__init__.py +++ b/src/poetry/masonry/builders/__init__.py @@ -1,6 +1,16 @@ from __future__ import annotations +from poetry.core.masonry.builders.sdist import SdistBuilder +from poetry.core.masonry.builders.wheel import WheelBuilder + from poetry.masonry.builders.editable import EditableBuilder -__all__ = ["EditableBuilder"] +__all__ = ["BUILD_FORMATS", "EditableBuilder"] + + +# might be extended by plugins +BUILD_FORMATS = { + "sdist": SdistBuilder, + "wheel": WheelBuilder, +} diff --git a/tests/console/commands/test_build.py b/tests/console/commands/test_build.py index ed9f3a3c5fa..3b378d1e4e5 100644 --- a/tests/console/commands/test_build.py +++ b/tests/console/commands/test_build.py @@ -5,17 +5,63 @@ from typing import TYPE_CHECKING +import pytest + from poetry.factory import Factory if TYPE_CHECKING: from pathlib import Path + from cleo.testers.command_tester import CommandTester + + from poetry.poetry import Poetry from poetry.utils.env import VirtualEnv from tests.types import CommandTesterFactory from tests.types import FixtureDirGetter +@pytest.fixture +def tmp_project_path(tmp_path: Path) -> Path: + return tmp_path / "project" + + +@pytest.fixture +def tmp_poetry(tmp_project_path: Path, fixture_dir: FixtureDirGetter) -> Poetry: + # copy project so that we start with a clean directory + shutil.copytree(fixture_dir("simple_project"), tmp_project_path) + poetry = Factory().create_poetry(tmp_project_path) + return poetry + + +@pytest.fixture +def tmp_tester( + tmp_poetry: Poetry, command_tester_factory: CommandTesterFactory +) -> CommandTester: + return command_tester_factory("build", tmp_poetry) + + +def get_package_glob(poetry: Poetry) -> str: + return f"{poetry.package.name.replace('-', '_')}-{poetry.package.version}*" + + +def test_build_format_is_not_valid(tmp_tester: CommandTester) -> None: + with pytest.raises(ValueError, match=r"Invalid format.*"): + tmp_tester.execute("--format not_valid") + + +@pytest.mark.parametrize("format", ["sdist", "wheel", "all"]) +def test_build_creates_packages_in_dist_directory_if_no_output_is_specified( + tmp_tester: CommandTester, tmp_project_path: Path, tmp_poetry: Poetry, format: str +) -> None: + tmp_tester.execute(f"--format {format}") + build_artifacts = tuple( + (tmp_project_path / "dist").glob(get_package_glob(tmp_poetry)) + ) + assert len(build_artifacts) > 0 + assert all(archive.exists() for archive in build_artifacts) + + def test_build_with_multiple_readme_files( fixture_dir: FixtureDirGetter, tmp_path: Path, From 90581f557cd50ece94b285ef5cb256640d8ce2f1 Mon Sep 17 00:00:00 2001 From: Alan Rivas Date: Sat, 27 Jan 2024 13:36:27 -0300 Subject: [PATCH 3/3] Fix error with a command in the docs (#8911) --- docs/cli.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 74ec6dc5334..db943dbcb09 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -377,8 +377,8 @@ poetry add git+https://github.com/sdispater/pendulum.git#develop poetry add git+https://github.com/sdispater/pendulum.git#2.0.5 # or using SSH instead: -poetry add git+ssh://github.com/sdispater/pendulum.git#develop -poetry add git+ssh://github.com/sdispater/pendulum.git#2.0.5 +poetry add git+ssh://git@github.com:sdispater/pendulum.git#develop +poetry add git+ssh://git@github.com:sdispater/pendulum.git#2.0.5 ``` or reference a subdirectory: