Skip to content

Commit

Permalink
faster PEP517 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and abn committed Mar 2, 2024
1 parent 28d5c00 commit 0906752
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
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

0 comments on commit 0906752

Please sign in to comment.