Skip to content

Commit 9d4945f

Browse files
committed
feat(cli): add option for a single output-dir and hide options
Signed-off-by: Sean Johnston <sejohnst@redhat.com>
1 parent 9b57894 commit 9d4945f

3 files changed

Lines changed: 84 additions & 21 deletions

File tree

src/fromager/__main__.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,16 @@
6565
type=clickext.ClickPath(),
6666
help="save error messages to a file",
6767
)
68-
@click.option(
69-
"-o",
70-
"--sdists-repo",
71-
default=pathlib.Path("sdists-repo"),
72-
type=clickext.ClickPath(),
73-
help="location to manage source distributions",
74-
)
75-
@click.option(
76-
"-w",
77-
"--wheels-repo",
78-
default=pathlib.Path("wheels-repo"),
79-
type=clickext.ClickPath(),
80-
help="location to manage wheel repository",
81-
)
8268
@click.option(
8369
"--build-wheel-server-url",
8470
help="An optional URL for external web server for building wheels, to replace the built-in server. Must be configured to serve the path specified for --wheels-repo.",
8571
)
8672
@click.option(
87-
"-t",
88-
"--work-dir",
89-
default=pathlib.Path("work-dir"),
73+
"-d",
74+
"--output-dir",
75+
default=None,
9076
type=clickext.ClickPath(),
91-
help="location to manage working files, including builds and logs",
77+
help="Location where sdists-repo, wheels-repo, and work-dir are created for logs, working files, source dists, and wheel repository",
9278
)
9379
@click.option(
9480
"-p",
@@ -143,6 +129,31 @@
143129
help="Build sdist and wheen with network isolation (unshare -cn)",
144130
show_default=True,
145131
)
132+
# hidden in favor of -d, --output-dir
133+
@click.option(
134+
"-o",
135+
"--sdists-repo",
136+
type=clickext.ClickPath(),
137+
default=pathlib.Path("sdists-repo"),
138+
help="location to manage source distributions",
139+
hidden=True,
140+
)
141+
@click.option(
142+
"-w",
143+
"--wheels-repo",
144+
type=clickext.ClickPath(),
145+
default=pathlib.Path("wheels-repo"),
146+
help="location to manage wheel repository",
147+
hidden=True,
148+
)
149+
@click.option(
150+
"-t",
151+
"--work-dir",
152+
type=clickext.ClickPath(),
153+
default=pathlib.Path("work-dir"),
154+
help="location to manage working files, including builds and logs",
155+
hidden=True,
156+
)
146157
@click.pass_context
147158
def main(
148159
ctx: click.Context,
@@ -151,10 +162,11 @@ def main(
151162
log_file: pathlib.Path,
152163
log_format: str,
153164
error_log_file: pathlib.Path,
165+
output_dir: pathlib.Path,
154166
sdists_repo: pathlib.Path,
155167
wheels_repo: pathlib.Path,
156-
build_wheel_server_url: str,
157168
work_dir: pathlib.Path,
169+
build_wheel_server_url: str,
158170
patches_dir: pathlib.Path,
159171
settings_file: pathlib.Path,
160172
settings_dir: pathlib.Path,
@@ -229,7 +241,7 @@ def main(
229241

230242
if network_isolation and not SUPPORTS_NETWORK_ISOLATION:
231243
ctx.fail(f"network isolation is not available: {NETWORK_ISOLATION_ERROR}")
232-
244+
logger.info(f"sdists_repo: {sdists_repo}")
233245
wkctx = context.WorkContext(
234246
active_settings=packagesettings.Settings.from_files(
235247
settings_file=settings_file,
@@ -240,10 +252,11 @@ def main(
240252
),
241253
constraints_file=constraints_file,
242254
patches_dir=patches_dir,
255+
output_dir=output_dir,
243256
sdists_repo=sdists_repo,
244257
wheels_repo=wheels_repo,
245-
wheel_server_url=build_wheel_server_url,
246258
work_dir=work_dir,
259+
wheel_server_url=build_wheel_server_url,
247260
cleanup=cleanup,
248261
variant=variant,
249262
network_isolation=network_isolation,

src/fromager/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(
4242
work_dir: pathlib.Path,
4343
cleanup: bool = True,
4444
variant: str = "cpu",
45+
output_dir: pathlib.Path | None = None,
4546
network_isolation: bool = False,
4647
max_jobs: int | None = None,
4748
settings_dir: pathlib.Path | None = None,
@@ -63,6 +64,10 @@ def __init__(
6364
self.constraints.load_constraints_file(constraints_file)
6465
else:
6566
self.input_constraints_uri = None
67+
if output_dir is not None:
68+
sdists_repo = output_dir / "sdists-repo"
69+
work_dir = output_dir / "work-dir"
70+
wheels_repo = output_dir / "wheels-repo"
6671
self.sdists_repo = pathlib.Path(sdists_repo).resolve()
6772
self.sdists_downloads = self.sdists_repo / "downloads"
6873
self.sdists_builds = self.sdists_repo / "builds"

tests/test_context.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,48 @@ def test_pip_constraints_args(tmp_path: pathlib.Path) -> None:
2828
)
2929
ctx.setup()
3030
assert [] == ctx.pip_constraint_args
31+
32+
33+
def test_output_directory_creation(tmp_path: pathlib.Path) -> None:
34+
"""Verify output directory creation"""
35+
36+
# default behavior
37+
# output_dir is None with sdists, wheels and work set to defaults
38+
ctx = context.WorkContext(
39+
active_settings=None,
40+
constraints_file=None,
41+
patches_dir=tmp_path / "overrides/patches",
42+
output_dir=None,
43+
sdists_repo=tmp_path / "sdists-repo",
44+
wheels_repo=tmp_path / "wheels-repo",
45+
work_dir=tmp_path / "work-dir",
46+
)
47+
ctx.setup()
48+
49+
assert ctx.sdists_repo == (tmp_path / "sdists-repo").resolve()
50+
assert ctx.wheels_repo == (tmp_path / "wheels-repo").resolve()
51+
assert ctx.work_dir == (tmp_path / "work-dir").resolve()
52+
53+
# set output_dir
54+
# should override defaults for sdists, wheels and work dirs
55+
output_dir = tmp_path / "test-output-dir"
56+
ctx = context.WorkContext(
57+
active_settings=None,
58+
constraints_file=None,
59+
patches_dir=tmp_path / "overrides/patches",
60+
output_dir=output_dir,
61+
sdists_repo=tmp_path / "sdists-repo",
62+
wheels_repo=tmp_path / "wheels-repo",
63+
work_dir=tmp_path / "work-dir",
64+
)
65+
ctx.setup()
66+
67+
# verify output_dir created
68+
assert ctx.sdists_repo == (output_dir / "sdists-repo").resolve()
69+
assert ctx.wheels_repo == (output_dir / "wheels-repo").resolve()
70+
assert ctx.work_dir == (output_dir / "work-dir").resolve()
71+
72+
# verify default dirs are not used
73+
assert ctx.sdists_repo != (tmp_path / "sdists-repo").resolve()
74+
assert ctx.wheels_repo != (tmp_path / "wheels-repo").resolve()
75+
assert ctx.work_dir != (tmp_path / "work-dir").resolve()

0 commit comments

Comments
 (0)