diff --git a/src/pyproject_api/__main__.py b/src/pyproject_api/__main__.py index 7e10879..2f4ef7b 100644 --- a/src/pyproject_api/__main__.py +++ b/src/pyproject_api/__main__.py @@ -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"] diff --git a/tests/test_main.py b/tests/test_main.py index 4d820b3..8363769 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,7 @@ from __future__ import annotations from pathlib import Path +from shutil import copytree from typing import TYPE_CHECKING import pytest @@ -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"), [ @@ -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"], ), (