diff --git a/lib/pip.js b/lib/pip.js index da4dd059..d5017e28 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -281,7 +281,9 @@ function dockerPathForWin(options, path) { * then remove all comments and empty lines, and sort the list which * assist with matching the static cache. The sorting will skip any * lines starting with -- as those are typically ordered at the - * start of a file ( eg: --index-url / --extra-index-url ) + * start of a file ( eg: --index-url / --extra-index-url ) or any + * lines that start with -f or -i, Please see: + * https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format * @param {string} source requirements * @param {string} target requirements where results are written * @param {Object} options @@ -297,7 +299,11 @@ function generateRequirementsFile(source, target, options) { if (req.startsWith('#')) { // Skip comments return false; - } else if (req.startsWith('--')) { + } else if ( + req.startsWith('--') || + req.startsWith('-f') || + req.startsWith('-i') + ) { // If we have options (prefixed with --) keep them for later prepend.push(req); return false; @@ -309,7 +315,9 @@ function generateRequirementsFile(source, target, options) { filteredRequirements.sort(); // Sort remaining alphabetically // Then prepend any options from above in the same order for (let item of prepend.reverse()) { - filteredRequirements.unshift(item); + if (item && item.length > 0) { + filteredRequirements.unshift(item); + } } fse.writeFileSync(target, filteredRequirements.join('\n') + '\n'); }