Skip to content

Commit

Permalink
fix: handle cyclic deps
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-go committed Jan 18, 2018
1 parent 70f10ce commit fe19d73
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
13 changes: 10 additions & 3 deletions plug/pip_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_children(n): return key_tree.get(n.key, [])
p.key.lower() in lowercase_pkgs_names or
(p.project_name and p.project_name.lower()) in lowercase_pkgs_names]

def create_children_recursive(root_package, key_tree):
def create_children_recursive(root_package, key_tree, ancestors):
root_name = root_package[NAME].lower()
if root_name not in key_tree:
msg = 'Required package missing: ' + root_name
Expand All @@ -43,15 +43,22 @@ def create_children_recursive(root_package, key_tree):
return
else:
sys.exit(msg)

ancestors = ancestors.copy()
ancestors.add(root_name)
children_packages_as_dist = key_tree[root_name]
for child_dist in children_packages_as_dist:
if child_dist.project_name.lower() in ancestors:
continue

child_package = {
NAME: child_dist.project_name,
VERSION: child_dist.installed_version,
FROM: root_package[FROM] +
[child_dist.key + VERSION_SEPARATOR + child_dist.installed_version]
}
create_children_recursive(child_package, key_tree)

create_children_recursive(child_package, key_tree, ancestors)
if DEPENDENCIES not in root_package:
root_package[DEPENDENCIES] = {}
root_package[DEPENDENCIES][child_dist.project_name] = child_package
Expand Down Expand Up @@ -81,7 +88,7 @@ def create_package_as_root(package, dir_as_root):
dir_as_root = create_dir_as_root()
for package in packages_as_dist_obj:
package_as_root = create_package_as_root(package, dir_as_root)
package_tree = create_children_recursive(package_as_root, key_tree)
package_tree = create_children_recursive(package_as_root, key_tree, set([]))
dir_as_root[DEPENDENCIES][package_as_root[NAME]] = package_tree
return dir_as_root

Expand Down
40 changes: 40 additions & 0 deletions test/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,46 @@ test('inspect', function (t) {
},
}, 'django-select2 looks ok');

t.match(pkg.dependencies['irc'], {
name: 'irc',
version: '16.2',
from: [
"pip-app@0.0.0",
"irc@16.2"
],
dependencies: {
'more-itertools': {},
'jaraco.functools': {},
'jaraco.collections': {
dependencies: {
'jaraco.text': {},
}
},
'jaraco.text': {
dependencies: {
'jaraco.collections': {}
}
},
}
}, 'irc ok, even though it has a cyclic dep, yay!')

t.match(pkg.dependencies['testtools'], {
name: 'testtools',
version: '2.3.0',
from: [
"pip-app@0.0.0",
"testtools@2.3.0"
],
dependencies: {
'pbr': {},
'extras': {},
'fixtures': {},
'unittest2': {},
'traceback2': {},
'python-mimeparse': {},
}
}, 'testtools ok, even though it\'s cyclic, yay!')

t.end();
});

Expand Down
2 changes: 2 additions & 0 deletions test/workspaces/pip-app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Jinja2==2.7.2
Django==1.6.1
python-etcd==0.4.5
Django-Select2==6.0.1 # this version installs with lowercase so it catches a previous bug in pip_resolve.py
irc==16.2 # this has a cyclic dependecy (interanl jaraco.text <==> jaraco.collections)
testtools==2.3.0 # this has a cycle (fixtures ==> testtols)

0 comments on commit fe19d73

Please sign in to comment.