Skip to content

Commit

Permalink
fix: python circular deps (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusArdelean authored Feb 5, 2024
1 parent 80c5f15 commit d391221
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pysrc/pip_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def create_tree_of_packages_dependencies(
def create_children_recursive(root_package, key_tree, ancestors, all_packages_map):
root_name = canonicalize_package_name(root_package[NAME])

# Checks if there is a circular dependency within the packages.
# Circular package example: apache.airflow and
if root_name in ancestors:
return root_package

if root_name not in key_tree:
msg = 'Required packages missing: ' + root_name
if allow_missing:
Expand All @@ -70,8 +75,10 @@ def create_children_recursive(root_package, key_tree, ancestors, all_packages_ma
ancestors = ancestors.copy()
ancestors.add(root_name)
children_packages_as_dist = key_tree[root_name]

for child_dist in children_packages_as_dist:
child_project_name = child_dist.project_name.lower()

if child_project_name in ancestors:
continue

Expand Down
48 changes: 44 additions & 4 deletions test/system/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.4',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand All @@ -131,7 +131,7 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.4',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.4',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down Expand Up @@ -289,6 +289,46 @@ describe('inspect', () => {
});
});

describe('Circular deps', () => {
let tearDown;
afterEach(() => {
tearDown();
});

it('Should get a valid dependency graph for circular dependencies', async () => {
const test_case = {
workspace: 'pip-app-circular-deps',
uninstallPackages: [],
pluginOpts: { allowEmpty: true }, // For Python 3.12
expected: [
{
pkg: {
name: 'apache-airflow',
version: '2.8.1',
},
directDeps: ['apache-airflow'],
},
],
};
testUtils.chdirWorkspaces(test_case.workspace);
testUtils.ensureVirtualenv(test_case.workspace);
tearDown = testUtils.activateVirtualenv(test_case.workspace);
testUtils.pipInstall();
if (test_case.uninstallPackages) {
test_case.uninstallPackages.forEach((pkg) => {
testUtils.pipUninstall(pkg);
});
}

const result = await inspect(
'.',
FILENAMES.pip.manifest,
test_case.pluginOpts
);
expect(result).toHaveProperty('dependencyGraph');
});
});

describe('poetry projects', () => {
it('should return expected dependencies for poetry-app', async () => {
const workspace = 'poetry-app';
Expand Down Expand Up @@ -402,7 +442,7 @@ describe('inspect', () => {
{
pkg: {
name: 'markupsafe',
version: '2.1.4',
version: '2.1.5',
},
directDeps: ['jinja2'],
},
Expand Down
1 change: 1 addition & 0 deletions test/workspaces/pip-app-circular-deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apache-airflow==2.8.1; python_version<"3.12"

0 comments on commit d391221

Please sign in to comment.