Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 1fe041a

Browse files
committed
Improve cycle detection
Keep a set of any bundle we've inspected before as a different set compared to the current bundles being inspected as part of the depth first chain. This fixes a major performance problem with re-evaluating bundles that have already been seen before while still allowing cycles to be spotted and accurately reported in the bundle configurations. Signed-off-by: William Douglas <[email protected]>
1 parent e036fd2 commit 1fe041a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
setup(
44
name="unbundle",
5-
version="0.1.6",
5+
version="1.0.0",
66
scripts=["unbundle"]
77
)

unbundle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import argparse
33
import os
44
import sys
55

6-
def resolve_includes(bundle_name, bundle_path, content, bundles=False, path=set()):
6+
def resolve_includes(bundle_name, bundle_path, content, bundles=False, path=set(), seen=set()):
77
"""
88
resolve_incudes returns a full package list of include-resolved packages in
99
the bundle definition file or pundle declaration under bundle_path. Sources
1010
for included bundles are other bundle definition files at
1111
bundle_path/bundles/* and bundle_path/packages.
1212
"""
13-
bundle_def = os.path.join(bundle_path, "bundles", bundle_name)
13+
if bundle_name in seen:
14+
return True
15+
seen.add(bundle_name)
1416
path.add(bundle_name)
17+
bundle_def = os.path.join(bundle_path, "bundles", bundle_name)
1518
try:
1619
with open(bundle_def, "r", encoding="latin-1") as bundlef:
1720
lines = bundlef.readlines()
@@ -31,9 +34,8 @@ def resolve_includes(bundle_name, bundle_path, content, bundles=False, path=set(
3134
elif line.startswith("include("):
3235
inc_bundle = line[line.find("(")+1:line.find(")")]
3336
if inc_bundle in path:
34-
# print(f"Error cycle detected: {inc_bundle} is part of a loop in bundles {path}.")
35-
# return False
36-
continue
37+
print(f"Error cycle detected: {inc_bundle} is part of a loop in bundles {path}.")
38+
return False
3739
success = resolve_includes(inc_bundle, bundle_path, content, bundles, path)
3840
if not success:
3941
return False

0 commit comments

Comments
 (0)