Skip to content
Snippets Groups Projects
Unverified Commit 235951a1 authored by Norbert Szulc's avatar Norbert Szulc Committed by GitHub
Browse files

feat(manager/pip-compile): Create wrapper for pip extractPackageFile (#27154)

parent 4899c375
No related branches found
No related tags found
No related merge requests found
import { Fixtures } from '../../../../test/fixtures';
import { extractPackageFile } from '.';
jest.mock('../../../util/fs');
describe('modules/manager/pip-compile/extract', () => {
describe('extractPackageFile()', () => {
it('returns object for requirements.in', () => {
const packageFile = extractPackageFile(
Fixtures.get('requirementsWithHashes.txt'),
'requirements.in',
{},
);
expect(packageFile).toHaveProperty('deps');
expect(packageFile?.deps[0]).toHaveProperty('depName', 'attrs');
});
it.each([
'random.py',
'app.cfg',
'already_locked.txt',
// TODO(not7cd)
'pyproject.toml',
'setup.py',
'setup.cfg',
])('returns null on not supported package files', (file: string) => {
expect(extractPackageFile('some content', file, {})).toBeNull();
});
});
});
import { logger } from '../../../logger';
import { extractPackageFile as extractRequirementsFile } from '../pip_requirements/extract';
// TODO(not7cd): enable in the next PR, when this can be properly tested
// import { extractPackageFile as extractSetupPyFile } from '../pip_setup';
// import { extractPackageFile as extractSetupCfgFile } from '../setup-cfg';
import type { ExtractConfig, PackageFileContent } from '../types';
import type { SupportedManagers } from './types';
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,
_config: ExtractConfig,
): PackageFileContent | null {
logger.trace('pip-compile.extractPackageFile()');
const manager = matchManager(packageFile);
// TODO(not7cd): extract based on manager: pep621, setuptools, identify other missing source types
switch (manager) {
// TODO(not7cd): enable in the next PR, when this can be properly tested
// case 'pip_setup':
// return extractSetupPyFile(content, _packageFile, _config);
// case 'setup-cfg':
// return await extractSetupCfgFile(content);
case 'pip_requirements':
return extractRequirementsFile(content);
case 'unknown':
logger.warn(
{ packageFile },
`pip-compile: could not determine manager for source file, fallback to pip_requirements`,
);
return extractRequirementsFile(content);
default:
logger.warn(
{ packageFile, manager },
`pip-compile: support for manager is not yet implemented`,
);
return null;
}
}
...@@ -2,7 +2,7 @@ import type { Category } from '../../../constants'; ...@@ -2,7 +2,7 @@ import type { Category } from '../../../constants';
import { GitTagsDatasource } from '../../datasource/git-tags'; import { GitTagsDatasource } from '../../datasource/git-tags';
import { PypiDatasource } from '../../datasource/pypi'; import { PypiDatasource } from '../../datasource/pypi';
export { extractPackageFile } from '../pip_requirements/extract'; export { extractPackageFile } from './extract';
export { updateArtifacts } from './artifacts'; export { updateArtifacts } from './artifacts';
export const supportsLockFileMaintenance = true; export const supportsLockFileMaintenance = true;
......
// managers supported by pip-tools Python package
export type SupportedManagers =
| 'pip_requirements'
| 'pip_setup'
| 'setup-cfg'
| 'pep621';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment