mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
c8ae853d58
This PR adds basic support for requirements.txt. Currently it works on fully specified (pinned) versions only, so is disabled by default. Enable it by setting `pip_requirements.enabled = true` in config.
32 lines
950 B
JavaScript
32 lines
950 B
JavaScript
// based on https://www.python.org/dev/peps/pep-0508/#names
|
|
const packagePattern = '([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9])';
|
|
|
|
module.exports = {
|
|
packagePattern,
|
|
extractDependencies,
|
|
};
|
|
|
|
function extractDependencies(fileContent) {
|
|
logger.debug('pip_requirements.extractDependencies()');
|
|
// TODO: for now we only support semver, but we need better support for python versions
|
|
// see https://github.com/pypa/packaging/blob/master/packaging/version.py
|
|
// see https://www.python.org/dev/peps/pep-0440/#version-epochs
|
|
const regex = new RegExp(
|
|
`^${packagePattern}==([0-9]+\\.[0-9]+\\.[0-9]+)$`,
|
|
'g'
|
|
);
|
|
return fileContent
|
|
.split('\n')
|
|
.map((line, lineNumber) => {
|
|
const matches = regex.exec(line);
|
|
return (
|
|
matches && {
|
|
depName: matches[1],
|
|
depType: 'python',
|
|
currentVersion: matches[2],
|
|
lineNumber,
|
|
}
|
|
);
|
|
})
|
|
.filter(Boolean);
|
|
}
|