Skip to content

Commit ab1bbbc

Browse files
authored
Merge pull request #507 from jacksgt/pr-editable
Handle all requirement flags properly and strip -e flags
2 parents b5cdf16 + 7726b2f commit ab1bbbc

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

lib/pip.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ function generateRequirementsFile(
6969
filterRequirementsFile(
7070
path.join(servicePath, '.serverless/requirements.txt'),
7171
targetFile,
72-
options
72+
options,
73+
serverless
7374
);
7475
serverless.cli.log(
7576
`Parsed requirements.txt from pyproject.toml in ${targetFile}...`
@@ -81,13 +82,14 @@ function generateRequirementsFile(
8182
filterRequirementsFile(
8283
path.join(servicePath, '.serverless/requirements.txt'),
8384
targetFile,
84-
options
85+
options,
86+
serverless
8587
);
8688
serverless.cli.log(
8789
`Parsed requirements.txt from Pipfile in ${targetFile}...`
8890
);
8991
} else {
90-
filterRequirementsFile(requirementsPath, targetFile, options);
92+
filterRequirementsFile(requirementsPath, targetFile, options, serverless);
9193
serverless.cli.log(
9294
`Generated requirements from ${requirementsPath} in ${targetFile}...`
9395
);
@@ -372,13 +374,13 @@ function getRequirements(source) {
372374
* assist with matching the static cache. The sorting will skip any
373375
* lines starting with -- as those are typically ordered at the
374376
* start of a file ( eg: --index-url / --extra-index-url ) or any
375-
* lines that start with -f or -i, Please see:
377+
* lines that start with -c, -e, -f, -i or -r, Please see:
376378
* https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
377379
* @param {string} source requirements
378380
* @param {string} target requirements where results are written
379381
* @param {Object} options
380382
*/
381-
function filterRequirementsFile(source, target, options) {
383+
function filterRequirementsFile(source, target, options, serverless) {
382384
const noDeploy = new Set(options.noDeploy || []);
383385
const requirements = getRequirements(source);
384386
var prepend = [];
@@ -389,10 +391,23 @@ function filterRequirementsFile(source, target, options) {
389391
return false;
390392
} else if (
391393
req.startsWith('--') ||
394+
req.startsWith('-c') ||
395+
req.startsWith('-e') ||
392396
req.startsWith('-f') ||
393-
req.startsWith('-i')
397+
req.startsWith('-i') ||
398+
req.startsWith('-r')
394399
) {
395-
// If we have options (prefixed with --) keep them for later
400+
if (req.startsWith('-e')) {
401+
// strip out editable flags
402+
// not required inside final archive and avoids pip bugs
403+
// see https://github.com/UnitedIncome/serverless-python-requirements/issues/240
404+
req = req.split('-e')[1].trim();
405+
serverless.cli.log(
406+
`Warning: Stripping -e flag from requirement ${req}`
407+
);
408+
}
409+
410+
// Keep options for later
396411
prepend.push(req);
397412
return false;
398413
} else if (req === '') {

test.js

+22
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ test(
376376
{ skip: !hasPython(3) }
377377
);
378378

379+
test(
380+
'py3.6 can package boto3 with editable',
381+
async t => {
382+
process.chdir('tests/base');
383+
const path = npm(['pack', '../..']);
384+
npm(['i', path]);
385+
sls([
386+
`--pythonBin=${getPythonBin(3)}`,
387+
'--fileName=requirements-w-editable.txt',
388+
'package'
389+
]);
390+
const zipfiles = await listZipFiles('.serverless/sls-py-req-test.zip');
391+
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
392+
t.true(
393+
zipfiles.includes(`botocore${sep}__init__.py`),
394+
'botocore is packaged'
395+
);
396+
t.end();
397+
},
398+
{ skip: !hasPython(3) }
399+
);
400+
379401
test(
380402
'py3.6 can package flask with dockerizePip option',
381403
async t => {
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-e git+https://github.com/boto/boto3.git#egg=boto3

0 commit comments

Comments
 (0)