Skip to content

Bugfix for requirements.txt options ordering #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ function dockerPathForWin(options, path) {

/** create a filtered requirements.txt without anything from noDeploy
* then remove all comments and empty lines, and sort the list which
* assist with matching the static cache
* 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 )
* @param {string} source requirements
* @param {string} target requirements where results are written
* @param {Object} options
Expand All @@ -277,14 +279,24 @@ function generateRequirementsFile(source, target, options) {
const requirements = fse
.readFileSync(source, { encoding: 'utf-8' })
.split(/\r?\n/);
var prepend = [];
const filteredRequirements = requirements.filter(req => {
req = req.trim();
if (req.length == 0 || req[0] == '#') {
if (req.startsWith('#')) {
// Skip comments
return false;
} else if (req.startsWith('--')) {
// If we have options (prefixed with --) keep them for later
prepend.push(req);
return false;
}
return !noDeploy.has(req.split(/[=<> \t]/)[0].trim());
});
filteredRequirements.sort(); // Sort them alphabetically
filteredRequirements.sort(); // Sort remaining alphabetically
// Then prepend any options from above in the same order
for (let item of prepend.reverse()) {
filteredRequirements.unshift(item);
}
fse.writeFileSync(target, filteredRequirements.join('\n'));
}

Expand Down