Skip to content

Commit 43e814b

Browse files
authored
Merge pull request #399 from shubhbapna/previous-graph-resolver
feat: allow dependency resolution using the result of a previous bootstrap
2 parents d1deec8 + 9e79efd commit 43e814b

File tree

4 files changed

+512
-28
lines changed

4 files changed

+512
-28
lines changed

src/fromager/commands/bootstrap.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
dependency_graph,
1212
progress,
1313
requirements_file,
14+
resolver,
1415
sdist,
1516
server,
17+
sources,
18+
wheels,
1619
)
1720

1821
# Map child_name==child_version to list of (parent_name==parent_version, Requirement)
@@ -57,11 +60,19 @@ def _get_requirements_from_args(
5760
type=clickext.ClickPath(),
5861
help="pip requirements file",
5962
)
63+
@click.option(
64+
"-p",
65+
"--previous-bootstrap",
66+
"prev_graph_file",
67+
type=clickext.ClickPath(),
68+
help="graph file produced from a previous bootstrap",
69+
)
6070
@click.argument("toplevel", nargs=-1)
6171
@click.pass_obj
6272
def bootstrap(
6373
wkctx: context.WorkContext,
6474
requirements_files: list[pathlib.Path],
75+
prev_graph_file: pathlib.Path | None,
6576
toplevel: list[str],
6677
) -> None:
6778
"""Compute and build the dependencies of a set of requirements recursively
@@ -77,19 +88,48 @@ def bootstrap(
7788
)
7889
logger.info("bootstrapping %r variant of %s", wkctx.variant, to_build)
7990

91+
if prev_graph_file:
92+
prev_graph = dependency_graph.DependencyGraph.from_file(prev_graph_file)
93+
else:
94+
prev_graph = None
95+
8096
pre_built = wkctx.settings.list_pre_built()
8197
if pre_built:
8298
logger.info("treating %s as pre-built wheels", sorted(pre_built))
8399

84100
server.start_wheel_server(wkctx)
85101

102+
# we need to resolve all the top level dependencies before we start bootstrapping.
103+
# this is to ensure that if we are using an older bootstrap to resolve packages
104+
# we are able to upgrade a package anywhere in the dependency tree if it is mentioned
105+
# in the toplevel without having to fall back to history
106+
for req in to_build:
107+
pbi = wkctx.package_build_info(req)
108+
if pbi.pre_built:
109+
servers = wheels.get_wheel_server_urls(wkctx, req)
110+
source_url, version = wheels.resolve_prebuilt_wheel(wkctx, req, servers)
111+
else:
112+
source_url, version = sources.resolve_source(
113+
wkctx, req, resolver.PYPI_SERVER_URL
114+
)
115+
wkctx.dependency_graph.add_dependency(
116+
parent_name=None,
117+
parent_version=None,
118+
req_type=requirements_file.RequirementType.TOP_LEVEL,
119+
req=req,
120+
req_version=version,
121+
download_url=source_url,
122+
pre_built=pbi.pre_built,
123+
)
124+
86125
with progress.progress_context(total=len(to_build)) as progressbar:
87126
for req in to_build:
88127
sdist.handle_requirement(
89128
wkctx,
90129
req,
91130
req_type=requirements_file.RequirementType.TOP_LEVEL,
92131
progressbar=progressbar,
132+
prev_graph=prev_graph,
93133
)
94134
progressbar.update()
95135

0 commit comments

Comments
 (0)