Skip to content
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

Automatic add to sys.path!! closes #1 #9

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 8 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
[![npm](https://nodei.co/npm/serverless-python-requirements.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/serverless-python-requirements)

A Serverless v1.0 plugin to automatically bundle dependencies from
`requirements.txt`.
`requirements.txt` and makes them available in your `PYTHONPATH`.


## Install
@@ -22,17 +22,10 @@ plugins:
```


## Adding the dependencies to `sys.path`
## How serverless-python-requirements adds the dependencies to `sys.path`

`serverless-python-requirements` adds a module called `requirements` to your
puck. To easily make the bundled dependencies available, simply import it. Eg.
add this to the top of any file using dependencies specified in your
`requirements.txt`:
```python
import requirements
# Now you can use deps you specified in requirements.txt!
import requests
```
`serverless-python-requirements` adds a module called `sitecustomize` to your
puck, which is imported automatically by Python's `site` module.

## Cross compiling!
Compiling non-pure-Python modules is supported on MacOS via the use of Docker
@@ -58,15 +51,15 @@ custom:

## Limitations
* if using the `package` directive in `serverless.yml` ensure that
`requirements.py` is are included as well as `.requirements` or
`sitecustomize.py` is are included as well as `.requirements` or
`.requirements.zip` if using [ZipImport](#zipimport).


## Manual invocations

The `.requirements` and `requirements.py` files are left behind to simplify
development. To clean them up, run `sls requirements clean`. You can also
install them manually for local development with `sls requirements install`.
The `.requirements` and `sitecustomize.py` files are left behind to speed up
subsequent deployments. To clean them up, run `sls requirements clean`. You can
also install them manually with `sls requirements install`.

## Credit
This plugin is influenced by
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ class ServerlessPythonRequirements {
this.serverless.cli.log('Packaging Python requirements helper...');

return fse.copyAsync(
path.resolve(__dirname, 'requirements.py'),
path.join(this.serverless.config.servicePath, 'requirements.py'));
path.resolve(__dirname, 'sitecustomize.py'),
path.join(this.serverless.config.servicePath, 'sitecustomize.py'));
};

installRequirements() {
@@ -66,7 +66,7 @@ class ServerlessPythonRequirements {
}

cleanup() {
const artifacts = ['requirements.py'];
const artifacts = ['sitecustomize.py'];
if (this.custom.zipImport)
artifacts.push('.requirements.zip')
else
@@ -99,7 +99,7 @@ class ServerlessPythonRequirements {
'requirements': {
commands: {
'clean': {
usage: 'Remove .requirements and requirements.py',
usage: 'Remove .requirements, .requirements.zip and sitecustomize.py',
lifecycleEvents: [
'clean',
],
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-python-requirements",
"version": "1.2.0",
"version": "2.0.0",
"engines": {
"node": ">=4.0"
},
@@ -31,7 +31,7 @@
"index.js",
"LICENSE",
"package.json",
"requirements.py",
"sitecustomize.py",
"README.md"
],
"main": "index.js",
File renamed without changes.