diff --git a/.github/scripts/deny-git-deps.py b/.github/scripts/deny-git-deps.py index 60221d7d..e6b7b53f 100644 --- a/.github/scripts/deny-git-deps.py +++ b/.github/scripts/deny-git-deps.py @@ -8,6 +8,7 @@ root folder. If not provided, it will use the cwd. import os import sys +import toml from cargo_workspace import Workspace, DependencyLocation @@ -29,18 +30,45 @@ def check_dep(dep, used_by): else: errors.append(f'🚫 Found git dependency {dep.name} in {used_by}') -# Check the workspace dependencies that can be inherited: -for dep in workspace.dependencies: - check_dep(dep, "workspace") +# Check the workspace dependencies directly from Cargo.toml to avoid +# cargo-workspace library bug with path+version combinations +cargo_toml_path = os.path.join(root, 'Cargo.toml') +with open(cargo_toml_path, 'r') as f: + cargo_toml = toml.load(f) - if workspace.crates.find_by_name(dep.name): - if dep.location != DependencyLocation.PATH: - errors.append(f'🚫 Workspace must use path to link local dependency {dep.name}') +workspace_deps = cargo_toml.get('workspace', {}).get('dependencies', {}) +for dep_name, dep_value in workspace_deps.items(): + # Check if it's a git dependency + if isinstance(dep_value, dict) and 'git' in dep_value: + if 'workspace' not in ALLOWED_GIT_DEPS.get(dep_name, []): + errors.append(f'🚫 Found git dependency {dep_name} in workspace') + + # Check if local dependency uses path + if isinstance(dep_value, dict) and 'path' in dep_value: + # This is a local dep with path, which is correct + pass + elif workspace.crates.find_by_name(dep_name): + # Local crate exists but no path specified + errors.append(f'🚫 Workspace must use path to link local dependency {dep_name}') # And the dependencies of each crate: for crate in workspace.crates: - for dep in crate.dependencies: - check_dep(dep, crate.name) + try: + for dep in crate.dependencies: + check_dep(dep, crate.name) + except ValueError as e: + # cargo-workspace library has a bug with path+version combinations + # Parse TOML directly for this crate + crate_toml_path = os.path.join(crate.path, 'Cargo.toml') + if os.path.exists(crate_toml_path): + with open(crate_toml_path, 'r') as f: + crate_toml = toml.load(f) + for section in ['dependencies', 'dev-dependencies', 'build-dependencies']: + deps = crate_toml.get(section, {}) + for dep_name, dep_value in deps.items(): + if isinstance(dep_value, dict) and 'git' in dep_value: + if crate.name not in ALLOWED_GIT_DEPS.get(dep_name, []): + errors.append(f'🚫 Found git dependency {dep_name} in {crate.name}') if errors: print('❌ Found errors:')