Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 02d0185

Browse files
authored
Fix linter code style warnings (#11)
1 parent 43e4334 commit 02d0185

14 files changed

+86
-69
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ function-naming-style=snake_case
168168
good-names=i,
169169
j,
170170
k,
171+
e,
171172
ex,
172173
Run,
173174
_

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ test:
99
flake:
1010
# Make sure code conforms to PEP8 standards
1111
pipenv run flake8 serverlessrepo
12-
pipenv run flake8 tests
12+
# Ignore missing docstring errors for tests
13+
pipenv run flake8 tests --ignore=D100,D101,D102,D103,D104
1314

1415
lint:
1516
# Linter performs static analysis to catch latent bugs
1617
pipenv run pylint --rcfile .pylintrc serverlessrepo
18+
# Ignore missing docstring errors for tests
19+
pipenv run pylint --rcfile .pylintrc tests --disable=C0111
1720

1821
# Command to run everytime you make changes to verify everything works
1922
build: flake lint test

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A Python library with convenience helpers for working with the [AWS Serverless A
66

77
Simply use pip to install the library:
88

9-
```
9+
```text
1010
pip install serverlessrepo
1111
```
1212

@@ -24,7 +24,7 @@ import serverlessrepo
2424

2525
Given an [AWS Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md) template, it publishes a new application using the specified metadata in AWS Serverless Application Repository. If the application already exists, it publishes a new application version.
2626

27-
#### publish_application_metadata(template, application_id)
27+
#### update_application_metadata(template, application_id)
2828

2929
Parses the application metadata from the SAM template and updates the application.
3030

@@ -43,12 +43,12 @@ with open('template.yaml', 'r') as f:
4343
Or updates the application's metadata using template.yaml:
4444

4545
```python
46-
from serverlessrepo import publish_application_metadata
46+
from serverlessrepo import update_application_metadata
4747

4848
with open('template.yaml', 'r') as f:
4949
template = f.read()
5050
application_id = 'arn:aws:serverlessrepo:us-east-1:123456789012:applications/test-app'
51-
publish_application_metadata(template, application_id)
51+
update_application_metadata(template, application_id)
5252
```
5353

5454
### Manage Application Permissions

serverlessrepo/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
"""
2-
Common library for AWS Serverless Application Repository
3-
"""
1+
"""Common library for AWS Serverless Application Repository."""
2+
3+
from .publish import ( # noqa: F401
4+
publish_application,
5+
update_application_metadata
6+
)
47

5-
from .publish import publish_application # noqa: F401
68
from .permission_helper import ( # noqa: F401
79
make_application_public,
810
make_application_private,

serverlessrepo/__version__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Serverlessrepo version and package meta-data.
3-
"""
1+
"""Serverlessrepo version and package meta-data."""
42

53
__title__ = 'serverlessrepo'
64
__version__ = '0.1.0'
@@ -11,4 +9,4 @@
119
)
1210
__url__ = 'https://github.com/awslabs/aws-serverlessrepo-python'
1311
__author__ = 'Amazon Web Services'
14-
__author_email__ = '<TBD>'
12+
__author_email__ = '[email protected]'

serverlessrepo/application_metadata.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
"""Module containing class to store SAR application metadata."""
2+
13
from .exceptions import InvalidApplicationMetadataError
24

35

46
class ApplicationMetadata(object):
5-
"""
6-
Class representing SAR metadata
7-
"""
7+
"""Class representing SAR metadata."""
88

99
# SAM template SAR metadata properties
1010
_NAME = 'Name'
@@ -20,7 +20,7 @@ class ApplicationMetadata(object):
2020

2121
def __init__(self, app_metadata):
2222
"""
23-
Initializes the object given SAR metadata properties
23+
Initialize the object given SAR metadata properties.
2424
2525
:param app_metadata: Dictionary containing SAR metadata properties
2626
:type app_metadata: dict
@@ -37,11 +37,12 @@ def __init__(self, app_metadata):
3737
self.source_code_url = app_metadata.get(self._SOURCE_CODE_URL)
3838

3939
def __eq__(self, other):
40+
"""Return whether two ApplicationMetadata objects are equal."""
4041
return isinstance(other, type(self)) and self.__dict__ == other.__dict__
4142

4243
def validate(self, required_props):
4344
"""
44-
Checks if the required application metadata properties have been populated
45+
Check if the required application metadata properties have been populated.
4546
4647
:param required_props: List of required properties
4748
:type required_props: list

serverlessrepo/application_policy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
"""Module containing class to store SAR application permissions."""
2+
13
import re
24

35
from .exceptions import InvalidApplicationPolicyError
46

57

68
class ApplicationPolicy(object):
7-
"""
8-
Class representing SAR application policy
9-
"""
9+
"""Class representing SAR application policy."""
1010

1111
# Supported actions for setting SAR application permissions
1212
GET_APPLICATION = 'GetApplication'
@@ -31,7 +31,7 @@ class ApplicationPolicy(object):
3131

3232
def __init__(self, principals, actions):
3333
"""
34-
Initializes the object given the principals and actions
34+
Initialize the object given the principals and actions.
3535
3636
:param principals: List of AWS account IDs, or *
3737
:type principals: list of str
@@ -43,7 +43,7 @@ def __init__(self, principals, actions):
4343

4444
def validate(self):
4545
"""
46-
Checks if the formats of principals and actions are valid
46+
Check if the formats of principals and actions are valid.
4747
4848
:return: True, if the policy is valid
4949
:raises: InvalidApplicationPolicyError
@@ -59,15 +59,15 @@ def validate(self):
5959
error_message='principal should be 12-digit AWS account ID or "*"')
6060

6161
unsupported_actions = sorted(set(self.actions) - set(self.SUPPORTED_ACTIONS))
62-
if len(unsupported_actions):
62+
if unsupported_actions:
6363
raise InvalidApplicationPolicyError(
6464
error_message='{} not supported'.format(', '.join(unsupported_actions)))
6565

6666
return True
6767

6868
def to_statement(self):
6969
"""
70-
Converts to a policy statement dictionary
70+
Convert to a policy statement dictionary.
7171
7272
:return: Dictionary containing Actions and Principals
7373
:rtype: dict

serverlessrepo/exceptions.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
"""
2-
Collection of public exceptions raised by this library
3-
"""
1+
"""Collection of public exceptions raised by this library."""
42

53

64
class ServerlessRepoError(Exception):
5+
"""Base exception raised by serverlessrepo library."""
76

87
MESSAGE = ''
98

109
def __init__(self, **kwargs):
10+
"""Init the exception object."""
1111
Exception.__init__(self, self.MESSAGE.format(**kwargs))
1212

1313

1414
class InvalidApplicationMetadataError(ServerlessRepoError):
15-
"""
16-
Raised when invalid application metadata is provided
17-
"""
15+
"""Raised when invalid application metadata is provided."""
16+
1817
MESSAGE = "Required application metadata properties not provided: '{properties}'"
1918

2019

2120
class ApplicationMetadataNotFoundError(ServerlessRepoError):
22-
"""
23-
Raised when application metadata is not found
24-
"""
21+
"""Raised when application metadata is not found."""
22+
2523
MESSAGE = "Application metadata not found in the SAM template: '{error_message}'"
2624

2725

2826
class InvalidApplicationPolicyError(ServerlessRepoError):
29-
"""
30-
Raised when invalid application policy is provided
31-
"""
27+
"""Raised when invalid application policy is provided."""
28+
3229
MESSAGE = "Invalid application policy: '{error_message}'"

serverlessrepo/parser.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
"""
2-
Helper to parse JSON/YAML SAM template and dump YAML files
3-
"""
1+
"""Helper to parse JSON/YAML SAM template and dump YAML files."""
42

53
import re
64
import json
5+
from collections import OrderedDict
76
import six
87
import yaml
98
from yaml.resolver import ScalarNode, SequenceNode
10-
from collections import OrderedDict
119

1210
from .application_metadata import ApplicationMetadata
1311
from .exceptions import ApplicationMetadataNotFoundError
@@ -20,9 +18,9 @@
2018
def intrinsics_multi_constructor(loader, tag_prefix, node):
2119
"""
2220
YAML constructor to parse CloudFormation intrinsics.
23-
This will return a dictionary with key being the instrinsic name
24-
"""
2521
22+
:return: a dictionary with key being the instrinsic name
23+
"""
2624
# Get the actual tag name excluding the first exclamation
2725
tag = node.tag[1:]
2826

@@ -60,7 +58,8 @@ def _dict_representer(dumper, data):
6058

6159
def yaml_dump(dict_to_dump):
6260
"""
63-
This function dumps the dictionary as a YAML document
61+
Dump the dictionary as a YAML document.
62+
6463
:param dict_to_dump: Data to be serialized as YAML
6564
:type dict_to_dump: dict
6665
:return: YAML document
@@ -76,7 +75,7 @@ def _dict_constructor(loader, node):
7675

7776
def parse_template(template_str):
7877
"""
79-
This function parses the SAM template
78+
Parse the SAM template.
8079
8180
:param template_str: A packaged YAML or json CloudFormation template
8281
:type template_str: str
@@ -96,7 +95,7 @@ def parse_template(template_str):
9695

9796
def get_app_metadata(template_dict):
9897
"""
99-
This function gets the application metadata from a SAM template
98+
Get the application metadata from a SAM template.
10099
101100
:param template_dict: SAM template as a dictionary
102101
:type template_dict: dict
@@ -107,11 +106,19 @@ def get_app_metadata(template_dict):
107106
if METADATA in template_dict and SERVERLESS_REPO_APPLICATION in template_dict[METADATA]:
108107
app_metadata_dict = template_dict[METADATA][SERVERLESS_REPO_APPLICATION]
109108
return ApplicationMetadata(app_metadata_dict)
110-
else:
111-
raise ApplicationMetadataNotFoundError(
112-
error_message='missing {} section in template Metadata'.format(SERVERLESS_REPO_APPLICATION))
109+
110+
raise ApplicationMetadataNotFoundError(
111+
error_message='missing {} section in template Metadata'.format(SERVERLESS_REPO_APPLICATION))
113112

114113

115114
def parse_application_id(text):
115+
"""
116+
Extract the application id from input text.
117+
118+
:param text: text to parse
119+
:type text: str
120+
:return: application id if found in the input
121+
:rtype: str
122+
"""
116123
result = re.search(APPLICATION_ID_PATTERN, text)
117124
return result.group(0) if result else None

serverlessrepo/permission_helper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
"""Module containing methods to manage application permissions."""
2+
13
import boto3
24

35
from .application_policy import ApplicationPolicy
46

57

68
def make_application_public(application_id):
79
"""
8-
This function sets the application to be public
10+
Set the application to be public.
11+
912
:raises ValueError
1013
"""
1114
if not application_id:
@@ -21,7 +24,8 @@ def make_application_public(application_id):
2124

2225
def make_application_private(application_id):
2326
"""
24-
This function sets the application to be private
27+
Set the application to be private.
28+
2529
:raises ValueError
2630
"""
2731
if not application_id:
@@ -35,7 +39,8 @@ def make_application_private(application_id):
3539

3640
def share_application_with_accounts(application_id, account_ids):
3741
"""
38-
This function shares the application privately with given AWS account IDs
42+
Share the application privately with given AWS account IDs.
43+
3944
:param account_ids: List of AWS account IDs, or *
4045
:type account_ids: list of str
4146
:raises ValueError

serverlessrepo/publish.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Module containing functions to publish or update application."""
2+
13
import boto3
24
from botocore.exceptions import ClientError
35

@@ -8,7 +10,7 @@
810

911
def publish_application(template):
1012
"""
11-
This function publishes the application
13+
Create a new application or new application version in SAR.
1214
1315
:param template: A packaged YAML or JSON SAM template
1416
:type template: str
@@ -46,9 +48,9 @@ def publish_application(template):
4648
}
4749

4850

49-
def publish_application_metadata(template, application_id):
51+
def update_application_metadata(template, application_id):
5052
"""
51-
This function updates the application metadata
53+
Update the application metadata.
5254
5355
:param template: A packaged YAML or JSON SAM template
5456
:type template: str
@@ -67,7 +69,7 @@ def publish_application_metadata(template, application_id):
6769

6870
def _create_application_request(app_metadata, template):
6971
"""
70-
This function constructs the request body to create application
72+
Construct the request body to create application.
7173
7274
:param app_metadata: Object containing app metadata
7375
:type app_metadata: ApplicationMetadata
@@ -96,7 +98,7 @@ def _create_application_request(app_metadata, template):
9698

9799
def _update_application_request(app_metadata, application_id):
98100
"""
99-
This function constructs the request body to update application
101+
Construct the request body to update application.
100102
101103
:param app_metadata: Object containing app metadata
102104
:type app_metadata: ApplicationMetadata
@@ -118,7 +120,7 @@ def _update_application_request(app_metadata, application_id):
118120

119121
def _create_application_version_request(app_metadata, application_id, template):
120122
"""
121-
This function constructs the request body to create application version
123+
Construct the request body to create application version.
122124
123125
:param app_metadata: Object containing app metadata
124126
:type app_metadata: ApplicationMetadata
@@ -141,7 +143,7 @@ def _create_application_version_request(app_metadata, application_id, template):
141143

142144
def _is_conflict_exception(e):
143145
"""
144-
This function checks whether the boto3 ClientError is ConflictException
146+
Check whether the boto3 ClientError is ConflictException.
145147
146148
:param e: boto3 exception
147149
:type e: ClientError

0 commit comments

Comments
 (0)