Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster PEP517 builds #9094

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import functools
import glob
import logging
import os

from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -56,7 +55,7 @@
builder.metadata_path(dest)
"""

PEP517_META_BUILD_DEPS = ["build==1.0.3", "pyproject_hooks==1.0.0"]
PEP517_META_BUILD_DEPS = ["build==1.1.1", "pyproject_hooks==1.0.0"]


class PackageInfoError(ValueError):
Expand Down Expand Up @@ -579,7 +578,7 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
return info

with ephemeral_environment(
flags={"no-pip": False, "setuptools": "bundle", "wheel": "bundle"}
flags={"no-pip": False, "no-setuptools": True, "no-wheel": True}
) as venv:
# TODO: cache PEP 517 build environment corresponding to each project venv
dest_dir = venv.path.parent / "dist"
Expand All @@ -600,31 +599,10 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
venv.run_python_script(pep517_meta_build_script)
info = PackageInfo.from_metadata_directory(dest_dir)
except EnvCommandError as e:
# something went wrong while attempting pep517 metadata build
# fallback to egg_info if setup.py available
logger.debug("PEP517 build failed: %s", e)
setup_py = path / "setup.py"
if not setup_py.exists():
raise PackageInfoError(
path,
e,
"No fallback setup.py file was found to generate egg_info.",
)

cwd = Path.cwd()
os.chdir(path)
try:
venv.run("python", "setup.py", "egg_info")
info = PackageInfo.from_metadata_directory(path)
except EnvCommandError as fbe:
raise PackageInfoError(
path, e, "Fallback egg_info generation failed.", fbe
)
finally:
os.chdir(cwd)
raise PackageInfoError(path, e, "PEP517 build failed")

if info:
logger.debug("Falling back to parsed setup.py file for %s", path)
return info

# if we reach here, everything has failed and all hope is lost
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def _prepare(
) -> Path:
from subprocess import CalledProcessError

with ephemeral_environment(self._env.python) as venv:
with ephemeral_environment(
self._env.python,
flags={"no-pip": True, "no-setuptools": True, "no-wheel": True},
) as venv:
env = IsolatedEnv(venv, self._pool)
builder = ProjectBuilder.from_isolated_env(
env, directory, runner=quiet_subprocess_runner
Expand Down
Loading