Skip to content

Commit

Permalink
Support for python37/38 (#116)
Browse files Browse the repository at this point in the history
* support for python37/38

* Use the multi-value query params to build WSGI environment
  • Loading branch information
akshaps authored May 20, 2022
1 parent 65a9e47 commit 286f238
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 5 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- run:
name: Install Python build dependencies
command: |
mv ./pyproject_test.toml ./pyproject.toml
poetry install
- run:
name: Run tests
Expand Down
29 changes: 26 additions & 3 deletions fleece/cli/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
from __future__ import print_function

import argparse
from datetime import datetime
import hashlib
from io import BytesIO
import os
import subprocess
import sys
import tarfile
import tempfile
from datetime import datetime
from io import BytesIO

import docker
from docker import errors


build_dir = os.path.abspath(os.path.dirname(__file__))


def parse_args(args):
parser = argparse.ArgumentParser(prog='fleece build',
description='Simple Lambda builder.')
parser.add_argument('--python', '-py', type=str, default=None,
help='Version of Python to use (27, 36, 37, 38)')
parser.add_argument('--python36', '-3', action='store_true',
help='use Python 3.6 (default: Python 2.7)')
parser.add_argument('--inject-build-info', action='store_true',
Expand Down Expand Up @@ -51,6 +54,9 @@ def parse_args(args):
parser.add_argument('service_dir', type=str,
help=('directory where the service is located '
'(default: $pwd)'))
result = parser.parse_args(args)
if _get_python_version(result) is None:
sys.exit(1)
return parser.parse_args(args)


Expand Down Expand Up @@ -137,8 +143,25 @@ def create_volume_container(image='alpine:3.4', command='/bin/true', **kwargs):
return container


def _get_python_version(args):
if args.python is None:
if args.python36:
return 'python36'
return 'python27'
else:
if args.python36:
print("Error: --python36 and --python cannot be used together.")
return None
# Accomodate people who want to put a single dot in there.
version = args.python.replace('.', '', 1)
if version not in ["27", "36", "37", "38"]:
print('Unrecognized Python version "{}"'.format(args.python))
return None
return 'python' + version


def build(args):
python_version = 'python36' if args.python36 else 'python27'
python_version = _get_python_version(args)
inject_build_info = args.inject_build_info
service_dir = os.path.abspath(args.service_dir)
service_name = os.path.basename(service_dir)
Expand Down
2 changes: 1 addition & 1 deletion fleece/handlers/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def build_wsgi_environ_from_event(event):
"""Create a WSGI environment from the proxy integration event."""
params = event.get("queryStringParameters")
params = event.get("multiValueQueryStringParameters")
environ = EnvironBuilder(
method=event.get("httpMethod") or "GET",
path=event.get("path") or "/",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fleece"
version = "1.0.0"
version = "1.1.0"
description = "Wrap the lamb...da"
license = "Apache-2.0"
readme = "README.md"
Expand Down
106 changes: 106 additions & 0 deletions pyproject_test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[tool.poetry]
name = "fleece"
version = "1.1.0"
description = "Wrap the lamb...da"
license = "Apache-2.0"
readme = "README.md"
homepage = "https://github.com/rackerlabs/fleece"
repository = "https://github.com/rackerlabs/fleece"
keywords = ['fleece', 'lambda']
classifiers = [
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Topic :: Software Development',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
]

authors = ["Bruce Stringer <[email protected]>", "Ryan Walker <[email protected]>", "Szilveszter Farkas <[email protected]>","Tim Simpson <[email protected]>"]
maintainers = ["Bruce Stringer <[email protected]>", "Ryan Walker <[email protected]>", "Szilveszter Farkas <[email protected]>","Tim Simpson <[email protected]>"]

include = ["fleece/cli/build/Dockerfile", "fleece/cli/build/docker_build_lambda.sh"]

packages = [
{ include = "fleece" }
]

[tool.poetry.scripts]
fleece = "fleece.cli.main:main"

[tool.poetry.extras]
connexion = [
"connexion",
"Flask",
"Werkzeug",
]
cli = [
"docker",
"PyYAML",
"ruamel.yaml",
"six",
]
wsgi = [
"Werkzeug",
]

[tool.poetry.dependencies]
python = "^3.6"
# connecxion
connexion = { version = "^1.1.9", optional = true }
Flask = { version = "^1.1.1", optional = true }
# cli
docker = { version = "^3.5.1", optional = true }
PyYAML = { version = "5.4", optional = true }
"ruamel.yaml" = { version = "^0.15.34", optional = true }
# wsgi and connecxion
Werkzeug = { version = "^0.15.5", optional = true }
structlog = "^20.1.0"
requests = "^2.9.1"
boto3 = "^1.0.0"
wrapt = "^1.10.10"
click = "8.0.1"

[tool.poetry.dev-dependencies]
coverage = "^4.0.3"
flake8 = "^3.8.3"
mock = "1.0.1"
nose = "^1.3.7"
pylint = "^1.5.4"
docker = "^3.5.1"
taskipy = "^1.2.1"
moto = "^1.3.14"
black = "^19.10b0"
safety = "^1.9.0"
isort = "^4.3.21"
pytest = "^5.4.1"
Werkzeug = "^0.15.5"
bandit = "^1.6.2"
"ruamel.yaml" = "^0.15.34"
Flask = "^1.1.1"
connexion = "^1.1.9"

[tool.taskipy.tasks]
pytest = "pytest --junitxml=test-results/junit.xml"
bandit = "bandit -c .bandit.yml -r fleece/"
black = "black fleece"
black_ci = "black -check fleece"
flake8 = "flake8 fleece/ tests/"
convert_readme = "pandoc --from=gfm --to=rst README.md --output=README.rst"
generate_requirements = "poetry export -f requirements.txt -o requirements.txt"
pre_safety = "task generate_requirements"
safety = "safety check -r requirements.txt"
isort = "isort -rc fleece"
isort_ci = "isort -rc -c fleece"
full = "task pytest && task black && task flake8 && task safety && task bandit && task isort"
ci = "task pytest && task black_ci && task flake8 && task safety && task bandit && task isort_ci"

[tool.isort]
force_single_line = true

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

0 comments on commit 286f238

Please sign in to comment.