Skip to content

Commit 2c16675

Browse files
authored
Merge pull request #78 from TheTripleV/pkg
Only load packages that are dependencies
2 parents 89834d3 + 9c96e1a commit 2c16675

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

robotpy_build/pkgcfg_provider.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,35 @@ class PkgCfgProvider:
117117

118118
def __init__(self):
119119
self.pkgs = {}
120-
for entry_point in iter_entry_points(group="robotpybuild", name=None):
121-
try:
122-
pkg = PkgCfg(entry_point)
123-
except Exception as e:
124-
warnings.warn(f"Error loading entry point {entry_point.name}: {e}")
125-
else:
126-
self.add_pkg(pkg)
120+
121+
def detect_pkgs(self) -> None:
122+
"""
123+
Detect and load packages under the robotpybuild entry point group.
124+
Only loads packages that are dependencies.
125+
"""
126+
deps_names = set().union(*[pkg.depends for pkg in self.pkgs.values()])
127+
entry_points = list(iter_entry_points(group="robotpybuild", name=None))
128+
129+
# Only load the dependencies of the package we're building.
130+
# If we load the [package being built], then the current build will fail.
131+
# If we load a package that depends on the [package being built],
132+
# then the [package being built] will be loaded and the current build will fail.
133+
run_loop = True
134+
while run_loop:
135+
run_loop = False
136+
for ep in entry_points:
137+
if ep.name in self.pkgs: # Prevents loading the package being built
138+
continue
139+
if ep.name not in deps_names and ep.name != "robotpy-build":
140+
continue
141+
try:
142+
pkg = PkgCfg(ep)
143+
except Exception as e:
144+
warnings.warn(f"Error loading entry point {ep.name}: {e}")
145+
else:
146+
self.add_pkg(pkg)
147+
deps_names |= set(pkg.depends)
148+
run_loop = True
127149

128150
def add_pkg(self, pkg: PkgCfg) -> None:
129151
self.pkgs[pkg.name] = pkg

robotpy_build/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def prepare(self):
105105
self._collect_static_libs()
106106
self._collect_wrappers()
107107

108+
self.pkgcfg.detect_pkgs()
109+
108110
self.setup_kwargs["cmdclass"] = {
109111
"build_py": BuildPy,
110112
"build_dl": BuildDl,

0 commit comments

Comments
 (0)