Skip to content

Commit af2e8ff

Browse files
authored
chore: update find-cycles to work with Python 2 or 3 (aws#10428)
I ran into a cycle issue and tried to use find-cycles to diagnose it; unfortunately, it wasn't Python 3-compatible. A quick update makes it work for either Python 2 or 3. Apologies for the extra noise -- I've got my editor to automatically delete trailing whitespace. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1fc1ab1 commit af2e8ff

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

scripts/find-cycles.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@
33
import sys
44
import collections
55
import pprint
6-
6+
77
def find(xs, x):
88
for i, value in enumerate(xs):
99
if x == value:
1010
return i
1111
return None
12-
12+
1313
filenames = sys.argv[1:]
14-
14+
1515
graph = collections.defaultdict(set)
1616
for filename in filenames:
17-
with file(filename) as f:
17+
with open(filename) as f:
1818
package_json = json.load(f)
19-
19+
2020
for key in ['devDependencies', 'dependencies']:
2121
if key in package_json:
2222
graph[package_json['name']].update(package_json[key].keys())
23-
24-
23+
24+
2525
checked = set()
26-
26+
2727
# Do a check for cycles for each package. This is slow but it works,
2828
# and it has the advantage that it can give good diagnostics.
2929
def check_for_cycles(package, path):
3030
i = find(path, package)
3131
if i is not None:
3232
cycle = path[i:] + [package]
33-
print 'Cycle: %s' % ' => '.join(cycle)
33+
print('Cycle: %s' % ' => '.join(cycle))
3434
return
35-
35+
3636
if package in checked:
3737
return
38-
38+
3939
checked.add(package)
40-
40+
4141
deps = graph.get(package, [])
4242
for dep in deps:
4343
check_for_cycles(dep, path + [package])
44-
44+
4545
for package in graph.keys():
4646
check_for_cycles(package, [])

0 commit comments

Comments
 (0)