Skip to content

Commit

Permalink
Add minimal frontend
Browse files Browse the repository at this point in the history
This can be useful for testing purposes.

Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Jan 3, 2023
1 parent 5a4f523 commit 2157f48
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/pyproject_api/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import argparse
import os
import pathlib
import sys

from ._frontend import SdistResult, WheelResult
from ._via_fresh_subprocess import SubprocessFrontend


def main_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument(
"srcdir",
type=pathlib.Path,
nargs="?",
default=pathlib.Path(os.getcwd()),
help="source directory (defaults to current directory)",
)
parser.add_argument(
"--sdist",
"-s",
dest="distributions",
action="append_const",
const="sdist",
default=[],
help="build a source distribution",
)
parser.add_argument(
"--wheel",
"-w",
dest="distributions",
action="append_const",
const="wheel",
help="build a wheel distribution",
)
parser.add_argument(
"--outdir",
"-o",
type=pathlib.Path,
help=f"output directory (defaults to {{srcdir}}{os.sep}dist)",
)
return parser


def build(argv: list[str]) -> None:
parser = main_parser()
args = parser.parse_args(argv)

outdir = args.outdir or args.srcdir / "dist"
distributions = args.distributions or ["sdist", "wheel"]

frontend = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(args.srcdir)[:-1])
res: SdistResult | WheelResult

if "sdist" in distributions:
print("Building sdist...")
res = frontend.build_sdist(sdist_directory=outdir)
print(res.out)
print(res.err)

if "wheel" in distributions:
print("Building wheel...")
res = frontend.build_wheel(outdir)
print(res.out)
print(res.err)


if __name__ == "__main__":
build(sys.argv[1:])
2 changes: 2 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ iwusr
mktemp
namelist
nitpicky
outdir
prj
py311
py38
pygments
pyproject
sdist
setenv
srcdir
tmpdir
toml
tomli
Expand Down

0 comments on commit 2157f48

Please sign in to comment.