Skip to content

Commit

Permalink
feat: support pre-commit local python hooks additional_dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Jan 5, 2025
1 parent 0b2732a commit f5e2ed5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ repos:
rev: 19.3b0
hooks:
- id: black
language: python
additional_dependencies:
- "request==1.1.1"
- repo: https://gitlab.com/psf/black
# should also detect gitlab
rev: 19.3b0
hooks:
- id: black
# missing language, not extracted
additional_dependencies:
- "urllib==24.9.0"
- repo: http://gitlab.com/psf/black
# should also detect http
rev: 19.3b0
Expand Down
19 changes: 19 additions & 0 deletions lib/modules/manager/pre-commit/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
matchesPrecommitDependencyHeuristic,
} from './parsing';
import type { PreCommitConfig } from './types';
import { pep508ToPackageDependency } from '../pep621/utils';

Check failure on line 16 in lib/modules/manager/pre-commit/extract.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../pep621/utils` import should occur before type import of `../types`

/**
* Determines the datasource(id) to be used for this dependency
Expand Down Expand Up @@ -136,6 +137,24 @@ function findDependencies(precommitFile: PreCommitConfig): PackageDependency[] {
return [];
}
const packageDependencies: PackageDependency[] = [];
precommitFile.repos.forEach((item) => {
if (item.repo !== 'meta') {
return;
}

item.hooks?.forEach((hook) => {
// normally language are not defined in yaml
// only support it when it's explicitly python
if (hook.language === 'python') {
hook.additional_dependencies?.map((req) => {
const dep = pep508ToPackageDependency('pre-commit-python', req);
if (dep) {
packageDependencies.push(dep);
}
});
}
});
});
precommitFile.repos.forEach((item) => {
if (matchesPrecommitDependencyHeuristic(item)) {
logger.trace(item, 'Matched pre-commit dependency spec');
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/pre-commit/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ export interface PreCommitConfig {
repos: PreCommitDependency[];
}

export interface PreCommitHook {
language?: 'python' | string;

Check failure on line 6 in lib/modules/manager/pre-commit/types.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

"python" is overridden by string in this union type.
additional_dependencies?: Array<string>;
}

export interface PreCommitDependency {
repo: string;
hooks?: Array<PreCommitHook>;
rev: string;
}

0 comments on commit f5e2ed5

Please sign in to comment.