Skip to content

Commit d391221

Browse files
fix: python circular deps (#232)
1 parent 80c5f15 commit d391221

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

pysrc/pip_resolve.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def create_tree_of_packages_dependencies(
5959
def create_children_recursive(root_package, key_tree, ancestors, all_packages_map):
6060
root_name = canonicalize_package_name(root_package[NAME])
6161

62+
# Checks if there is a circular dependency within the packages.
63+
# Circular package example: apache.airflow and
64+
if root_name in ancestors:
65+
return root_package
66+
6267
if root_name not in key_tree:
6368
msg = 'Required packages missing: ' + root_name
6469
if allow_missing:
@@ -70,8 +75,10 @@ def create_children_recursive(root_package, key_tree, ancestors, all_packages_ma
7075
ancestors = ancestors.copy()
7176
ancestors.add(root_name)
7277
children_packages_as_dist = key_tree[root_name]
78+
7379
for child_dist in children_packages_as_dist:
7480
child_project_name = child_dist.project_name.lower()
81+
7582
if child_project_name in ancestors:
7683
continue
7784

test/system/inspect.spec.ts

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('inspect', () => {
117117
{
118118
pkg: {
119119
name: 'markupsafe',
120-
version: '2.1.4',
120+
version: '2.1.5',
121121
},
122122
directDeps: ['jinja2'],
123123
},
@@ -131,7 +131,7 @@ describe('inspect', () => {
131131
{
132132
pkg: {
133133
name: 'markupsafe',
134-
version: '2.1.4',
134+
version: '2.1.5',
135135
},
136136
directDeps: ['jinja2'],
137137
},
@@ -173,7 +173,7 @@ describe('inspect', () => {
173173
{
174174
pkg: {
175175
name: 'markupsafe',
176-
version: '2.1.4',
176+
version: '2.1.5',
177177
},
178178
directDeps: ['jinja2'],
179179
},
@@ -289,6 +289,46 @@ describe('inspect', () => {
289289
});
290290
});
291291

292+
describe('Circular deps', () => {
293+
let tearDown;
294+
afterEach(() => {
295+
tearDown();
296+
});
297+
298+
it('Should get a valid dependency graph for circular dependencies', async () => {
299+
const test_case = {
300+
workspace: 'pip-app-circular-deps',
301+
uninstallPackages: [],
302+
pluginOpts: { allowEmpty: true }, // For Python 3.12
303+
expected: [
304+
{
305+
pkg: {
306+
name: 'apache-airflow',
307+
version: '2.8.1',
308+
},
309+
directDeps: ['apache-airflow'],
310+
},
311+
],
312+
};
313+
testUtils.chdirWorkspaces(test_case.workspace);
314+
testUtils.ensureVirtualenv(test_case.workspace);
315+
tearDown = testUtils.activateVirtualenv(test_case.workspace);
316+
testUtils.pipInstall();
317+
if (test_case.uninstallPackages) {
318+
test_case.uninstallPackages.forEach((pkg) => {
319+
testUtils.pipUninstall(pkg);
320+
});
321+
}
322+
323+
const result = await inspect(
324+
'.',
325+
FILENAMES.pip.manifest,
326+
test_case.pluginOpts
327+
);
328+
expect(result).toHaveProperty('dependencyGraph');
329+
});
330+
});
331+
292332
describe('poetry projects', () => {
293333
it('should return expected dependencies for poetry-app', async () => {
294334
const workspace = 'poetry-app';
@@ -402,7 +442,7 @@ describe('inspect', () => {
402442
{
403443
pkg: {
404444
name: 'markupsafe',
405-
version: '2.1.4',
445+
version: '2.1.5',
406446
},
407447
directDeps: ['jinja2'],
408448
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
apache-airflow==2.8.1; python_version<"3.12"

0 commit comments

Comments
 (0)