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

refactor(pip-compile): Move matchManager to common.ts #29359

Merged
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
20 changes: 20 additions & 0 deletions lib/modules/manager/pip-compile/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
extractHeaderCommand,
extractPythonVersion,
getRegistryCredVarsFromPackageFile,
matchManager,
} from './common';
import { inferCommandExecDir } from './utils';

Expand Down Expand Up @@ -283,4 +284,23 @@ describe('modules/manager/pip-compile/common', () => {
).toEqual({});
});
});

describe('matchManager()', () => {
it('matches pip_setup setup.py', () => {
expect(matchManager('setup.py')).toBe('pip_setup');
});

it('matches setup-cfg setup.cfg', () => {
expect(matchManager('setup.cfg')).toBe('setup-cfg');
});

it('matches pep621 pyproject.toml', () => {
expect(matchManager('pyproject.toml')).toBe('pep621');
});

it('matches pip_requirements any .in file', () => {
expect(matchManager('file.in')).toBe('pip_requirements');
expect(matchManager('another_file.in')).toBe('pip_requirements');
});
});
});
19 changes: 18 additions & 1 deletion lib/modules/manager/pip-compile/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ensureLocalPath } from '../../../util/fs/util';
import * as hostRules from '../../../util/host-rules';
import { regEx } from '../../../util/regex';
import type { PackageFileContent, UpdateArtifactsConfig } from '../types';
import type { PipCompileArgs } from './types';
import type { PipCompileArgs, SupportedManagers } from './types';

export function getPythonVersionConstraint(
config: UpdateArtifactsConfig,
Expand Down Expand Up @@ -304,3 +304,20 @@ export function getRegistryCredVarsFromPackageFile(

return allCreds;
}

export function matchManager(filename: string): SupportedManagers | 'unknown' {
if (filename.endsWith('setup.py')) {
return 'pip_setup';
}
if (filename.endsWith('setup.cfg')) {
return 'setup-cfg';
}
if (filename.endsWith('pyproject.toml')) {
return 'pep621';
}
// naive, could be improved, maybe use pip_requirements.fileMatch
if (filename.endsWith('.in')) {
return 'pip_requirements';
}
return 'unknown';
}
25 changes: 2 additions & 23 deletions lib/modules/manager/pip-compile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,14 @@ import type {
PackageFile,
PackageFileContent,
} from '../types';
import { extractHeaderCommand } from './common';
import type {
DependencyBetweenFiles,
PipCompileArgs,
SupportedManagers,
} from './types';
import { extractHeaderCommand, matchManager } from './common';
import type { DependencyBetweenFiles, PipCompileArgs } from './types';
import {
generateMermaidGraph,
inferCommandExecDir,
sortPackageFiles,
} from './utils';

function matchManager(filename: string): SupportedManagers | 'unknown' {
if (filename.endsWith('setup.py')) {
return 'pip_setup';
}
if (filename.endsWith('setup.cfg')) {
return 'setup-cfg';
}
if (filename.endsWith('pyproject.toml')) {
return 'pep621';
}
// naive, could be improved, maybe use pip_requirements.fileMatch
if (filename.endsWith('.in')) {
return 'pip_requirements';
}
return 'unknown';
}

export function extractPackageFile(
content: string,
packageFile: string,
Expand Down