diff --git a/.github/actions/base-setup/create_constraints_file.py b/.github/actions/base-setup/create_constraints_file.py index b7a384b..9ce5a9a 100644 --- a/.github/actions/base-setup/create_constraints_file.py +++ b/.github/actions/base-setup/create_constraints_file.py @@ -1,10 +1,10 @@ import sys -from typing import cast, List +from importlib.metadata import PackageMetadata from pathlib import Path +from typing import List, cast from build.util import project_wheel_metadata from packaging.requirements import Requirement -from importlib.metadata import PackageMetadata output_file = sys.argv[-2] top_level_project_dir = sys.argv[-1] @@ -13,7 +13,7 @@ def extract_dependencies(project_dir): reqs = [] - print(f'Extracting metadata from wheel for {project_dir}...') + print(f"Extracting metadata from wheel for {project_dir}...") metadata = project_wheel_metadata(source_dir=project_dir) reqs.extend(get_requires_dist(metadata)) @@ -22,28 +22,26 @@ def extract_dependencies(project_dir): local_projects = {} for req in reqs: r = Requirement(req) - if r.url and r.url.startswith('file://'): - path = r.url.replace('file://', '') + if r.url and r.url.startswith("file://"): + path = r.url.replace("file://", "") local_projects[r.name] = path reqs_from_local_dependencies = [] for dependency_name, path in local_projects.items(): - print(f'Discovering constraints in local {r.name} package under {path}') + print(f"Discovering constraints in local {r.name} package under {path}") sub_dependencies = extract_dependencies(path) # filter out dependencies between local packages (e.g. jupyter-ai depends on # a fixed minimum version of `jupyter-ai-magics`, but here we want to test # the latest version against its third-party dependencies - not the old one). sub_dependencies = [ - req - for req in sub_dependencies - if Requirement(req).name not in local_projects + req for req in sub_dependencies if Requirement(req).name not in local_projects ] reqs_from_local_dependencies.extend(sub_dependencies) return reqs + reqs_from_local_dependencies def get_requires_dist(metadata: PackageMetadata) -> List[str]: - return cast(List[str], metadata.get_all('Requires-Dist')) + return cast(List[str], metadata.get_all("Requires-Dist")) reqs = extract_dependencies(top_level_project_dir)