WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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
1 change: 1 addition & 0 deletions news/3231.bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the bug that `pdm build` would fail when `use_uv` is true.
74 changes: 52 additions & 22 deletions src/pdm/cli/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import tarfile
import tempfile
from pathlib import Path
from typing import Mapping

from pdm.cli.commands.base import BaseCommand
Expand Down Expand Up @@ -32,6 +33,7 @@ def do_build(
wheel: bool = True,
dest: str = "dist",
clean: bool = True,
verbose: int = 0,
config_settings: Mapping[str, str] | None = None,
hooks: HookManager | None = None,
) -> None:
Expand All @@ -57,29 +59,56 @@ def do_build(
hooks.try_emit("pre_build", dest=dest, config_settings=config_settings)
artifacts: list[str] = []
with project.core.ui.logging("build"):
if sdist:
project.core.ui.echo("[info]Building sdist...")
sdist_file = SdistBuilder(project.root, project.environment).build(dest)
project.core.ui.echo(f"[info]Built sdist at {sdist_file}")
artifacts.append(sdist_file)
if wheel:
if not project.config["use_uv"]:
if sdist:
project.core.ui.echo("[info]Building wheel from sdist...")
sdist_out = tempfile.mkdtemp(prefix="pdm-build-via-sdist-")
try:
with tarfile.open(sdist_file, "r:gz") as tf:
tf.extractall(sdist_out)
sdist_name = os.path.basename(sdist_file)[: -len(".tar.gz")]
whl = WheelBuilder(os.path.join(sdist_out, sdist_name), project.environment).build(dest)
project.core.ui.echo(f"[info]Built wheel at {whl}")
artifacts.append(whl)
finally:
shutil.rmtree(sdist_out, ignore_errors=True)
else:
project.core.ui.echo("[info]Building wheel...")
whl = WheelBuilder(project.root, project.environment).build(dest)
project.core.ui.echo(f"[info]Built wheel at {whl}")
artifacts.append(whl)
project.core.ui.echo("[info]Building sdist...")
sdist_file = SdistBuilder(project.root, project.environment).build(dest)
project.core.ui.echo(f"[info]Built sdist at {sdist_file}")
artifacts.append(sdist_file)
if wheel:
if sdist:
project.core.ui.echo("[info]Building wheel from sdist...")
sdist_out = tempfile.mkdtemp(prefix="pdm-build-via-sdist-")
try:
with tarfile.open(sdist_file, "r:gz") as tf:
tf.extractall(sdist_out)
sdist_name = os.path.basename(sdist_file)[: -len(".tar.gz")]
whl = WheelBuilder(os.path.join(sdist_out, sdist_name), project.environment).build(dest)
project.core.ui.echo(f"[info]Built wheel at {whl}")
artifacts.append(whl)
finally:
shutil.rmtree(sdist_out, ignore_errors=True)
else:
project.core.ui.echo("[info]Building wheel...")
whl = WheelBuilder(project.root, project.environment).build(dest)
project.core.ui.echo(f"[info]Built wheel at {whl}")
artifacts.append(whl)
else:
import subprocess

dest_dir = Path(dest).absolute()

uv_build_cmd = [*project.core.uv_cmd, "build", "--out-dir", str(dest_dir)]
if verbose == -1:
uv_build_cmd.append("-q")
elif verbose > 0:
uv_build_cmd.append(f"-{'v'*verbose}")
subprocess.run(uv_build_cmd, check=True)

# pdm build doesn't include .gitignore, and pdm publish would fail with .gitignore
(dest_dir / ".gitignore").unlink(missing_ok=True)
for sdist_fp in dest_dir.glob("*.tar.gz"):
if sdist is False:
sdist_fp.unlink(missing_ok=True)
else:
artifacts.append(str(sdist_fp))

for whl_file in dest_dir.glob("*.whl"):
if wheel is False:
whl_file.unlink(missing_ok=True)
else:
artifacts.append(str(whl_file))

hooks.try_emit("post_build", artifacts=artifacts, config_settings=config_settings)

def add_arguments(self, parser: argparse.ArgumentParser) -> None:
Expand Down Expand Up @@ -113,5 +142,6 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
wheel=options.wheel,
dest=options.dest,
clean=options.clean,
verbose=options.verbose,
hooks=HookManager(project, options.skip),
)
1 change: 1 addition & 0 deletions tests/cli/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_build_command(project, pdm, mocker):
wheel=True,
dest=mock.ANY,
clean=True,
verbose=0,
hooks=mock.ANY,
)
assert project.core.state.config_settings == {"a": "1", "b": "2"}
Expand Down
Loading