Skip to content

Commit 8dda026

Browse files
authored
Merge pull request #6 from 4dn-dcic/kmp_poetryfest
Put python-lambda under poetry (still as a beta).
2 parents 420c530 + 00a5fb9 commit 8dda026

14 files changed

Lines changed: 543 additions & 35 deletions

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __pycache__/
88

99
# Distribution / packaging
1010
.Python
11-
env/
11+
*env/
1212
build/
1313
develop-eggs/
1414
dist/
@@ -57,3 +57,10 @@ docs/_build/
5757

5858
# PyBuilder
5959
target/
60+
61+
# PyCharm
62+
.idea/
63+
64+
# Emacs backup files
65+
*~
66+

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ sudo: false
33
python:
44
- '3.6'
55
install:
6-
- pip install -r requirements.txt
7-
- pip install -r dev-requirements.txt
6+
- pip install --upgrade pip==19.0.3
7+
- pip install poetry
8+
- poetry install
89
- pip install coveralls
910
script:
1011
- pytest --cov aws_lambda -v tests

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,24 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
22+
23+
================================================================================
24+
Portions of this software are based in part on the work of Nick Ficano.
25+
Use that earlier work requires inclusion of this additional notice,
26+
which continues to apply to those portions:
27+
28+
ISC License
29+
30+
Copyright (c) 2016, Nick Ficano
31+
32+
Permission to use, copy, modify, and/or distribute this software for any
33+
purpose with or without fee is hereby granted, provided that the above
34+
copyright notice and this permission notice appear in all copies.
35+
36+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ lint:
2626
flake8 python-lambda tests
2727

2828
release: clean
29-
python setup.py sdist upload
30-
python setup.py bdist_wheel upload
29+
poetry publish
3130

3231
install: clean
33-
python setup.py install
32+
poetry install

README.rst

Lines changed: 101 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
========
2-
python-λ
3-
========
1+
=================
2+
python-lambda-4dn
3+
=================
44

5+
(python-λ forked for 4DN-DCIC projects)
6+
---------------------------------------
57

6-
.. image:: https://img.shields.io/pypi/v/python-lambda.svg
8+
9+
.. image:: https://img.shields.io/pypi/v/python-lambda-4dn.svg
710
:alt: Pypi
8-
:target: https://pypi.python.org/pypi/python-lambda/
11+
:target: https://pypi.python.org/pypi/python-lambda-4dn/
912

1013
.. image:: https://travis-ci.org/4dn-dcic/python-lambda.svg?branch=master
1114
:alt: Build Status
@@ -15,34 +18,88 @@ python-λ
1518
:alt: Coverage
1619
:target: https://coveralls.io/github/4dn-dcic/python-lambda?branch=master
1720

18-
Python-lambda is a toolset for developing and deploying *serverless* Python code in AWS Lambda.
21+
This is a toolset for developing and deploying *serverless* Python code in AWS Lambda.
22+
23+
.. Important::
1924

20-
Important
21-
=======================
22-
This is a FORK of the original Python-lambda package by Nick Ficano.
23-
It will NOT be updated regularly and is frozen per our projects needs.
25+
This is a FORK of Nick Ficano's `Python-lambda <https://pypi.python.org/pypi/python-lambda>`_
26+
package. It will NOT be updated regularly and is frozen for the needs of projects at the
27+
`4D Nucleome Data Coordination and Integration Center (4DN-DCIC)
28+
<https://github.com/4dn-dcic>`_.
2429

2530
Description
2631
===========
2732

28-
AWS Lambda is a service that allows you to write Python, Java, or Node.js code that gets executed in response to events like http requests or files uploaded to S3.
33+
AWS Lambda is a service that allows you to write Python, Java, or Node.js code that
34+
gets executed in response to events like http requests or files uploaded to S3.
35+
36+
Working with Lambda is relatively easy, but the process of bundling and deploying your code
37+
is not as simple as it could be.
38+
39+
The *Python-Lambda* library takes away the guess work of developing your Python-Lambda
40+
services by providing you a toolset to streamline the annoying parts.
41+
42+
Important Legal Notice
43+
======================
2944

30-
Working with Lambda is relatively easy, but the process of bundling and deploying your code is not as simple as it could be.
45+
The original `Python-lambda <https://pypi.python.org/pypi/python-lambda>`_ is licensed under
46+
an ISC license. `The version of that license active at time of the fork is here
47+
<https://github.com/nficano/python-lambda/blob/01f1b8c3651de4e772618851b2117277ca95b1b4/LICENSE>`_.
48+
Github's summary of that license describes it as:
3149

32-
The *Python-Lambda* library takes away the guess work of developing your Python-Lambda services by providing you a toolset to streamline the annoying parts.
50+
A permissive license lets people do anything with your code with proper attribution
51+
and without warranty. The ISC license is functionally equivalent to the BSD 2-Clause
52+
and MIT licenses, removing some language that is no longer necessary.
3353

34-
Requirements
35-
============
54+
Since our derivative work is covered under the MIT license, and on a theory
55+
that the underlying license is equivalent to the MIT license,
56+
we shorthand our licensing requirements as just "MIT" because that's more consistent
57+
with how we describe licensing for other 4DN-DCIC software.
58+
However, for the properly formal legal detail,
59+
please refer to our actual `LICENSE <LICENSE>`_.
60+
61+
System Requirements
62+
===================
3663

3764
* Python 3.6
3865
* Pip (Any should work)
3966
* Virtualenv (>=15.0.0)
40-
* Virtualenvwrapper (>=4.7.1)
67+
68+
Setting Up a Virtual Environment (OPTIONAL)
69+
===========================================
70+
71+
This is optional.
72+
If you do not create a virtual environment, Poetry will make one for you.
73+
But there are still good reasons you might want to make your own, so here
74+
are three ways to do it:
75+
76+
* If you have virtualenvwrapper that knows to use Python 3.6::
77+
78+
mkvirtualenv myenv
79+
80+
* If you have virtualenv but not virtualenvwrapper, and you have python3.6 in your ``PATH``::
81+
82+
virtualenv myenv -p python3.6
83+
84+
* If you are using ``pyenv`` to control what environment you use::
85+
86+
pyenv exec python -m venv myenv
87+
88+
89+
Installing Poetry in a Virtual Environment
90+
==========================================
91+
92+
Once you have created a virtual environment, or have decided to just let Poetry handle that,
93+
install with poetry::
94+
95+
poetry install
96+
4197

4298
Getting Started
4399
===============
44100

45-
Using this library is intended to be as straightforward as possible. Code for a very simple lambda used in the tests is reproduced below.
101+
Using this library is intended to be as straightforward as possible.
102+
Code for a very simple lambda used in the tests is reproduced below.
46103

47104
.. code:: python
48105
@@ -57,11 +114,13 @@ Using this library is intended to be as straightforward as possible. Code for a
57114
'description': 'Test lambda'
58115
}
59116
60-
61117
def handler(event, context):
62118
return 'Hello! My input event is %s' % event
63119
64-
This code illustrates the two things required to create a lambda. The first is ``config``, which specifies metadata for AWS. One important thing to note in here is the ``role`` field. This must be a IAM role with Lambda permissions - the one in this example is ours. The second is the ``handler`` function. This is the actual code that is executed.
120+
This code illustrates the two things required to create a lambda. The first is ``config``,
121+
which specifies metadata for AWS. One important thing to note in here is the ``role`` field.
122+
This must be a IAM role with Lambda permissions - the one in this example is ours.
123+
The second is the ``handler`` function. This is the actual code that is executed.
65124

66125
Given this code in ``example_function.py`` you would deploy this function like so:
67126

@@ -75,14 +134,34 @@ Given this code in ``example_function.py`` you would deploy this function like s
75134
requirements_fpath='path/to/requirements',
76135
extra_config={'optional_arguments_for': 'boto3'})
77136
78-
And that's it! You've deployed a simple lambda function. You can navigate to the AWS console to create a test event to trigger it or you can invoke it directly using Boto3.
137+
And that's it! You've deployed a simple lambda function. You can navigate to the AWS
138+
console to create a test event to trigger it or you can invoke it directly using Boto3.
79139

80140
Advanced Usage
81141
==============
82142

83-
Many of the options specified in the above code block when it came to actually deploying the function are not used. These become more useful as you want to make more complicated lambda functions. The ideal way to incorporate dependencies into lambda functions is by providing a ``requirements.txt`` file. We rely on ``pip`` to install these packages and have found it to be very reliable. While it is also possible to specify local modules as well through ``package_objects``, doing so is not recommended because those modules must be specified at the top level of the repository in order to work out of the box. There is a comment on this topic in ``example_function_package.py`` with code on how to handle it.
143+
Many of the options specified in the above code block when it came to actually
144+
deploying the function are not used. These become more useful as you want to make more
145+
complicated lambda functions. The ideal way to incorporate dependencies into lambda functions
146+
is by providing a ``requirements.txt`` file. We rely on ``pip`` to install these packages
147+
and have found it to be very reliable. While it is also possible to specify local modules
148+
as well through ``package_objects``, doing so is not recommended because those modules
149+
must be specified at the top level of the repository in order to work out of the box.
150+
There is a comment on this topic in ``example_function_package.py``
151+
with code on how to handle it.
84152

85153
Tests
86154
========
87155

88-
Tests can be found in the ``test_aws_lambda.py``. Using the tests as a guide to develop your lambdas is probably a good idea. You can also see how to invoke the lambdas directly from Python (and interpret the response).
156+
Tests can be found in the ``test_aws_lambda.py``. Using the tests as a guide to develop
157+
your lambdas is probably a good idea. You can also see how to invoke the lambdas directly
158+
from Python (and interpret the response). You can invoke all of this by just doing::
159+
160+
pytest
161+
162+
The usual ``pytest`` arguments are permited. For example, to invoke an individual test,
163+
mention its name. To see verbose output, use ``-v``; or use ``-vv`` for extra-verbose output,
164+
as in::
165+
166+
pytest -vv -k test_deploy_lambda_with_package_and_requirements
167+

aws_lambda/_version.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""Version information."""
2+
import pkg_resources
3+
4+
# Information in this file is now superseded by the pyproject.toml file.
25

36
# The following line *must* be the last in the module, exactly as formatted:
4-
__version__ = "1.0.1"
7+
__version__ = pkg_resources.get_distribution('python-lambda-4dn').version

dev-requirements.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

dev-requirements.txt.DISABLED

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest>=3.0.5,<4
2+
pytest-cov>=2.3.1,<3
3+
# pygments is only needed by PyCharm to render the README
4+
pygments>=2

0 commit comments

Comments
 (0)