Skip to content

update code formatting and buildspec #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
92 changes: 92 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
exclude: ^(buildspec.yml|.pre-commit-config.yaml)$
fail_fast: true
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.17
hooks:
- id: isort
# language_version: python3.6
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
exclude: templates/
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
- id: check-case-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- --fix=lf
- id: trailing-whitespace
- id: flake8
additional_dependencies:
- flake8-bugbear>=19.3.0
- flake8-builtins>=1.4.1
- flake8-commas>=2.0.0
- flake8-comprehensions>=2.1.0
- flake8-debugger>=3.1.0
- flake8-pep3101>=1.2.1
# language_version: python3.6
exclude: templates/resource_model.py
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-sort-keys
- id: check-merge-conflict
# - id: check-yaml # doesn't work with CloudFormation templates/intrinsics, should use cfn-lint instead
# language_version: python3.6
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.3.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-log-warn
- repo: https://github.com/PyCQA/bandit
rev: f5a6f0ca62 # TODO: update once a release > 1.5.1 hits with this change in
hooks:
- id: bandit
files: "^src/"
# have to skip B322, as there is no way to indicate the codebase is Python 3 only (input only vulnerable in Py2)
args: ["--skip", "B322"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.711'
hooks:
- id: mypy
files: "^src/"
- repo: local
hooks:
- id: pylint-local
name: pylint-local
description: Run pylint in the local virtualenv
entry: pylint "setup.py" "src/" "tests/"
language: system
# ignore all files, run on hard-coded modules instead
pass_filenames: false
always_run: true
- id: pytest-local
name: pytest-local
description: Run pytest in the local virtualenv
entry: pytest --cov="rpdk.python" --doctest-modules --ignore "tests/data" "tests/"
language: system
# ignore all files, run on hard-coded modules instead
pass_filenames: false
always_run: true
- id: pytest-cfn_resource-local
name: pytest-cfn_resource-local
description: Run pytest against the cfn_resource module in the local virtualenv
entry: pytest --cov="cfn_resource" --doctest-modules "src/tests/" --rootdir="src/"
language: system
# ignore all files, run on hard-coded modules instead
pass_filenames: false
always_run: true
#- id: functional-tests
# name: functional-tests
# description: Runs functional tests using sam-local
# entry: >
# tests/functional-tests.sh src/
# language: system
# pass_filenames: false
# always_run: true
6 changes: 1 addition & 5 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,4 @@ good-names=e,ex,f,fp,i,j,k,n,_
[FORMAT]

indent-string=' '
max-line-length=120

[DESIGN]
max-attributes=12
max-args=7
max-line-length=88
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Contributing Guidelines

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

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


## Reporting Bugs/Feature Requests

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

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
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
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

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

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


## Finding contributions to work on
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.
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.


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


Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AWS Cloudformation Rpdk Python Plugin
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

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

License
-------
Expand Down
37 changes: 15 additions & 22 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
version: 0.2
phases:
pre_build:
install:
commands:
- pip install --upgrade pip wheel
# make sure pip/setuptools/wheel is up to date, awscli for SDK patching
- pip install --upgrade pip setuptools wheel awscli -r requirements.txt
- aws configure add-model --service-model "file://$CODEBUILD_SRC_DIR_RPDK/cloudformation-2010-05-15.normal.json" --service-name cloudformation
build:
commands:
# install aws-cloudformation-rpdk
- cd "$CODEBUILD_SRC_DIR_RPDK"
- pip install .
# patch boto3/awscli with internal SDK (must be done after RPDK is installed, since awscli is a dep currently)
- aws configure add-model --service-model "file://cloudformation-2010-05-15.normal.json" --service-name cloudformation
# install aws-cloudformation-rpdk-python-plugin (Python)
- cd "$CODEBUILD_SRC_DIR"
- ls -la
- pip install . # -r requirements.txt (currently no testing/linting dependencies)
# work around https://github.com/boto/botocore/issues/1733
- pip install 'urllib3<1.25'
# run unit tests/linting here
- pip install pytest pylint
- pytest
- pylint python/rpdk/python/ src/
# end-to-end test - need privileged codebuild job and docker installed in container
# - pip install aws-sam-cli
# - ./tests/functional-tests.sh ${CODEBUILD_SRC_DIR}/src/
# install aws-cloudformation-rpdk-python-plugin and rpdk core
- pip install "$CODEBUILD_SRC_DIR_RPDK" .
# run lints/tests
- pre-commit run --all-files
# end-to-end test
- DIR=$(mktemp -d)
- cd "$DIR"
- ls -la
- |
echo "AWS::Foo::Bar
1" | uluru-cli init -vv # python3.6
1" | cfn-cli init -vv # python3.6
- ls -la
- DIR=$(mktemp -d)
- cd "$DIR"
- ls -la
- |
echo "AWS::Foo::Bar
2" | uluru-cli init -vv # python3.7
2" | cfn-cli init -vv # python3.7
- ls -la
71 changes: 36 additions & 35 deletions python/rpdk/python/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import shutil

import docker

from rpdk.core.plugin_base import LanguagePlugin


LOG = logging.getLogger(__name__)

EXECUTABLE = "uluru-cli"
OLD_VIRTUAL_ENV = ''
EXECUTABLE = "cfn-cli"
OLD_VIRTUAL_ENV = ""
OLD_PATH = []


Expand All @@ -28,7 +26,7 @@ def __init__(self):
self.package_name = None
self.schema_filename = None
self.namespace = None
self.cfn_resource_version = 'cfn_resource==0.0.1'
self.cfn_resource_version = "cfn_resource==0.0.1"

def _package_from_project(self, project):
self.namespace = tuple(s.lower() for s in project.type_info)
Expand Down Expand Up @@ -57,44 +55,46 @@ def init(self, project):

templates = [
[
project.root / "Handler.yaml",
self.env.get_template("Handler.yaml"),
project.root / "template.yml",
self.env.get_template("template.yml"),
{
'resource_type': project.type_name,
'handler_params': {
"resource_type": project.type_name,
"handler_params": {
"Handler": project.entrypoint,
"Runtime": project.runtime,
"CodeUri": self.CODE_URI.format(self.package_name),
}
}
"Timeout": 900,
},
},
],
[
project.root / self.package_name / "handlers.py",
self.env.get_template("handlers.py"),
{}
{},
],
[
project.root / self.package_name / "__init__.py",
self.env.get_template("__init__.py.jinja2"),
{}
self.env.get_template("__init__.py"),
{},
],
[
project.root / "README.md",
self.env.get_template("README.md"),
{
'type_name': project.type_name,
'schema_path': project.schema_path,
'project_path': self.package_name,
'executable': EXECUTABLE
}
"type_name": project.type_name,
"schema_path": project.schema_path,
"project_path": self.package_name,
"executable": EXECUTABLE,
},
],
[
project.root / "requirements.txt",
self.env.get_template("requirements.txt.jinja2"),
# until cfn_resource has it's own pypi package, this will need to be updated to point to the absolute
# path for the src folder in your working copy
{'cfn_resource_version': self.cfn_resource_version}
]
self.env.get_template("requirements.txt"),
# until cfn_resource has it's own pypi package, this will need to be
# updated to point to the absolute path for the src folder in your
# working copy
{"cfn_resource_version": self.cfn_resource_version},
],
]

for path, template, kwargs in templates:
Expand All @@ -118,8 +118,8 @@ def generate(self, project):
templates = [
[
resource_model_path,
self.env.get_template("resource_model.py.jinja2"),
{'properties': project.schema["properties"]}
self.env.get_template("resource_model.py"),
{"properties": project.schema["properties"]},
]
]

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

resource_model_path = project.root / "resource_model"
handlers_path = project.root / self.package_name
deps_path = project.root / 'build'
deps_path = project.root / "build"

self._docker_build(project)
write_with_relative_path(resource_model_path)
Expand All @@ -153,19 +153,20 @@ def write_with_relative_path(path, base=project.root):
def _docker_build(cls, project):
LOG.debug("Dependencies build started")
docker_client = docker.from_env()
volumes = {str(project.root): {'bind': '/project', 'mode': 'rw'}}
with open(project.root / 'requirements.txt', 'r') as f:
volumes = {str(project.root): {"bind": "/project", "mode": "rw"}}
with open(project.root / "requirements.txt", "r") as f:
for line in f.readlines():
if line.startswith("/"):
line = line.rstrip('\n')
volumes[line] = {'bind': line, 'mode': 'ro'}
line = line.rstrip("\n")
volumes[line] = {"bind": line, "mode": "ro"}
logs = docker_client.containers.run(
image='lambci/lambda:build-{}'.format(cls.RUNTIME),
command='pip install --upgrade -r /project/requirements.txt -t /project/build/',
image="lambci/lambda:build-{}".format(cls.RUNTIME),
command="pip install --upgrade -r /project/requirements.txt -t "
"/project/build/",
auto_remove=True,
volumes=volumes
volumes=volumes,
)
LOG.debug("pip install logs: \n%s", logs.decode('utf-8'))
LOG.debug("pip install logs: \n%s", logs.decode("utf-8"))


class Python37LanguagePlugin(Python36LanguagePlugin):
Expand Down
6 changes: 3 additions & 3 deletions python/rpdk/python/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Congratulations on starting development! Next steps:
1. Write the JSON schema describing your resource, `{{ schema_path.name }}`
2. Implement your resource handlers in `{{ project_path }}/handlers.py`

> Don't modify files in `resource_model/` by hand, any modifications will be overwritten when `generate` or
`package` commandsare run.
> Don't modify files in `resource_model/` by hand, any modifications will be overwritten when `generate` or
`package` commandsare run.

Implement CloudFormation resource here. Each function must return a ProgressEvent.

Expand All @@ -19,5 +19,5 @@ ProgressEvent(
# callback_delay_minutes=0 # setting to a value > 0 will re-call handler after specified time
)

Failures can be passed back to CloudFormation by either raising an exception, preferably one of cfn_resource.exceptions
Failures can be passed back to CloudFormation by either raising an exception, preferably one of cfn_resource.exceptions
operation_status to Status.FAILED and error_code to one of cfn_resource.exceptions
Loading