Skip to content

Handle all requirement flags properly and strip -e flags #507

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
Oct 2, 2020
Merged
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
29 changes: 22 additions & 7 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 @@ -372,13 +374,13 @@ function getRequirements(source) {
* 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:
* lines that start with -c, -e, -f, -i or -r, Please see:
* https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
* @param {string} source requirements
* @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 @@ -389,10 +391,23 @@ function filterRequirementsFile(source, target, options) {
return false;
} else if (
req.startsWith('--') ||
req.startsWith('-c') ||
req.startsWith('-e') ||
req.startsWith('-f') ||
req.startsWith('-i')
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
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,28 @@ test(
{ skip: !hasPython(3) }
);

test(
'py3.6 can package boto3 with editable',
async t => {
process.chdir('tests/base');
const path = npm(['pack', '../..']);
npm(['i', path]);
sls([
`--pythonBin=${getPythonBin(3)}`,
'--fileName=requirements-w-editable.txt',
'package'
]);
const zipfiles = await listZipFiles('.serverless/sls-py-req-test.zip');
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
t.true(
zipfiles.includes(`botocore${sep}__init__.py`),
'botocore is packaged'
);
t.end();
},
{ skip: !hasPython(3) }
);

test(
'py3.6 can package flask with dockerizePip option',
async t => {
Expand Down
1 change: 1 addition & 0 deletions tests/base/requirements-w-editable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e git+https://github.com/boto/boto3.git#egg=boto3