-
Couldn't load subscription status.
- Fork 31
Add sdist_backend setting, default to PEP 517 #577
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import enum | ||
| import errno | ||
| import inspect | ||
| import json | ||
| import logging | ||
|
|
@@ -38,6 +40,13 @@ | |
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class SDistBackend(enum.StrEnum): | ||
| # build sdist with PEP 517 hook | ||
| PEP517 = "pep571" | ||
| # create sdist with tarfile | ||
| TARBALL = "tarball" | ||
|
|
||
|
|
||
| def get_source_type(ctx: context.WorkContext, req: Requirement) -> str: | ||
| source_type = requirements_file.SourceType.SDIST | ||
| pbi = ctx.package_build_info(req) | ||
|
|
@@ -631,6 +640,11 @@ def build_sdist( | |
| return sdist_filename | ||
|
|
||
|
|
||
| # meson dist currently only works with Git or Mercurial repos | ||
| # affects NumPy and projects with https://mesonbuild.com/meson-python/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Meson doesn't work with an alternative VCS, it won't be used. I don't think Fromager should worry about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to clarify this comment or remove |
||
| BUILD_BACKEND_FORCE_TARBALL = {"mesonpy"} | ||
|
|
||
|
|
||
| def default_build_sdist( | ||
| ctx: context.WorkContext, | ||
| extra_environ: dict, | ||
|
|
@@ -639,6 +653,50 @@ def default_build_sdist( | |
| sdist_root_dir: pathlib.Path, | ||
| build_env: build_environment.BuildEnvironment, | ||
| build_dir: pathlib.Path, | ||
| ) -> pathlib.Path: | ||
| pbi = ctx.package_build_info(req) | ||
| sdist_backend = pbi.sdist_backend | ||
|
|
||
| pyproject_toml = dependencies.get_pyproject_contents(sdist_root_dir) | ||
| backend_settings = dependencies.get_build_backend(pyproject_toml) | ||
| build_backend = backend_settings["build-backend"] | ||
| if build_backend in BUILD_BACKEND_FORCE_TARBALL: | ||
| logger.info( | ||
| f"{req.name}: force build sdist tarball for backend '{build_backend}'" | ||
| ) | ||
| sdist_backend = SDistBackend.TARBALL | ||
|
|
||
| match sdist_backend: | ||
| case SDistBackend.PEP517: | ||
| return pep517_build_sdist( | ||
| ctx=ctx, | ||
| extra_environ=extra_environ, | ||
| req=req, | ||
| version=version, | ||
| sdist_root_dir=sdist_root_dir, | ||
| ) | ||
| case SDistBackend.TARBALL: | ||
| return tarball_build_sdist( | ||
| ctx=ctx, | ||
| extra_environ=extra_environ, | ||
| req=req, | ||
| version=version, | ||
| sdist_root_dir=sdist_root_dir, | ||
| build_env=build_env, | ||
| build_dir=build_dir, | ||
| ) | ||
| case _ as unreachable: | ||
| typing.assert_never(unreachable) | ||
|
|
||
|
|
||
| def tarball_build_sdist( | ||
| ctx: context.WorkContext, | ||
| extra_environ: dict, | ||
| req: Requirement, | ||
| version: Version, | ||
| sdist_root_dir: pathlib.Path, | ||
| build_env: build_environment.BuildEnvironment, | ||
| build_dir: pathlib.Path, | ||
| ) -> pathlib.Path: | ||
| # It seems like the "correct" way to do this would be to run the | ||
| # PEP 517 API in the source tree we have modified. However, quite | ||
|
|
@@ -650,6 +708,7 @@ def default_build_sdist( | |
| # | ||
| # For cases where the PEP 517 approach works, use | ||
| # pep517_build_sdist(). | ||
| logger.debug(f"{req.name}: build sdist tarball") | ||
| sdist_filename = ctx.sdists_builds / f"{req.name}-{version}.tar.gz" | ||
| if sdist_filename.exists(): | ||
| sdist_filename.unlink() | ||
|
|
@@ -670,14 +729,24 @@ def pep517_build_sdist( | |
| req: Requirement, | ||
| sdist_root_dir: pathlib.Path, | ||
| version: Version, | ||
| build_env: build_environment.BuildEnvironment | None = None, | ||
| ) -> pathlib.Path: | ||
| """Use the PEP 517 API to build a source distribution from a modified source tree.""" | ||
| logger.debug(f"{req.name}: build sdist PEP 517") | ||
| pyproject_toml = dependencies.get_pyproject_contents(sdist_root_dir) | ||
| hook_caller = dependencies.get_build_backend_hook_caller( | ||
| sdist_root_dir, | ||
| pyproject_toml, | ||
| extra_environ, | ||
| network_isolation=ctx.network_isolation, | ||
| build_env=build_env, | ||
| ) | ||
| sdist_filename = hook_caller.build_sdist(ctx.sdists_builds) | ||
| return ctx.sdists_builds / sdist_filename | ||
| sdist = ctx.sdists_builds / sdist_filename | ||
| if not sdist.is_file(): | ||
| raise FileNotFoundError( | ||
| errno.ENOENT, | ||
| f"{req.name}: PEP 517 build sdist failed for {req.name}=={version}", | ||
| sdist, | ||
| ) | ||
| return sdist | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 typo, but PEP 571 is the
manylinux2010PEP so could be a deep feature tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch :)