Skip to content

Commit c024632

Browse files
authored
Merge branch 'master' into miketheman/update-eslint
2 parents ebc7d91 + f33c79a commit c024632

File tree

12 files changed

+179
-99
lines changed

12 files changed

+179
-99
lines changed
File renamed without changes.

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
```

lib/pip.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { spawnSync } = require('child_process');
77
const { quote } = require('shell-quote');
88
const { buildImage, getBindPath, getDockerUid } = require('./docker');
99
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
10+
const { isPoetryProject } = require('./poetry');
1011
const {
1112
checkForAndDeleteMaxCacheVersions,
1213
sha256Path,
@@ -62,7 +63,8 @@ function generateRequirementsFile(
6263
) {
6364
if (
6465
options.usePoetry &&
65-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
66+
fse.existsSync(path.join(servicePath, 'pyproject.toml')) &&
67+
isPoetryProject(servicePath)
6668
) {
6769
filterRequirementsFile(
6870
path.join(servicePath, '.serverless/requirements.txt'),
@@ -442,7 +444,9 @@ function copyVendors(vendorFolder, targetFolder, serverless) {
442444
function requirementsFileExists(servicePath, options, fileName) {
443445
if (
444446
options.usePoetry &&
445-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
447+
fse.existsSync(
448+
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
449+
)
446450
) {
447451
return true;
448452
}

lib/poetry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ function isPoetryProject(servicePath) {
9090
return false;
9191
}
9292

93-
module.exports = { pyprojectTomlToRequirements };
93+
module.exports = { pyprojectTomlToRequirements, isPoetryProject };

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
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": "^6.8.0",
48-
"prettier": "*",
48+
"prettier": "^1",
4949
"cross-spawn": "*",
5050
"deasync-promise": "*",
5151
"tape": "*"
@@ -75,7 +75,6 @@
7575
},
7676
"prettier": {
7777
"semi": true,
78-
"singleQuote": true,
79-
"parser": "babel"
78+
"singleQuote": true
8079
}
8180
}

0 commit comments

Comments
 (0)