Skip to content

Commit 48f561f

Browse files
committed
linting
1 parent 2b5e5c3 commit 48f561f

File tree

5 files changed

+64
-36
lines changed

5 files changed

+64
-36
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- repo: https://github.com/pre-commit/pre-commit-hooks
2+
sha: v0.8.0
3+
hooks:
4+
- id: autopep8-wrapper
5+
- id: check-ast
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: detect-private-key
9+
- id: double-quote-string-fixer
10+
- id: end-of-file-fixer
11+
- id: flake8
12+
- id: requirements-txt-fixer
13+
- id: trailing-whitespace
14+
- repo: https://github.com/asottile/reorder_python_imports
15+
sha: v0.3.4
16+
hooks:
17+
- id: reorder-python-imports
18+
language_version: python3.6
19+
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
20+
sha: v1.1.0
21+
hooks:
22+
- id: python-safety-dependencies-check

aws_lambda/aws_lambda.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import print_function
3+
34
import json
45
import logging
56
import os
67
import sys
78
import time
89
from imp import load_source
9-
from shutil import copy, copyfile
10+
from shutil import copy
11+
from shutil import copyfile
1012
from tempfile import mkdtemp
1113

12-
import botocore
1314
import boto3
15+
import botocore
1416
import pip
1517
import yaml
1618

17-
from .helpers import mkdir, read, archive, timestamp
19+
from .helpers import archive
20+
from .helpers import mkdir
21+
from .helpers import read
22+
from .helpers import timestamp
1823

1924

2025
log = logging.getLogger(__name__)
@@ -44,22 +49,22 @@ def cleanup_old_versions(src, keep_last_versions):
4449
cfg.get('region'))
4550

4651
response = client.list_versions_by_function(
47-
FunctionName=cfg.get("function_name")
52+
FunctionName=cfg.get('function_name')
4853
)
49-
versions = response.get("Versions")
50-
if len(response.get("Versions")) < keep_last_versions:
51-
print("Nothing to delete. (Too few versions published)")
54+
versions = response.get('Versions')
55+
if len(response.get('Versions')) < keep_last_versions:
56+
print('Nothing to delete. (Too few versions published)')
5257
else:
53-
version_numbers = [elem.get("Version") for elem in
58+
version_numbers = [elem.get('Version') for elem in
5459
versions[1:-keep_last_versions]]
5560
for version_number in version_numbers:
5661
try:
5762
client.delete_function(
58-
FunctionName=cfg.get("function_name"),
63+
FunctionName=cfg.get('function_name'),
5964
Qualifier=version_number
6065
)
6166
except botocore.exceptions.ClientError as e:
62-
print("Skipping Version {}: {}"
67+
print('Skipping Version {}: {}'
6368
.format(version_number, e.message))
6469

6570

@@ -111,7 +116,7 @@ def invoke(src, alt_event=None, verbose=False):
111116
path_to_event_file = os.path.join(src, 'event.json')
112117
event = read(path_to_event_file, loader=json.loads)
113118

114-
#Tweak to allow module to import local modules
119+
# Tweak to allow module to import local modules
115120
try:
116121
sys.path.index(src)
117122
except:
@@ -129,10 +134,10 @@ def invoke(src, alt_event=None, verbose=False):
129134
results = fn(event, None)
130135
end = time.time()
131136

132-
print("{0}".format(results))
137+
print('{0}'.format(results))
133138
if verbose:
134-
print("\nexecution time: {:.8f}s\nfunction execution "
135-
"timeout: {:2}s".format(end - start, cfg.get('timeout', 15)))
139+
print('\nexecution time: {:.8f}s\nfunction execution '
140+
'timeout: {:2}s'.format(end - start, cfg.get('timeout', 15)))
136141

137142

138143
def init(src, minimal=False):
@@ -145,7 +150,7 @@ def init(src, minimal=False):
145150
"""
146151

147152
templates_path = os.path.join(
148-
os.path.dirname(os.path.abspath(__file__)), "project_templates")
153+
os.path.dirname(os.path.abspath(__file__)), 'project_templates')
149154
for filename in os.listdir(templates_path):
150155
if (minimal and filename == 'event.json') or filename.endswith('.pyc'):
151156
continue
@@ -178,18 +183,19 @@ def build(src, requirements=False, local_package=None):
178183
# Combine the name of the Lambda function with the current timestamp to use
179184
# for the output filename.
180185
function_name = cfg.get('function_name')
181-
output_filename = "{0}-{1}.zip".format(timestamp(), function_name)
186+
output_filename = '{0}-{1}.zip'.format(timestamp(), function_name)
182187

183188
path_to_temp = mkdtemp(prefix='aws-lambda')
184189
pip_install_to_target(path_to_temp,
185190
requirements=requirements,
186191
local_package=local_package)
187192

188193
# Hack for Zope.
189-
if "zope" in os.listdir(path_to_temp):
190-
print("Zope packages detected; fixing Zope package paths to make them importable.")
194+
if 'zope' in os.listdir(path_to_temp):
195+
print('Zope packages detected; fixing Zope package paths to '
196+
'make them importable.')
191197
# Touch.
192-
with open(os.path.join(path_to_temp, "zope/__init__.py"), "wb"):
198+
with open(os.path.join(path_to_temp, 'zope/__init__.py'), 'wb'):
193199
pass
194200

195201
# Gracefully handle whether ".zip" was included in the filename or not.
@@ -204,7 +210,7 @@ def build(src, requirements=False, local_package=None):
204210
continue
205211
if filename == 'config.yaml':
206212
continue
207-
print("Bundling: %r" % filename)
213+
print('Bundling: %r' % filename)
208214
files.append(os.path.join(src, filename))
209215

210216
# "cd" into `temp_path` directory.
@@ -264,7 +270,7 @@ def _install_packages(path, packages):
264270
A list of packages to be installed via pip.
265271
"""
266272
def _filter_blacklist(package):
267-
blacklist = ["-i", "#", "Python==", "python-lambda=="]
273+
blacklist = ['-i', '#', 'Python==', 'python-lambda==']
268274
return all(package.startswith(entry) is False for entry in blacklist)
269275
filtered_packages = filter(_filter_blacklist, packages)
270276
for package in filtered_packages:
@@ -296,16 +302,16 @@ def pip_install_to_target(path, requirements=False, local_package=None):
296302
print('Gathering pip packages')
297303
packages.extend(pip.operations.freeze.freeze())
298304
else:
299-
if os.path.exists("requirements.txt"):
305+
if os.path.exists('requirements.txt'):
300306
print('Gathering requirement packages')
301-
data = read("requirements.txt")
307+
data = read('requirements.txt')
302308
packages.extend(data.splitlines())
303309

304310
if not packages:
305311
print('No dependency packages installed!')
306312

307313
if local_package is not None:
308-
if not isinstance(local_package, (list, tuple) ):
314+
if not isinstance(local_package, (list, tuple)):
309315
local_package = [local_package]
310316
for l_package in local_package:
311317
packages.append(l_package)
@@ -314,7 +320,7 @@ def pip_install_to_target(path, requirements=False, local_package=None):
314320

315321
def get_role_name(account_id, role):
316322
"""Shortcut to insert the `account_id` and `role` into the iam string."""
317-
return "arn:aws:iam::{0}:role/{1}".format(account_id, role)
323+
return 'arn:aws:iam::{0}:role/{1}'.format(account_id, role)
318324

319325

320326
def get_account_id(aws_access_key_id, aws_secret_access_key):
@@ -337,7 +343,7 @@ def get_client(client, aws_access_key_id, aws_secret_access_key, region=None):
337343
def create_function(cfg, path_to_zip_file):
338344
"""Register and upload a function to AWS Lambda."""
339345

340-
print("Creating your new Lambda function")
346+
print('Creating your new Lambda function')
341347
byte_stream = read(path_to_zip_file)
342348
aws_access_key_id = cfg.get('aws_access_key_id')
343349
aws_secret_access_key = cfg.get('aws_secret_access_key')
@@ -375,7 +381,7 @@ def create_function(cfg, path_to_zip_file):
375381
def update_function(cfg, path_to_zip_file):
376382
"""Updates the code of an existing Lambda function"""
377383

378-
print("Updating your Lambda function")
384+
print('Updating your Lambda function')
379385
byte_stream = read(path_to_zip_file)
380386
aws_access_key_id = cfg.get('aws_access_key_id')
381387
aws_secret_access_key = cfg.get('aws_secret_access_key')

aws_lambda/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
import datetime as dt
23
import os
34
import zipfile
4-
import datetime as dt
55

66

77
def mkdir(path):

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import pip
4-
5-
from setuptools import setup, find_packages
4+
from setuptools import find_packages
5+
from setuptools import setup
66

77
with open('README.rst') as readme_file:
88
readme = readme_file.read()
99

1010
requirements = pip.req.parse_requirements(
11-
"requirements.txt", session=pip.download.PipSession()
11+
'requirements.txt', session=pip.download.PipSession()
1212
)
1313
pip_requirements = [str(r.req) for r in requirements]
1414

@@ -19,9 +19,9 @@
1919
setup(
2020
name='python-lambda',
2121
version='0.8.1',
22-
description="The bare minimum for a Python app running on Amazon Lambda.",
22+
description='The bare minimum for a Python app running on Amazon Lambda.',
2323
long_description=readme,
24-
author="Nick Ficano",
24+
author='Nick Ficano',
2525
author_email='nficano@gmail.com',
2626
url='https://github.com/nficano/python-lambda',
2727
packages=find_packages(),
@@ -32,15 +32,15 @@
3232
include_package_data=True,
3333
scripts=['scripts/lambda'],
3434
install_requires=pip_requirements,
35-
license="ISCL",
35+
license='ISCL',
3636
zip_safe=False,
3737
keywords='python-lambda',
3838
classifiers=[
3939
'Development Status :: 2 - Pre-Alpha',
4040
'Intended Audience :: Developers',
4141
'License :: OSI Approved :: ISC License (ISCL)',
4242
'Natural Language :: English',
43-
"Programming Language :: Python :: 2",
43+
'Programming Language :: Python :: 2',
4444
'Programming Language :: Python :: 2.6',
4545
'Programming Language :: Python :: 2.7',
4646
'Programming Language :: Python :: 3',

tests/dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bumpversion==0.5.3
2-
2+
pre-commit==0.15.0

0 commit comments

Comments
 (0)