Skip to content

Commit 7df9620

Browse files
jlarkin09claude
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 a19dea7 commit 7df9620

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
@@ -66,19 +66,28 @@
6666
type=clickext.ClickPath(),
6767
help="save error messages to a file",
6868
)
69+
@click.option(
70+
"-O",
71+
"--output-dir",
72+
default=pathlib.Path("."),
73+
type=clickext.ClickPath(),
74+
help="base directory for sdists-repo, wheels-repo, and work-dir (default: current directory)",
75+
)
6976
@click.option(
7077
"-o",
7178
"--sdists-repo",
72-
default=pathlib.Path("sdists-repo"),
79+
default=None,
7380
type=clickext.ClickPath(),
74-
help="location to manage source distributions",
81+
hidden=True,
82+
help="location to manage source distributions (overrides --output-dir)",
7583
)
7684
@click.option(
7785
"-w",
7886
"--wheels-repo",
79-
default=pathlib.Path("wheels-repo"),
87+
default=None,
8088
type=clickext.ClickPath(),
81-
help="location to manage wheel repository",
89+
hidden=True,
90+
help="location to manage wheel repository (overrides --output-dir)",
8291
)
8392
@click.option(
8493
"--build-wheel-server-url",
@@ -87,9 +96,10 @@
8796
@click.option(
8897
"-t",
8998
"--work-dir",
90-
default=pathlib.Path("work-dir"),
99+
default=None,
91100
type=clickext.ClickPath(),
92-
help="location to manage working files, including builds and logs",
101+
hidden=True,
102+
help="location to manage working files, including builds and logs (overrides --output-dir)",
93103
)
94104
@click.option(
95105
"-p",
@@ -158,10 +168,11 @@ def main(
158168
log_file: pathlib.Path,
159169
log_format: str,
160170
error_log_file: pathlib.Path,
161-
sdists_repo: pathlib.Path,
162-
wheels_repo: pathlib.Path,
171+
output_dir: pathlib.Path,
172+
sdists_repo: pathlib.Path | None,
173+
wheels_repo: pathlib.Path | None,
163174
build_wheel_server_url: str,
164-
work_dir: pathlib.Path,
175+
work_dir: pathlib.Path | None,
165176
patches_dir: pathlib.Path,
166177
settings_file: pathlib.Path,
167178
settings_dir: pathlib.Path,
@@ -176,6 +187,15 @@ def main(
176187
global _DEBUG
177188
_DEBUG = debug
178189

190+
# Resolve output directories: explicit per-directory flags take
191+
# precedence, otherwise derive from --output-dir.
192+
if not sdists_repo:
193+
sdists_repo = output_dir / "sdists-repo"
194+
if not wheels_repo:
195+
wheels_repo = output_dir / "wheels-repo"
196+
if not work_dir:
197+
work_dir = output_dir / "work-dir"
198+
179199
# Set custom log factory to prepend requirement name.
180200
logging.setLogRecordFactory(log.FromagerLogRecord)
181201
# 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)