Skip to content

Commit 53fc782

Browse files
authored
Cleaning up (#30)
* Cleaning up * Removing unused imports * Black code styling * Remove unused test reqs, add pytest test runner, exclude tests from package * Move cli modules to own submodule * More minor clean up * Removing github module
1 parent 103e2b8 commit 53fc782

16 files changed

+172
-105
lines changed

Diff for: .gitignore

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# IPython Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# dotenv
79+
.env
80+
81+
# virtualenv
82+
venv/
83+
ENV/
84+
85+
# Spyder project settings
86+
.spyderproject
87+
88+
# Rope project settings
89+
.ropeproject
90+
91+
# node.js
92+
node_modules
93+
.serverless
94+
95+
.pytest_cache
96+
.requirements

Diff for: MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.md LICENSE
2+
recursive-include iopipe_cli *.py

Diff for: iopipe_cli/awslambda.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from . import layers
21
from . import utils
32

43

@@ -56,7 +55,8 @@ def _add_iopipe(
5655
if not allow_upgrade and orig_handler == runtime_handler:
5756
raise (
5857
UpdateLambdaException(
59-
"Already installed. Pass --upgrade (or -u) to allow upgrade or reinstall to latest layer version."
58+
"Already installed. Pass --upgrade (or -u) to allow upgrade or "
59+
"reinstall to latest layer version."
6060
)
6161
)
6262
if runtime == "provider" or runtime not in utils.RUNTIME_CONFIG.keys():
@@ -147,7 +147,8 @@ def _remove_iopipe(config, region, function_arn, layer_arn):
147147
# Detect non-IOpipe handler and error if necessary.
148148
if not utils.is_valid_handler(runtime, orig_handler):
149149
raise UpdateLambdaException(
150-
"IOpipe installation (via layers) not auto-detected for the specified function.\n"
150+
"IOpipe installation (via layers) not auto-detected for the specified "
151+
"function.\n"
151152
"Error: Unrecognized handler in deployed function."
152153
)
153154

@@ -166,8 +167,10 @@ def _remove_iopipe(config, region, function_arn, layer_arn):
166167
env_handler = env_handler or env_alt_handler
167168
if not env_handler:
168169
raise UpdateLambdaException(
169-
"IOpipe installation (via layers) not auto-detected for the specified function.\n"
170-
+ "Error: Environment variable IOPIPE_HANDLER or IOPIPE_GENERIC_HANDLER not found."
170+
"IOpipe installation (via layers) not auto-detected for the specified "
171+
"function.\n"
172+
"Error: Environment variable IOPIPE_HANDLER or IOPIPE_GENERIC_HANDLER not "
173+
"found."
171174
)
172175

173176
# Delete IOpipe env vars

Diff for: iopipe_cli/cli.py

-30
This file was deleted.

Diff for: iopipe_cli/cli/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import click
2+
3+
from .. import utils
4+
from ..awslambda import MultipleLayersException, UpdateLambdaException
5+
6+
from . import awslambda, stack
7+
8+
9+
@click.group(name="cli")
10+
def cli_group():
11+
pass
12+
13+
14+
def click_groups(group):
15+
awslambda.register(group)
16+
stack.register(group)
17+
18+
19+
@utils.catch_boto_errors
20+
def main():
21+
try:
22+
click_groups(cli_group)
23+
cli_group()
24+
except MultipleLayersException:
25+
utils.error("Multiple layers found. Pass --layer-arn to specify layer ARN")
26+
except UpdateLambdaException as e:
27+
utils.error(e)

Diff for: iopipe_cli/cli_awslambda.py renamed to iopipe_cli/cli/awslambda.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from . import awslambda
2-
from . import utils
3-
4-
import boto3
5-
import botocore
61
import click
72
import itertools
83
import json
94
import shutil
105

6+
from .. import awslambda, utils
7+
118

129
@click.group(name="lambda")
1310
def lambda_group():
14-
None
11+
pass
1512

1613

1714
def register(group):

Diff for: iopipe_cli/cli_stack.py renamed to iopipe_cli/cli/stack.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
from . import stack
2-
from . import utils
3-
41
import click
52
import os
63

4+
from .. import stack, utils
75

8-
IOPIPE_FF_CLOUDFORMATION = os.environ.get("IOPIPE_FF_CLOUDFORMATION")
6+
IOPIPE_FF_CLOUDFORMATION = os.getenv("IOPIPE_FF_CLOUDFORMATION")
97

108

119
@click.group(name="stack")
1210
def stack_group():
13-
None
11+
pass
1412

1513

1614
def register(group):

Diff for: iopipe_cli/combine_dict.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Copy-pasta from Stackoverflow: https://stackoverflow.com/questions/39997469/how-to-deep-merge-dicts
1+
# Copy-pasta from Stackoverflow:
2+
# https://stackoverflow.com/questions/39997469/how-to-deep-merge-dicts
3+
import collections
4+
5+
26
def combine_dict(map1: dict, map2: dict):
37
def update(d: dict, u: dict):
48
for k, v in u.items():

Diff for: iopipe_cli/github.py

-14
This file was deleted.

Diff for: iopipe_cli/layers.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import json
21
import requests
32

43

54
def index(region, runtime):
65
req = requests.get(
7-
"https://%s.layers.iopipe.com/get-layers?CompatibleRuntime=%s"
8-
% (region, runtime)
6+
f"https://{region}.layers.iopipe.com/get-layers?CompatibleRuntime={runtime}"
97
)
10-
layers_response = json.loads(req.content)
8+
layers_response = req.json()
119
return layers_response.get("Layers", [])

Diff for: iopipe_cli/s3zip.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# import boto3
21
import requests
32

43

@@ -51,7 +50,7 @@ def _check_blob_magic_bytes(blob, magic, distance):
5150

5251
return _check_blob_magic_bytes(blob, magic, 0)
5352

54-
eocd_block = check_blob_magic_bytes(reverse(iter(eocd_blob)), 0x06054B50)
53+
eocd_block = check_blob_magic_bytes(reversed(iter(eocd_blob)), 0x06054B50)
5554
if not eocd_block:
5655
raise Exception("No zip central directory signature found.")
5756

Diff for: iopipe_cli/stack.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from . import awslambda
2-
from . import utils
3-
from .combine_dict import combine_dict
4-
51
import boto3
62
import itertools
73
import json
84

5+
from . import awslambda, utils
6+
from .combine_dict import combine_dict
7+
98

109
def get_stack_ids():
1110
CloudFormation = boto3.client("cloudformation")
@@ -33,7 +32,8 @@ def map_stack_ids():
3332

3433
def get_template(stackid):
3534
CloudFormation = boto3.client("cloudformation")
36-
# DOC get_template: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.get_template
35+
# DOC get_template:
36+
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.get_template
3737
template_body = CloudFormation.get_template(StackName=stackid)
3838
# example_get_template_body = '''
3939
# {
@@ -99,5 +99,6 @@ def update_cloudformation_stack(stack_id, function_arn, token):
9999
# stackid = get_stack_ids(function_arn)
100100
orig_template = get_template(stack_id)
101101
template_body = modify_cloudformation(orig_template, function_arn, token)
102-
# DOC update_stack: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.update_stack
102+
# DOC update_stack:
103+
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.update_stack
103104
CloudFormation.update_stack(StackName=stack_id, TemplateBody=template_body)

Diff for: iopipe_cli/utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from . import layers
2-
31
import boto3
42
import botocore
53
import click
64
import collections
75
import jwt
8-
import os
96
import sys
107

8+
from . import layers
9+
1110
IOPIPE_ARN_PREFIX_TEMPLATE = "arn:aws:lambda:%s:146318645305"
1211
RUNTIME_CONFIG = {
1312
"java8": {
@@ -127,7 +126,7 @@ def check_token(ctx, param, value):
127126
try:
128127
jwt.decode(value, verify=False)
129128
return value
130-
except:
129+
except Exception:
131130
raise click.BadParameter("token invalid.")
132131

133132

Diff for: setup.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[aliases]
2+
test=pytest
3+
4+
[flake8]
5+
max-line-length = 88

Diff for: setup.py

+8-24
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,17 @@
1010
README = open(os.path.join(os.path.dirname(__file__), "README.md"), "r").read()
1111

1212
setup(
13-
name='iopipe-cli',
14-
version='0.1.7',
15-
python_requires='>=3.3',
13+
name="iopipe-cli",
14+
version="0.1.7",
15+
python_requires=">=3.3",
1616
description="cli utility for managing and instrumenting serverless applications",
1717
long_description=README,
1818
author="IOpipe",
1919
author_email="[email protected]",
2020
url="https://github.com/iopipe/iopipe-cli",
21-
packages=find_packages(),
22-
install_requires=[
23-
'click',
24-
'boto3',
25-
'requests',
26-
'pyjwt'
27-
],
28-
tests_require=[
29-
"coverage==5.0a2",
30-
"mock",
31-
"more-itertools<6.0.0",
32-
"pytest==4.1.0",
33-
"pytest-benchmark==3.2.0",
34-
"pytest-cov==2.6.1",
35-
"requests",
36-
],
37-
entry_points={
38-
'console_scripts': [
39-
'iopipe = iopipe_cli.cli:main',
40-
],
41-
}
21+
packages=find_packages(exclude=("tests", "tests.*")),
22+
install_requires=["click", "boto3", "requests", "pyjwt"],
23+
setup_requires=["pytest-runner"],
24+
tests_require=["coverage", "pytest", "pytest-cov", "requests"],
25+
entry_points={"console_scripts": ["iopipe = iopipe_cli.cli:main"]},
4226
)

0 commit comments

Comments
 (0)