Skip to content

Commit 40c1564

Browse files
fix(cli): resolve output directories before invoking backends (#316)
## Summary Resolve the CLI's selected output directory against the caller's working directory before passing it to the frontend. Previously, `python -m pyproject_api project --wheel` created `project/dist` in the caller's directory, then sent `project/dist` to a backend already running inside `project`, causing the demo backend to raise `FileNotFoundError`. The runtime change is one expression. Add nine end-to-end cases using the repository's existing demo backend for default, relative and absolute output paths across sdist/wheel/editable builds. They check real generated artifacts; no subprocess behavior is mocked. The pristine source fails six cases, while the three absolute-path controls pass. Adjust two existing argument-test expectations and document the CLI path interpretation. This keeps symlink interpretation intact (`absolute()`, not `resolve()`) and leaves generic frontend path/configuration arguments unchanged. ## Validation - Linux Python3.11.17,3.12.15,3.13.16,3.14.8, stable3.15.0 and free-threaded3.15.0: official tox baseline74 passed → patched83 passed in every environment, all reaching the configured100% coverage gate. - Official tox `fix`, `type`, `docs` and `pkg_meta` passed; fixed pre-commit hooks did not modify the three candidate files. Linux tested copies match the canonical worktree byte for byte. - Windows Python3.12.14: CLI tests16 passed; full-suite baseline73 passed/1 failed and patch82 passed/1 failed. The same unchanged `test_ensure_empty_dir_on_path_symlink_to_folder` fails with WinError1314 because this account cannot create directory symlinks. - The original CLI repro now creates the real demo wheel at the expected path. - Read-only AI review found no actionable issue; no independent human review is claimed. Hosted CI and macOS are unverified. AI assistance was used for investigation, tests, implementation and review; no production incident is claimed. Closes #315 Remote verification: ReadTheDocs and pre-commit.ci succeeded. [Actions run38507824873](https://github.com/tox-dev/pyproject-api/actions/runs/38507824873) is `action_required`, awaiting maintainer approval to run; hosted tests are not yet verified. --------- Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
1 parent c58293e commit 40c1564

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎src/pyproject_api/__main__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def main(argv: list[str]) -> None: # ruff:ignore[undocumented-public-function]
6565
parser = main_parser()
6666
args = parser.parse_args(argv)
6767

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

‎tests/test_main.py‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4+
from shutil import copytree
45
from typing import TYPE_CHECKING
56

67
import pytest
@@ -12,6 +13,37 @@
1213
import pytest_mock
1314

1415

16+
@pytest.mark.parametrize(
17+
("distribution", "filename"),
18+
[
19+
pytest.param("--sdist", "demo_pkg_inline-1.0.0.tar.gz", id="sdist"),
20+
pytest.param("--wheel", "demo_pkg_inline-1.0.0-py3-none-any.whl", id="wheel"),
21+
pytest.param("--editable", "demo_pkg_inline-1.0.0-py3-none-any.whl", id="editable"),
22+
],
23+
)
24+
@pytest.mark.parametrize(
25+
("outdir_args", "outdir"),
26+
[
27+
pytest.param([], "project/dist", id="default-outdir"),
28+
pytest.param(["--outdir", "artifacts"], "artifacts", id="relative-outdir"),
29+
],
30+
)
31+
def test_cli_build_relative_to_caller(
32+
tmp_path: Path,
33+
monkeypatch: pytest.MonkeyPatch,
34+
distribution: str,
35+
filename: str,
36+
outdir_args: list[str],
37+
outdir: str,
38+
) -> None:
39+
copytree(Path(__file__).parent / "demo_pkg_inline", tmp_path / "project")
40+
monkeypatch.chdir(tmp_path)
41+
42+
pyproject_api.__main__.main(["project", distribution, *outdir_args])
43+
44+
assert (tmp_path / outdir / filename).is_file()
45+
46+
1547
@pytest.mark.parametrize(
1648
("cli_args", "srcdir", "outdir", "hooks"),
1749
[
@@ -24,13 +56,13 @@
2456
(
2557
["src"],
2658
Path("src"),
27-
Path("src") / "dist",
59+
Path("src").absolute() / "dist",
2860
["build_sdist", "build_wheel"],
2961
),
3062
(
3163
["-o", "out"],
3264
Path.cwd(),
33-
Path("out"),
65+
Path("out").absolute(),
3466
["build_sdist", "build_wheel"],
3567
),
3668
(

0 commit comments

Comments
 (0)