Skip to content

Commit

Permalink
fix: write version file for sdist build as well
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Jul 13, 2023
1 parent c8f70dd commit 2add9f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
This is a simple script to call pdm-pep517's backend apis to make release artifacts.
"""
import argparse
import logging
import os

import pdm.backend as api

Expand All @@ -13,9 +15,19 @@


def main() -> None:
api.build_sdist("dist")
api.build_wheel("dist")
api.build_editable("dist")
parser = argparse.ArgumentParser()
parser.add_argument("--no-wheel", action="store_false", dest="wheel")
parser.add_argument("--no-sdist", action="store_false", dest="sdist")
parser.add_argument("--no-editable", action="store_false", dest="editable")
parser.add_argument("path", nargs="?", default=".")
args = parser.parse_args()
os.chdir(args.path)
if args.sdist:
api.build_sdist("dist")
if args.wheel:
api.build_wheel("dist")
if args.editable:
api.build_editable("dist")


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion src/pdm/backend/hooks/version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def _write_version(
write_template: str = "{}\n",
) -> None:
"""Write the resolved version to the file."""
if write_to is not None and context.target != "sdist":
if write_to is not None:
if context.target == "sdist" and context.config.build_config.package_dir:
write_to = os.path.join(
context.config.build_config.package_dir, write_to
)
target = context.build_dir / write_to
if not target.parent.exists():
target.parent.mkdir(0o700, parents=True)
Expand Down

0 comments on commit 2add9f1

Please sign in to comment.