Skip to content

Commit

Permalink
Strip out all -e flags when processing requirements file
Browse files Browse the repository at this point in the history
Previously, there were various with installing editable packages in
different python / pip versions.
serverless#240

This adds logic to strip out all '-e' editable flags from the
requirements.txt file and issues a warning to the CLI.

fixes serverless#240
  • Loading branch information
jacksgt committed Oct 2, 2020
1 parent 632f389 commit 1bb2ce3
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function generateRequirementsFile(
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
options,
serverless
);
serverless.cli.log(
`Parsed requirements.txt from pyproject.toml in ${targetFile}...`
Expand All @@ -81,13 +82,14 @@ function generateRequirementsFile(
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
targetFile,
options
options,
serverless
);
serverless.cli.log(
`Parsed requirements.txt from Pipfile in ${targetFile}...`
);
} else {
filterRequirementsFile(requirementsPath, targetFile, options);
filterRequirementsFile(requirementsPath, targetFile, options, serverless);
serverless.cli.log(
`Generated requirements from ${requirementsPath} in ${targetFile}...`
);
Expand Down Expand Up @@ -378,7 +380,7 @@ function getRequirements(source) {
* @param {string} target requirements where results are written
* @param {Object} options
*/
function filterRequirementsFile(source, target, options) {
function filterRequirementsFile(source, target, options, serverless) {
const noDeploy = new Set(options.noDeploy || []);
const requirements = getRequirements(source);
var prepend = [];
Expand All @@ -395,7 +397,15 @@ function filterRequirementsFile(source, target, options) {
req.startsWith('-i') ||
req.startsWith('-r')
) {
// If we have options (prefixed with --) keep them for later
if (req.startsWith('-e')) {
// strip out editable flags
// not required inside final archive and avoids pip bugs
// see https://github.com/UnitedIncome/serverless-python-requirements/issues/240
req = req.split('-e')[1].trim();
serverless.cli.log(`Warning: Stripping -e flag from requirement ${req}`);
}

// Keep options for later
prepend.push(req);
return false;
} else if (req === '') {
Expand Down

0 comments on commit 1bb2ce3

Please sign in to comment.