Skip to content

No longer sort generated requriements.txt file #481

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

Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,4 @@ package:
- [@bweigel](https://github.com/bweigel) - adding the `slimPatternsAppendDefaults` option & fixing per-function packaging when some functions don't have requirements & Porting tests from bats to js!
- [@squaresurf](https://github.com/squaresurf) - adding usePoetry option
- [@david-mk-lawrence](https://github.com/david-mk-lawrence) - added Lambda Layer support

26 changes: 4 additions & 22 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,45 +366,27 @@ function getRequirements(source) {
}

/** 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. 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 ) or any
* lines that start with -f or -i, Please see:
* https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
* then remove all comments and empty lines. NOTE: In contrast to how
* this function used to work, it no longer re-orders requirements.txt
* contents to preserve ordering-related issues. See:
* https://pip.pypa.io/en/stable/reference/pip_install/#installation-order
* @param {string} source requirements
* @param {string} target requirements where results are written
* @param {Object} options
*/
function filterRequirementsFile(source, target, options) {
const noDeploy = new Set(options.noDeploy || []);
const requirements = getRequirements(source);
var prepend = [];
const filteredRequirements = requirements.filter(req => {
req = req.trim();
if (req.startsWith('#')) {
// Skip comments
return false;
} 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;
} else if (req === '') {
return false;
}
return !noDeploy.has(req.split(/[=<> \t]/)[0].trim());
});
filteredRequirements.sort(); // Sort remaining alphabetically
// Then prepend any options from above in the same order
for (let item of prepend.reverse()) {
if (item && item.length > 0) {
filteredRequirements.unshift(item);
}
}
fse.writeFileSync(target, filteredRequirements.join('\n') + '\n');
}

Expand Down