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
2 changes: 1 addition & 1 deletion src/pyproject_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main(argv: list[str]) -> None: # ruff:ignore[undocumented-public-function]
parser = main_parser()
args = parser.parse_args(argv)

outdir = args.outdir or args.srcdir / "dist"
outdir = (args.outdir or args.srcdir / "dist").absolute()
# we intentionally do not build editable distributions by default
distributions = args.distributions or ["sdist", "wheel"]

Expand Down
36 changes: 34 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from pathlib import Path
from shutil import copytree
from typing import TYPE_CHECKING

import pytest
Expand All @@ -12,6 +13,37 @@
import pytest_mock


@pytest.mark.parametrize(
("distribution", "filename"),
[
pytest.param("--sdist", "demo_pkg_inline-1.0.0.tar.gz", id="sdist"),
pytest.param("--wheel", "demo_pkg_inline-1.0.0-py3-none-any.whl", id="wheel"),
pytest.param("--editable", "demo_pkg_inline-1.0.0-py3-none-any.whl", id="editable"),
],
)
@pytest.mark.parametrize(
("outdir_args", "outdir"),
[
pytest.param([], "project/dist", id="default-outdir"),
pytest.param(["--outdir", "artifacts"], "artifacts", id="relative-outdir"),
],
)
def test_cli_build_relative_to_caller(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
distribution: str,
filename: str,
outdir_args: list[str],
outdir: str,
) -> None:
copytree(Path(__file__).parent / "demo_pkg_inline", tmp_path / "project")
monkeypatch.chdir(tmp_path)

pyproject_api.__main__.main(["project", distribution, *outdir_args])

assert (tmp_path / outdir / filename).is_file()


@pytest.mark.parametrize(
("cli_args", "srcdir", "outdir", "hooks"),
[
Expand All @@ -24,13 +56,13 @@
(
["src"],
Path("src"),
Path("src") / "dist",
Path("src").absolute() / "dist",
["build_sdist", "build_wheel"],
),
(
["-o", "out"],
Path.cwd(),
Path("out"),
Path("out").absolute(),
["build_sdist", "build_wheel"],
),
(
Expand Down
Loading