renovate/lib/manager/pip_requirements/extract.js
Ayoub Kaanich c8ae853d58 feat: python requirements.txt support (#1858)
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.
2018-04-28 20:39:07 +02:00

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);
}