Skip to content

Commit aa5a335

Browse files
authored
Merge branch 'master' into miketheman/move-circle-config
2 parents 00b65cc + e118eff commit aa5a335

File tree

4 files changed

+92
-95
lines changed

4 files changed

+92
-95
lines changed

README.md

+54-50
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
A Serverless v1.x plugin to automatically bundle dependencies from
99
`requirements.txt` and make them available in your `PYTHONPATH`.
1010

11-
## Requires Serverless >= v1.34**
11+
## Requires Serverless >= v1.34
1212

1313
## Install
1414

@@ -145,8 +145,8 @@ bottle = {git = "ssh://[email protected]/bottlepy/bottle.git", tag = "0.12.16"}
145145

146146
To help deal with potentially large dependencies (for example: `numpy`, `scipy`
147147
and `scikit-learn`) there is support for compressing the libraries. This does
148-
require a minor change to your code to decompress them. To enable this add the
149-
following to your `serverless.yml`:
148+
require a minor change to your code to decompress them. To enable this add the
149+
following to your `serverless.yml`:
150150

151151
```yaml
152152
custom:
@@ -189,7 +189,7 @@ custom:
189189
pythonRequirements:
190190
slim: true
191191
slimPatterns:
192-
- "**/*.egg-info*"
192+
- '**/*.egg-info*'
193193
```
194194

195195
To overwrite the default patterns set the option `slimPatternsAppendDefaults` to `false` (`true` by default).
@@ -200,7 +200,7 @@ custom:
200200
slim: true
201201
slimPatternsAppendDefaults: false
202202
slimPatterns:
203-
- "**/*.egg-info*"
203+
- '**/*.egg-info*'
204204
```
205205

206206
This will remove all folders within the installed requirements that match
@@ -237,7 +237,7 @@ functions:
237237
hello:
238238
handler: handler.hello
239239
layers:
240-
- {Ref: PythonRequirementsLambdaLayer}
240+
- { Ref: PythonRequirementsLambdaLayer }
241241
```
242242

243243
If the layer requires additional or custom configuration, add them onto the `layer` option.
@@ -279,7 +279,7 @@ And second, a what we call "static caching" which caches output of pip after com
279279
Since generally `requirements.txt` files rarely change, you will often see large amounts of speed improvements when enabling the static cache feature.
280280
These caches will be shared between all your projects if no custom `cacheLocation` is specified (see below).
281281

282-
_**Please note:** This has replaced the previously recommended usage of "--cache-dir" in the pipCmdExtraArgs_
282+
_**Please note:** This has replaced the previously recommended usage of "--cache-dir" in the pipCmdExtraArgs_
283283

284284
```yaml
285285
custom:
@@ -290,7 +290,12 @@ custom:
290290

291291
### Other caching options
292292

293-
There are two additional options related to caching. You can specify where in your system that this plugin caches with the `cacheLocation` option. By default it will figure out automatically where based on your username and your OS to store the cache via the [appdirectory](https://www.npmjs.com/package/appdirectory) module. Additionally, you can specify how many max static caches to store with `staticCacheMaxVersions`, as a simple attempt to limit disk space usage for caching. This is DISABLED (set to 0) by default. Example:
293+
There are two additional options related to caching.
294+
You can specify where in your system that this plugin caches with the `cacheLocation` option.
295+
By default it will figure out automatically where based on your username and your OS to store the cache via the [appdirectory](https://www.npmjs.com/package/appdirectory) module.
296+
Additionally, you can specify how many max static caches to store with `staticCacheMaxVersions`, as a simple attempt to limit disk space usage for caching.
297+
This is DISABLED (set to 0) by default.
298+
Example:
294299

295300
```yaml
296301
custom:
@@ -299,7 +304,6 @@ custom:
299304
useDownloadCache: true
300305
cacheLocation: '/home/user/.my_cache_goes_here'
301306
staticCacheMaxVersions: 10
302-
303307
```
304308

305309
### Extra pip arguments
@@ -309,8 +313,8 @@ You can specify extra arguments [supported by pip](https://pip.pypa.io/en/stable
309313
```yaml
310314
custom:
311315
pythonRequirements:
312-
pipCmdExtraArgs:
313-
- --compile
316+
pipCmdExtraArgs:
317+
- --compile
314318
```
315319

316320
### Extra Docker arguments
@@ -321,8 +325,8 @@ You can specify extra arguments to be passed to [docker build](https://docs.dock
321325
custom:
322326
pythonRequirements:
323327
dockerizePip: true
324-
dockerBuildCmdExtraArgs: ["--build-arg", "MY_GREAT_ARG=123"]
325-
dockerRunCmdExtraArgs: ["-v", "${env:PWD}:/my-app"]
328+
dockerBuildCmdExtraArgs: ['--build-arg', 'MY_GREAT_ARG=123']
329+
dockerRunCmdExtraArgs: ['-v', '${env:PWD}:/my-app']
326330
```
327331

328332
### Customize requirements file name
@@ -372,10 +376,10 @@ the requirements for function2 in the second one.
372376

373377
Quick notes on the config file:
374378

375-
* The `module` field must be used to tell the plugin where to find the `requirements.txt` file for
376-
each function.
377-
* The `handler` field must not be prefixed by the folder name (already known through `module`) as
378-
the root of the zip artifact is already the path to your function.
379+
- The `module` field must be used to tell the plugin where to find the `requirements.txt` file for
380+
each function.
381+
- The `handler` field must not be prefixed by the folder name (already known through `module`) as
382+
the root of the zip artifact is already the path to your function.
379383

380384
### Customize Python executable
381385

@@ -431,16 +435,16 @@ custom:
431435
[Brew wilfully breaks the `--target` option with no seeming intention to fix it](https://github.com/Homebrew/brew/pull/821)
432436
which causes issues since this uses that option. There are a few easy workarounds for this:
433437

434-
* Install Python from [python.org](https://www.python.org/downloads/) and specify it with the
435-
[`pythonBin` option](#customize-python-executable).
438+
- Install Python from [python.org](https://www.python.org/downloads/) and specify it with the
439+
[`pythonBin` option](#customize-python-executable).
436440

437441
OR
438442

439-
* Create a virtualenv and activate it while using serverless.
443+
- Create a virtualenv and activate it while using serverless.
440444

441445
OR
442446

443-
* [Install Docker](https://docs.docker.com/docker-for-mac/install/) and use the [`dockerizePip` option](#cross-compiling).
447+
- [Install Docker](https://docs.docker.com/docker-for-mac/install/) and use the [`dockerizePip` option](#cross-compiling).
444448

445449
Also, [brew seems to cause issues with pipenv](https://github.com/dschep/lambda-decorators/issues/4#event-1418928080),
446450
so make sure you install pipenv using pip.
@@ -501,10 +505,10 @@ If you wish to exclude most of the files in your project, and only include the s
501505
package:
502506
individually: false
503507
include:
504-
- "./src/lambda_one/**"
505-
- "./src/lambda_two/**"
508+
- './src/lambda_one/**'
509+
- './src/lambda_two/**'
506510
exclude:
507-
- "**"
511+
- '**'
508512
```
509513

510514
This will be very slow. Serverless adds a default `"&ast;&ast;"` include. If you are using the `cacheLocation` parameter to this plugin, this will result in all of the cached files' names being loaded and then subsequently discarded because of the exclude pattern. To avoid this happening you can add a negated include pattern, as is observed in <https://github.com/serverless/serverless/pull/5825>.
@@ -515,37 +519,37 @@ Use this approach instead:
515519
package:
516520
individually: false
517521
include:
518-
- "!./**"
519-
- "./src/lambda_one/**"
520-
- "./src/lambda_two/**"
522+
- '!./**'
523+
- './src/lambda_one/**'
524+
- './src/lambda_two/**'
521525
exclude:
522-
- "**"
526+
- '**'
523527
```
524528

525529
## Contributors
526530

527-
* [@dschep](https://github.com/dschep) - Lead developer & maintainer
528-
* [@azurelogic](https://github.com/azurelogic) - logging & documentation fixes
529-
* [@abetomo](https://github.com/abetomo) - style & linting
530-
* [@angstwad](https://github.com/angstwad) - `deploy --function` support
531-
* [@mather](https://github.com/mather) - the cache invalidation option
532-
* [@rmax](https://github.com/rmax) - the extra pip args option
533-
* [@bsamuel-ui](https://github.com/bsamuel-ui) - Python 3 support
534-
* [@suxor42](https://github.com/suxor42) - fixing permission issues with Docker on Linux
535-
* [@mbeltran213](https://github.com/mbeltran213) - fixing docker linux -u option bug
536-
* [@Tethik](https://github.com/Tethik) - adding usePipenv option
537-
* [@miketheman](https://github.com/miketheman) - fixing bug with includes when using zip option
538-
* [@wattdave](https://github.com/wattdave) - fixing bug when using `deploymentBucket`
539-
* [@heri16](https://github.com/heri16) - fixing Docker support in Windows
540-
* [@ryansb](https://github.com/ryansb) - package individually support
541-
* [@cgrimal](https://github.com/cgrimal) - Private SSH Repo access in Docker, `dockerFile` option
531+
- [@dschep](https://github.com/dschep) - Lead developer & maintainer
532+
- [@azurelogic](https://github.com/azurelogic) - logging & documentation fixes
533+
- [@abetomo](https://github.com/abetomo) - style & linting
534+
- [@angstwad](https://github.com/angstwad) - `deploy --function` support
535+
- [@mather](https://github.com/mather) - the cache invalidation option
536+
- [@rmax](https://github.com/rmax) - the extra pip args option
537+
- [@bsamuel-ui](https://github.com/bsamuel-ui) - Python 3 support
538+
- [@suxor42](https://github.com/suxor42) - fixing permission issues with Docker on Linux
539+
- [@mbeltran213](https://github.com/mbeltran213) - fixing docker linux -u option bug
540+
- [@Tethik](https://github.com/Tethik) - adding usePipenv option
541+
- [@miketheman](https://github.com/miketheman) - fixing bug with includes when using zip option
542+
- [@wattdave](https://github.com/wattdave) - fixing bug when using `deploymentBucket`
543+
- [@heri16](https://github.com/heri16) - fixing Docker support in Windows
544+
- [@ryansb](https://github.com/ryansb) - package individually support
545+
- [@cgrimal](https://github.com/cgrimal) - Private SSH Repo access in Docker, `dockerFile` option
542546
to build a custom docker image, real per-function requirements, and the `vendor` option
543-
* [@kichik](https://github.com/kichik) - Imposed windows & `noDeploy` support,
547+
- [@kichik](https://github.com/kichik) - Imposed windows & `noDeploy` support,
544548
switched to adding files straight to zip instead of creating symlinks, and
545549
improved pip cache support when using docker.
546-
* [@dee-me-tree-or-love](https://github.com/dee-me-tree-or-love) - the `slim` package option
547-
* [@alexjurkiewicz](https://github.com/alexjurkiewicz) - [docs about docker workflows](#native-code-dependencies-during-build)
548-
* [@andrewfarley](https://github.com/andrewfarley) - Implemented download caching and static caching
549-
* [@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!
550-
* [@squaresurf](https://github.com/squaresurf) - adding usePoetry option
551-
* [@david-mk-lawrence](https://github.com/david-mk-lawrence) - added Lambda Layer support
550+
- [@dee-me-tree-or-love](https://github.com/dee-me-tree-or-love) - the `slim` package option
551+
- [@alexjurkiewicz](https://github.com/alexjurkiewicz) - [docs about docker workflows](#native-code-dependencies-during-build)
552+
- [@andrewfarley](https://github.com/andrewfarley) - Implemented download caching and static caching
553+
- [@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!
554+
- [@squaresurf](https://github.com/squaresurf) - adding usePoetry option
555+
- [@david-mk-lawrence](https://github.com/david-mk-lawrence) - added Lambda Layer support

example_native_deps/README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
### native compilation example
1+
# Native compilation example
2+
23
Uses `dockerizePip` to deploy numpy-scipy-sklearn demo.
34

4-
### test
5+
## Test
6+
57
As in other examples, use node version >= 6.
68

7-
```
9+
```bash
810
cd example_native_deps
911
npm install --prefix . serverless-python-requirements
1012
sls deploy --verbose
@@ -13,10 +15,10 @@ sls invoke -f hello --verbose --log
1315

1416
...expected result:
1517

16-
```
18+
```json
1719
{
18-
"numpy": "1.13.3",
19-
"scipy": "1.0.0",
20-
"sklearn": "0.19.1"
20+
"numpy": "1.13.3",
21+
"scipy": "1.0.0",
22+
"sklearn": "0.19.1"
2123
}
2224
```

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"main": "index.js",
3939
"bin": {},
4040
"scripts": {
41-
"ci:lint": "eslint *.js lib/*.js --format junit --output-file ~/reports/eslint.xml && prettier -c index.js lib/*.js",
41+
"ci:lint": "eslint *.js lib/*.js --format junit --output-file ~/reports/eslint.xml && prettier -c '{.,lib}/*.{js,md}'",
4242
"test": "node test.js",
43-
"lint": "eslint *.js lib/*.js && prettier -l index.js lib/*.js || (echo need formatting ; exit 1)",
44-
"format": "prettier --write index.js lib/*.js test.js"
43+
"lint": "eslint *.js lib/*.js && prettier -c '{.,lib}/*.{js,md}'",
44+
"format": "prettier --write '{.,lib}/*.{js,md}'"
4545
},
4646
"devDependencies": {
4747
"eslint": "^5.16.0",
@@ -75,7 +75,6 @@
7575
},
7676
"prettier": {
7777
"semi": true,
78-
"singleQuote": true,
79-
"parser": "babel"
78+
"singleQuote": true
8079
}
8180
}

test.js

+25-33
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ test('py3.6 packages have the same hash', t => {
140140
sls(['package']);
141141
const fileHash = sha256File('.serverless/sls-py-req-test.zip');
142142
sls(['package']);
143-
t.equal(sha256File('.serverless/sls-py-req-test.zip'), fileHash, 'packages have the same hash');
143+
t.equal(
144+
sha256File('.serverless/sls-py-req-test.zip'),
145+
fileHash,
146+
'packages have the same hash'
147+
);
144148
t.end();
145149
});
146150

@@ -271,10 +275,7 @@ test(
271275

272276
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
273277
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
274-
t.true(
275-
zipfiles.includes(`boto3${sep}__init__.py`),
276-
'boto3 is packaged'
277-
);
278+
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
278279
t.end();
279280
},
280281
{ skip: !canUseDocker() }
@@ -652,7 +653,10 @@ test('pipenv py3.6 can package flask with default options', t => {
652653
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
653654
t.true(zipfiles.includes(`flask${sep}__init__.py`), 'flask is packaged');
654655
t.true(zipfiles.includes(`boto3${sep}__init__.py`), 'boto3 is packaged');
655-
t.false(zipfiles.includes(`pytest${sep}__init__.py`), 'dev-package pytest is NOT packaged');
656+
t.false(
657+
zipfiles.includes(`pytest${sep}__init__.py`),
658+
'dev-package pytest is NOT packaged'
659+
);
656660
t.end();
657661
});
658662

@@ -1617,8 +1621,11 @@ test(
16171621
'foobar has retained its executable file permissions'
16181622
);
16191623

1620-
const zipfiles_hello2 = listZipFilesWithMetaData('.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip');
1621-
const flaskPerm = statSync('.serverless/module2/requirements/bin/flask').mode;
1624+
const zipfiles_hello2 = listZipFilesWithMetaData(
1625+
'.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip'
1626+
);
1627+
const flaskPerm = statSync('.serverless/module2/requirements/bin/flask')
1628+
.mode;
16221629

16231630
t.true(
16241631
zipfiles_hello2['bin/flask'].unixPermissions === flaskPerm,
@@ -1651,8 +1658,11 @@ test(
16511658
'foobar has retained its executable file permissions'
16521659
);
16531660

1654-
const zipfiles_hello2 = listZipFilesWithMetaData('.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip');
1655-
const flaskPerm = statSync('.serverless/module2/requirements/bin/flask').mode;
1661+
const zipfiles_hello2 = listZipFilesWithMetaData(
1662+
'.serverless/module2-sls-py-req-test-indiv-dev-hello2.zip'
1663+
);
1664+
const flaskPerm = statSync('.serverless/module2/requirements/bin/flask')
1665+
.mode;
16561666

16571667
t.true(
16581668
zipfiles_hello2['bin/flask'].unixPermissions === flaskPerm,
@@ -1681,10 +1691,7 @@ test('py3.6 uses download cache by defaul option', t => {
16811691
process.chdir('tests/base');
16821692
const path = npm(['pack', '../..']);
16831693
npm(['i', path]);
1684-
sls([
1685-
'--cacheLocation=.requirements-cache',
1686-
'package'
1687-
]);
1694+
sls(['--cacheLocation=.requirements-cache', 'package']);
16881695
t.true(
16891696
pathExistsSync(`.requirements-cache${sep}downloadCacheslspyc${sep}http`),
16901697
'cache directoy exists'
@@ -1753,10 +1760,7 @@ test(
17531760
process.chdir('tests/base');
17541761
const path = npm(['pack', '../..']);
17551762
npm(['i', path]);
1756-
sls([
1757-
'--dockerizePip=true',
1758-
'package'
1759-
]);
1763+
sls(['--dockerizePip=true', 'package']);
17601764
const cachepath = getUserCachePath();
17611765
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
17621766
t.true(
@@ -1832,11 +1836,7 @@ test(
18321836
process.chdir('tests/base');
18331837
const path = npm(['pack', '../..']);
18341838
npm(['i', path]);
1835-
sls([
1836-
'--dockerizePip=true',
1837-
'--slim=true',
1838-
'package'
1839-
]);
1839+
sls(['--dockerizePip=true', '--slim=true', 'package']);
18401840
const cachepath = getUserCachePath();
18411841
const cacheFolderHash = sha256Path('.serverless/requirements.txt');
18421842
t.true(
@@ -1855,11 +1855,7 @@ test(
18551855
`${cachepath}${sep}${cacheFolderHash}_slspyc${sep}injected_file_is_bad_form`,
18561856
'injected new file into static cache folder'
18571857
);
1858-
sls([
1859-
'--dockerizePip=true',
1860-
'--slim=true',
1861-
'package'
1862-
]);
1858+
sls(['--dockerizePip=true', '--slim=true', 'package']);
18631859

18641860
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
18651861
t.true(
@@ -1883,11 +1879,7 @@ test(
18831879
process.chdir('tests/base');
18841880
const path = npm(['pack', '../..']);
18851881
npm(['i', path]);
1886-
sls([
1887-
'--dockerizePip=true',
1888-
'--slim=true',
1889-
'package'
1890-
]);
1882+
sls(['--dockerizePip=true', '--slim=true', 'package']);
18911883
const cachepath = getUserCachePath();
18921884
t.true(
18931885
pathExistsSync(`${cachepath}${sep}downloadCacheslspyc${sep}http`),

0 commit comments

Comments
 (0)