From 1bb2ce3cbced72476fc01a4989e52a54b6cd4d2b Mon Sep 17 00:00:00 2001 From: Jack Henschel Date: Sun, 19 Apr 2020 13:26:24 +0300 Subject: [PATCH] Strip out all -e flags when processing requirements file Previously, there were various with installing editable packages in different python / pip versions. https://github.com/UnitedIncome/serverless-python-requirements/issues/240 This adds logic to strip out all '-e' editable flags from the requirements.txt file and issues a warning to the CLI. fixes #240 --- lib/pip.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/pip.js b/lib/pip.js index 4cacfcaa..38897a80 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -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}...` @@ -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}...` ); @@ -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 = []; @@ -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 === '') {