Skip to content

Commit b4ecc43

Browse files
AndrewFarleydschep
authored andcommitted
Adding -f and -i to requirements.txt options ignore list before sorting (#238)
Fixes: #236 (again, properly) Problem: requirements.txt options which must be in the proper order at the start of the file were being sorted. This properly skips sorting them and keeps them in order they were.
1 parent 8a32692 commit b4ecc43

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/pip.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ function dockerPathForWin(options, path) {
281281
* then remove all comments and empty lines, and sort the list which
282282
* assist with matching the static cache. The sorting will skip any
283283
* lines starting with -- as those are typically ordered at the
284-
* start of a file ( eg: --index-url / --extra-index-url )
284+
* start of a file ( eg: --index-url / --extra-index-url ) or any
285+
* lines that start with -f or -i, Please see:
286+
* https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
285287
* @param {string} source requirements
286288
* @param {string} target requirements where results are written
287289
* @param {Object} options
@@ -297,7 +299,11 @@ function generateRequirementsFile(source, target, options) {
297299
if (req.startsWith('#')) {
298300
// Skip comments
299301
return false;
300-
} else if (req.startsWith('--')) {
302+
} else if (
303+
req.startsWith('--') ||
304+
req.startsWith('-f') ||
305+
req.startsWith('-i')
306+
) {
301307
// If we have options (prefixed with --) keep them for later
302308
prepend.push(req);
303309
return false;
@@ -309,7 +315,9 @@ function generateRequirementsFile(source, target, options) {
309315
filteredRequirements.sort(); // Sort remaining alphabetically
310316
// Then prepend any options from above in the same order
311317
for (let item of prepend.reverse()) {
312-
filteredRequirements.unshift(item);
318+
if (item && item.length > 0) {
319+
filteredRequirements.unshift(item);
320+
}
313321
}
314322
fse.writeFileSync(target, filteredRequirements.join('\n') + '\n');
315323
}

0 commit comments

Comments
 (0)