Skip to content

Commit 2a36e7f

Browse files
jlarkin09claude
authored andcommitted
feat(cli): add option for a single output-dir and hide options
Add a new -O/--output-dir option that sets the base directory for sdists-repo, wheels-repo, and work-dir. The individual directory options are hidden but still functional for backwards compatibility. When --output-dir is "." (the default), behavior is identical to before. Closes: #721 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Justin Larkin <jlarkin@redhat.com> Made-with: Cursor
1 parent 1e3d3ff commit 2a36e7f

2 files changed

Lines changed: 83 additions & 9 deletions

File tree

src/fromager/__main__.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,28 @@
6767
type=clickext.ClickPath(),
6868
help="save error messages to a file",
6969
)
70+
@click.option(
71+
"-O",
72+
"--output-dir",
73+
default=pathlib.Path("."),
74+
type=clickext.ClickPath(),
75+
help="base directory for sdists-repo, wheels-repo, and work-dir (default: current directory)",
76+
)
7077
@click.option(
7178
"-o",
7279
"--sdists-repo",
73-
default=pathlib.Path("sdists-repo"),
80+
default=None,
7481
type=clickext.ClickPath(),
75-
help="location to manage source distributions",
82+
hidden=True,
83+
help="location to manage source distributions (overrides --output-dir)",
7684
)
7785
@click.option(
7886
"-w",
7987
"--wheels-repo",
80-
default=pathlib.Path("wheels-repo"),
88+
default=None,
8189
type=clickext.ClickPath(),
82-
help="location to manage wheel repository",
90+
hidden=True,
91+
help="location to manage wheel repository (overrides --output-dir)",
8392
)
8493
@click.option(
8594
"--build-wheel-server-url",
@@ -88,9 +97,10 @@
8897
@click.option(
8998
"-t",
9099
"--work-dir",
91-
default=pathlib.Path("work-dir"),
100+
default=None,
92101
type=clickext.ClickPath(),
93-
help="location to manage working files, including builds and logs",
102+
hidden=True,
103+
help="location to manage working files, including builds and logs (overrides --output-dir)",
94104
)
95105
@click.option(
96106
"-p",
@@ -159,10 +169,11 @@ def main(
159169
log_file: pathlib.Path,
160170
log_format: str,
161171
error_log_file: pathlib.Path,
162-
sdists_repo: pathlib.Path,
163-
wheels_repo: pathlib.Path,
172+
output_dir: pathlib.Path,
173+
sdists_repo: pathlib.Path | None,
174+
wheels_repo: pathlib.Path | None,
164175
build_wheel_server_url: str,
165-
work_dir: pathlib.Path,
176+
work_dir: pathlib.Path | None,
166177
patches_dir: pathlib.Path,
167178
settings_file: pathlib.Path,
168179
settings_dir: pathlib.Path,
@@ -177,6 +188,15 @@ def main(
177188
global _DEBUG
178189
_DEBUG = debug
179190

191+
# Resolve output directories: explicit per-directory flags take
192+
# precedence, otherwise derive from --output-dir.
193+
if not sdists_repo:
194+
sdists_repo = output_dir / "sdists-repo"
195+
if not wheels_repo:
196+
wheels_repo = output_dir / "wheels-repo"
197+
if not work_dir:
198+
work_dir = output_dir / "work-dir"
199+
180200
# Set custom log factory to prepend requirement name.
181201
logging.setLogRecordFactory(log.FromagerLogRecord)
182202
# Set the overall logger level to debug and allow the handlers to filter

tests/test_cli.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,60 @@ def test_fromager_version(cli_runner: CliRunner) -> None:
4242
assert result.stdout.startswith("fromager, version")
4343

4444

45+
def test_output_dir_hidden_options(cli_runner: CliRunner) -> None:
46+
"""--output-dir is visible in help; old per-directory flags are hidden."""
47+
result = cli_runner.invoke(fromager, ["--help"])
48+
assert "-O, --output-dir" in result.output
49+
lines = result.output.splitlines()
50+
option_lines = [line.strip() for line in lines if line.strip().startswith("-")]
51+
option_names = " ".join(option_lines)
52+
assert "--sdists-repo" not in option_names
53+
assert "--wheels-repo" not in option_names
54+
assert "--work-dir" not in option_names
55+
56+
57+
def test_output_dir_sets_subdirectories(
58+
tmp_path: pathlib.Path, cli_runner: CliRunner
59+
) -> None:
60+
"""Passing -O <dir> creates sdists-repo, wheels-repo, work-dir under it."""
61+
out = tmp_path / "my-output"
62+
out.mkdir()
63+
64+
result = cli_runner.invoke(
65+
fromager,
66+
["-O", str(out), "canonicalize", "some-package"],
67+
)
68+
assert result.exit_code == 0, result.output
69+
assert (out / "sdists-repo").is_dir()
70+
assert (out / "wheels-repo").is_dir()
71+
assert (out / "work-dir").is_dir()
72+
73+
74+
def test_output_dir_overridden_by_explicit_flags(
75+
tmp_path: pathlib.Path, cli_runner: CliRunner
76+
) -> None:
77+
"""Explicit --sdists-repo takes precedence over --output-dir."""
78+
out = tmp_path / "base"
79+
out.mkdir()
80+
81+
result = cli_runner.invoke(
82+
fromager,
83+
[
84+
"-O",
85+
str(out),
86+
"--sdists-repo",
87+
str(tmp_path / "custom-sdists"),
88+
"canonicalize",
89+
"some-package",
90+
],
91+
)
92+
assert result.exit_code == 0, result.output
93+
assert (tmp_path / "custom-sdists").is_dir()
94+
assert (out / "wheels-repo").is_dir()
95+
assert (out / "work-dir").is_dir()
96+
assert not (out / "sdists-repo").exists()
97+
98+
4599
KNOWN_COMMANDS: set[str] = {
46100
"bootstrap",
47101
"bootstrap-parallel",

0 commit comments

Comments
 (0)