Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: python circular deps / recursion error #232

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"