Skip to content

Commit 73501aa

Browse files
dimblebyradoering
authored andcommitted
rearrange EnvManager build_venv()
so that it is possible to force installation of setuptools and wheel
1 parent 95dd8d3 commit 73501aa

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

src/poetry/inspection/info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
579579
return info
580580

581581
with ephemeral_environment(
582-
flags={"no-pip": False, "no-setuptools": False, "no-wheel": False}
582+
flags={"no-pip": False, "setuptools": "bundle", "wheel": "bundle"}
583583
) as venv:
584584
# TODO: cache PEP 517 build environment corresponding to each project venv
585585
dest_dir = venv.path.parent / "dist"

src/poetry/utils/env/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@contextmanager
4242
def ephemeral_environment(
4343
executable: Path | None = None,
44-
flags: dict[str, bool] | None = None,
44+
flags: dict[str, str | bool] | None = None,
4545
) -> Iterator[VirtualEnv]:
4646
with temporary_directory() as tmp_dir:
4747
# TODO: cache PEP 517 build environment corresponding to each project venv

src/poetry/utils/env/env_manager.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -612,35 +612,40 @@ def build_venv(
612612
cls,
613613
path: Path,
614614
executable: Path | None = None,
615-
flags: dict[str, bool] | None = None,
615+
flags: dict[str, str | bool] | None = None,
616616
with_pip: bool | None = None,
617617
with_wheel: bool | None = None,
618618
with_setuptools: bool | None = None,
619619
prompt: str | None = None,
620620
) -> virtualenv.run.session.Session:
621-
if WINDOWS:
622-
path = get_real_windows_path(path)
623-
executable = get_real_windows_path(executable) if executable else None
624-
625621
flags = flags or {}
626622

627-
flags["no-pip"] = (
628-
not with_pip if with_pip is not None else flags.pop("no-pip", True)
629-
)
623+
if with_pip is not None:
624+
flags["no-pip"] = not with_pip
630625

631-
flags["no-setuptools"] = (
632-
not with_setuptools
633-
if with_setuptools is not None
634-
else flags.pop("no-setuptools", True)
635-
)
626+
if with_wheel is not None:
627+
wheel_flags: dict[str, str | bool] = (
628+
{"wheel": "bundle"} if with_wheel else {"no-wheel": True}
629+
)
630+
flags.update(wheel_flags)
636631

637-
# we want wheels to be enabled when pip is required and it has not been
638-
# explicitly disabled
639-
flags["no-wheel"] = (
640-
not with_wheel
641-
if with_wheel is not None
642-
else flags.pop("no-wheel", flags["no-pip"])
643-
)
632+
if with_setuptools is not None:
633+
setuptools_flags: dict[str, str | bool] = (
634+
{"setuptools": "bundle"} if with_setuptools else {"no-setuptools": True}
635+
)
636+
flags.update(setuptools_flags)
637+
638+
flags.setdefault("no-pip", True)
639+
640+
if "setuptools" not in flags and "no-setuptools" not in flags:
641+
flags["no-setuptools"] = True
642+
643+
if "wheel" not in flags and "no-wheel" not in flags:
644+
flags["no-wheel"] = True
645+
646+
if WINDOWS:
647+
path = get_real_windows_path(path)
648+
executable = get_real_windows_path(executable) if executable else None
644649

645650
executable_str = None if executable is None else executable.resolve().as_posix()
646651

@@ -658,6 +663,9 @@ def build_venv(
658663
if value is True:
659664
args.append(f"--{flag}")
660665

666+
elif value is not False:
667+
args.append(f"--{flag}={value}")
668+
661669
args.append(str(path))
662670

663671
cli_result = virtualenv.cli_run(args)

tests/utils/test_env.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1489,18 +1489,21 @@ def test_env_system_packages_are_relative_to_lib(
14891489
@pytest.mark.parametrize(
14901490
("flags", "packages"),
14911491
[
1492-
({"no-pip": False}, {"pip", "wheel"}),
1492+
({"no-pip": False}, {"pip"}),
14931493
({"no-pip": False, "no-wheel": True}, {"pip"}),
1494+
({"no-pip": False, "no-wheel": False}, {"pip", "wheel"}),
14941495
({"no-pip": True}, set()),
14951496
({"no-setuptools": False}, {"setuptools"}),
14961497
({"no-setuptools": True}, set()),
1498+
({"setuptools": "bundle"}, {"setuptools"}),
14971499
({"no-pip": True, "no-setuptools": False}, {"setuptools"}),
14981500
({"no-wheel": False}, {"wheel"}),
1501+
({"wheel": "bundle"}, {"wheel"}),
14991502
({}, set()),
15001503
],
15011504
)
15021505
def test_env_no_pip(
1503-
tmp_path: Path, poetry: Poetry, flags: dict[str, bool], packages: set[str]
1506+
tmp_path: Path, poetry: Poetry, flags: dict[str, str | bool], packages: set[str]
15041507
) -> None:
15051508
venv_path = tmp_path / "venv"
15061509
EnvManager(poetry).build_venv(path=venv_path, flags=flags)

0 commit comments

Comments
 (0)