Skip to content

Commit 0bb0a40

Browse files
committed
formatting and lint updates, bring ci in line with rpdk core
1 parent ef72948 commit 0bb0a40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+912
-532
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ venv.bak/
123123
dmypy.json
124124

125125
# Pyre type checker
126-
.pyre/
126+
.pyre/

.pre-commit-config.yaml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
exclude: ^(buildspec.yml|.pre-commit-config.yaml)$
2+
fail_fast: true
3+
repos:
4+
- repo: https://github.com/pre-commit/mirrors-isort
5+
rev: v4.3.17
6+
hooks:
7+
- id: isort
8+
# language_version: python3.6
9+
- repo: https://github.com/ambv/black
10+
rev: stable
11+
hooks:
12+
- id: black
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v2.0.0
15+
hooks:
16+
- id: check-case-conflict
17+
- id: end-of-file-fixer
18+
- id: mixed-line-ending
19+
args:
20+
- --fix=lf
21+
- id: trailing-whitespace
22+
- id: flake8
23+
additional_dependencies:
24+
- flake8-bugbear>=19.3.0
25+
- flake8-builtins>=1.4.1
26+
- flake8-commas>=2.0.0
27+
- flake8-comprehensions>=2.1.0
28+
- flake8-debugger>=3.1.0
29+
- flake8-pep3101>=1.2.1
30+
# language_version: python3.6
31+
- id: pretty-format-json
32+
args:
33+
- --autofix
34+
- --indent=4
35+
- --no-sort-keys
36+
- id: check-merge-conflict
37+
# - id: check-yaml # doesn't work with CloudFormation templates/intrinsics, should use cfn-lint instead
38+
# language_version: python3.6
39+
- repo: https://github.com/pre-commit/pygrep-hooks
40+
rev: v1.3.0
41+
hooks:
42+
- id: python-check-blanket-noqa
43+
- id: python-check-mock-methods
44+
- id: python-no-log-warn
45+
- repo: https://github.com/PyCQA/bandit
46+
rev: f5a6f0ca62 # TODO: update once a release > 1.5.1 hits with this change in
47+
hooks:
48+
- id: bandit
49+
files: "^src/"
50+
# have to skip B101, contract tests use it and there's no way to skip for specific files
51+
# have to skip B322, as there is no way to indicate the codebase is Python 3 only (input only vulnerable in Py2)
52+
args: ["--skip", "B101,B322"]
53+
- repo: local
54+
hooks:
55+
- id: pylint-local
56+
name: pylint-local
57+
description: Run pylint in the local virtualenv
58+
entry: pylint "setup.py" "src/" "tests/"
59+
language: system
60+
# ignore all files, run on hard-coded modules instead
61+
pass_filenames: false
62+
always_run: true
63+
- id: pytest-local
64+
name: pytest-local
65+
description: Run pytest in the local virtualenv
66+
entry: pytest --cov="rpdk.python" --doctest-modules --ignore "tests/data" "tests/"
67+
language: system
68+
# ignore all files, run on hard-coded modules instead
69+
pass_filenames: false
70+
always_run: true
71+
- id: pytest-cfn_resource-local
72+
name: pytest-cfn_resource-local
73+
description: Run pytest against the cfn_resource module in the local virtualenv
74+
entry: pytest --cov="cfn_resource" --doctest-modules "src/tests/" --rootdir="src/"
75+
language: system
76+
# ignore all files, run on hard-coded modules instead
77+
pass_filenames: false
78+
always_run: true
79+
#- id: functional-tests
80+
# name: functional-tests
81+
# description: Runs functional tests using sam-local
82+
# entry: >
83+
# tests/functional-tests.sh src/
84+
# language: system
85+
# pass_filenames: false
86+
# always_run: true

.pylintrc

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ good-names=e,ex,f,fp,i,j,k,n,_
2121
[FORMAT]
2222

2323
indent-string=' '
24-
max-line-length=120
25-
26-
[DESIGN]
27-
max-attributes=12
28-
max-args=7
24+
max-line-length=88

CODE_OF_CONDUCT.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## Code of Conduct
2-
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3-
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
2+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
44
[email protected] with any additional questions or comments.

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Contributing Guidelines
22

3-
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
3+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
44
documentation, we greatly value feedback and contributions from our community.
55

6-
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
6+
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

99

1010
## Reporting Bugs/Feature Requests
1111

1212
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
1313

14-
When filing an issue, please check [existing open](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/issues), or [recently closed](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
14+
When filing an issue, please check [existing open](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/issues), or [recently closed](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
1515
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
1616

1717
* A reproducible test case or series of steps
@@ -36,17 +36,17 @@ To send us a pull request, please:
3636
5. Send us a pull request, answering any default questions in the pull request interface.
3737
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
3838

39-
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
39+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4040
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4141

4242

4343
## Finding contributions to work on
44-
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/labels/help%20wanted) issues is a great place to start.
44+
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-cloudformation-rpdk-python-plugin/labels/help%20wanted) issues is a great place to start.
4545

4646

4747
## Code of Conduct
48-
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49-
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
48+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
5050
[email protected] with any additional questions or comments.
5151

5252

NOTICE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
AWS Cloudformation Rpdk Python Plugin
2-
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
The CloudFormation Resource Provider Development Kit (RPDK) allows you to author your own resource providers that can be used by CloudFormation.
55

6-
This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.
6+
This plugin library helps to provide runtime bindings for the execution of your providers by CloudFormation.
77

88
License
99
-------

buildspec.yml

+15-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
version: 0.2
22
phases:
3-
pre_build:
3+
install:
44
commands:
5-
- pip install --upgrade pip wheel
5+
# make sure pip/setuptools/wheel is up to date, awscli for SDK patching
6+
- pip install --upgrade pip setuptools wheel awscli -r requirements.txt
7+
- aws configure add-model --service-model "file://$CODEBUILD_SRC_DIR_RPDK/cloudformation-2010-05-15.normal.json" --service-name cloudformation
68
build:
79
commands:
8-
# install aws-cloudformation-rpdk
9-
- cd "$CODEBUILD_SRC_DIR_RPDK"
10-
- pip install .
11-
# patch boto3/awscli with internal SDK (must be done after RPDK is installed, since awscli is a dep currently)
12-
- aws configure add-model --service-model "file://cloudformation-2010-05-15.normal.json" --service-name cloudformation
13-
# install aws-cloudformation-rpdk-python-plugin (Python)
14-
- cd "$CODEBUILD_SRC_DIR"
15-
- ls -la
16-
- pip install . # -r requirements.txt (currently no testing/linting dependencies)
17-
# work around https://github.com/boto/botocore/issues/1733
18-
- pip install 'urllib3<1.25'
19-
# run unit tests/linting here
20-
- pip install pytest pylint
21-
- pytest
22-
- pylint python/rpdk/python/ src/
23-
# end-to-end test - need privileged codebuild job and docker installed in container
24-
# - pip install aws-sam-cli
25-
# - ./tests/functional-tests.sh ${CODEBUILD_SRC_DIR}/src/
10+
# install aws-cloudformation-rpdk-python-plugin and rpdk core
11+
- pip install "$CODEBUILD_SRC_DIR_RPDK" .
12+
# run lints/tests
13+
- pre-commit run --all-files
14+
# end-to-end test
2615
- DIR=$(mktemp -d)
2716
- cd "$DIR"
2817
- ls -la
2918
- |
3019
echo "AWS::Foo::Bar
31-
1" | uluru-cli init -vv # python3.6
20+
1" | cfn-cli init -vv # python3.6
21+
- ls -la
22+
- DIR=$(mktemp -d)
23+
- cd "$DIR"
24+
- ls -la
3225
- |
3326
echo "AWS::Foo::Bar
34-
2" | uluru-cli init -vv # python3.7
27+
2" | cfn-cli init -vv # python3.7
3528
- ls -la

python/rpdk/python/codegen.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import shutil
44

55
import docker
6-
76
from rpdk.core.plugin_base import LanguagePlugin
87

9-
108
LOG = logging.getLogger(__name__)
119

12-
EXECUTABLE = "uluru-cli"
13-
OLD_VIRTUAL_ENV = ''
10+
EXECUTABLE = "cfn-cli"
11+
OLD_VIRTUAL_ENV = ""
1412
OLD_PATH = []
1513

1614

@@ -28,7 +26,7 @@ def __init__(self):
2826
self.package_name = None
2927
self.schema_filename = None
3028
self.namespace = None
31-
self.cfn_resource_version = 'cfn_resource==0.0.1'
29+
self.cfn_resource_version = "cfn_resource==0.0.1"
3230

3331
def _package_from_project(self, project):
3432
self.namespace = tuple(s.lower() for s in project.type_info)
@@ -58,43 +56,44 @@ def init(self, project):
5856
templates = [
5957
[
6058
project.root / "Handler.yaml",
61-
self.env.get_template("Handler.yaml"),
59+
self.env.get_template("Handler.yaml.jinja2"),
6260
{
63-
'resource_type': project.type_name,
64-
'handler_params': {
61+
"resource_type": project.type_name,
62+
"handler_params": {
6563
"Handler": project.entrypoint,
6664
"Runtime": project.runtime,
6765
"CodeUri": self.CODE_URI.format(self.package_name),
68-
}
69-
}
66+
},
67+
},
7068
],
7169
[
7270
project.root / self.package_name / "handlers.py",
73-
self.env.get_template("handlers.py"),
74-
{}
71+
self.env.get_template("handlers.py.jinja2"),
72+
{},
7573
],
7674
[
7775
project.root / self.package_name / "__init__.py",
7876
self.env.get_template("__init__.py.jinja2"),
79-
{}
77+
{},
8078
],
8179
[
8280
project.root / "README.md",
8381
self.env.get_template("README.md"),
8482
{
85-
'type_name': project.type_name,
86-
'schema_path': project.schema_path,
87-
'project_path': self.package_name,
88-
'executable': EXECUTABLE
89-
}
83+
"type_name": project.type_name,
84+
"schema_path": project.schema_path,
85+
"project_path": self.package_name,
86+
"executable": EXECUTABLE,
87+
},
9088
],
9189
[
9290
project.root / "requirements.txt",
9391
self.env.get_template("requirements.txt.jinja2"),
94-
# until cfn_resource has it's own pypi package, this will need to be updated to point to the absolute
95-
# path for the src folder in your working copy
96-
{'cfn_resource_version': self.cfn_resource_version}
97-
]
92+
# until cfn_resource has it's own pypi package, this will need to be
93+
# updated to point to the absolute path for the src folder in your
94+
# working copy
95+
{"cfn_resource_version": self.cfn_resource_version},
96+
],
9897
]
9998

10099
for path, template, kwargs in templates:
@@ -119,7 +118,7 @@ def generate(self, project):
119118
[
120119
resource_model_path,
121120
self.env.get_template("resource_model.py.jinja2"),
122-
{'properties': project.schema["properties"]}
121+
{"properties": project.schema["properties"]},
123122
]
124123
]
125124

@@ -141,7 +140,7 @@ def write_with_relative_path(path, base=project.root):
141140

142141
resource_model_path = project.root / "resource_model"
143142
handlers_path = project.root / self.package_name
144-
deps_path = project.root / 'build'
143+
deps_path = project.root / "build"
145144

146145
self._docker_build(project)
147146
write_with_relative_path(resource_model_path)
@@ -153,19 +152,20 @@ def write_with_relative_path(path, base=project.root):
153152
def _docker_build(cls, project):
154153
LOG.debug("Dependencies build started")
155154
docker_client = docker.from_env()
156-
volumes = {str(project.root): {'bind': '/project', 'mode': 'rw'}}
157-
with open(project.root / 'requirements.txt', 'r') as f:
155+
volumes = {str(project.root): {"bind": "/project", "mode": "rw"}}
156+
with open(project.root / "requirements.txt", "r") as f:
158157
for line in f.readlines():
159158
if line.startswith("/"):
160-
line = line.rstrip('\n')
161-
volumes[line] = {'bind': line, 'mode': 'ro'}
159+
line = line.rstrip("\n")
160+
volumes[line] = {"bind": line, "mode": "ro"}
162161
logs = docker_client.containers.run(
163-
image='lambci/lambda:build-{}'.format(cls.RUNTIME),
164-
command='pip install --upgrade -r /project/requirements.txt -t /project/build/',
162+
image="lambci/lambda:build-{}".format(cls.RUNTIME),
163+
command="pip install --upgrade -r /project/requirements.txt -t "
164+
"/project/build/",
165165
auto_remove=True,
166-
volumes=volumes
166+
volumes=volumes,
167167
)
168-
LOG.debug("pip install logs: \n%s", logs.decode('utf-8'))
168+
LOG.debug("pip install logs: \n%s", logs.decode("utf-8"))
169169

170170

171171
class Python37LanguagePlugin(Python36LanguagePlugin):

0 commit comments

Comments
 (0)