diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..841036d --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[run] +branch = True + +[report] +fail_under = 100 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c58da1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +.DS_Store +.idea/ +.vscode/ +*.tar.gz + +# We want to allow the tests/lib folder +!tests/lib + +# Node.js +node_modules/ +coverage/ diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..acaad2d --- /dev/null +++ b/.pylintrc @@ -0,0 +1,24 @@ +[MASTER] + +ignore=CVS,models.py,handlers.py +jobs=1 +persistent=yes + +[MESSAGES CONTROL] + +disable= + missing-docstring, # not everything needs a docstring + fixme, # work in progress + bad-continuation, # clashes with black + too-few-public-methods, # triggers when inheriting + ungrouped-imports, # clashes with isort + duplicate-code, # broken, setup.py + +[BASIC] + +good-names=e,ex,f,fp,i,j,k,n,_ + +[FORMAT] + +indent-string=' ' +max-line-length=88 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..efab0a1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Eduardo Rodrigues + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..621ea9d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,7 @@ +include README.md +include LICENSE + +graft python/rpdk/typescript + +# last rule wins, put excludes last +global-exclude __pycache__ *.py[co] .DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..02161e1 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# DEVELOPER PREVIEW (COMMUNITY DRIVEN) + +We're excited to share our progress with adding new languages to the CloudFormation CLI! This plugin is an early preview prepared by the community, and not ready for production use. + +## AWS CloudFormation Resource Provider TypeScript Plugin + +The CloudFormation CLI (cfn) allows you to author your own resource providers that can be used by CloudFormation. + +This plugin library helps to provide TypeScript runtime bindings for the execution of your providers by CloudFormation. + +Usage +----- + +If you are using this package to build resource providers for CloudFormation, install the [CloudFormation CLI TypeScript Plugin](https://github.com/eduardomourar/cloudformation-cli-typescript-plugin) - this will automatically install the the [CloudFormation CLI](https://github.com/aws-cloudformation/cloudformation-cli)! A Python virtual environment is recommended. + +**Prerequisites** + + - Python version 3.6 or above + - Your choice of TypeScript IDE + +**Installation** + +```shell +pip3 install git+https://github.com/eduardomourar/cloudformation-cli-typescript-plugin.git#egg=cloudformation-cli-typescript-plugin +``` + +Refer to the [CloudFormation CLI User Guide](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-types.html) for the [CloudFormation CLI](https://github.com/aws-cloudformation/cloudformation-cli) for usage instructions. + + +Development +----------- + +For changes to the plugin, a Python virtual environment is recommended. Check out and install the plugin in editable mode: + +```shell +python3 -m venv env +source env/bin/activate +pip3 install -e /path/to/cloudformation-cli-typescript-plugin +``` + +You may also want to check out the [CloudFormation CLI](https://github.com/aws-cloudformation/cloudformation-cli) if you wish to make edits to that. In this case, installing them in one operation works well: + +```shell +pip3 install \ + -e /path/to/cloudformation-cli \ + -e /path/to/cloudformation-cli-typescript-plugin +``` + +That ensures neither is accidentally installed from PyPI. + +Linting and running unit tests is done via [pre-commit](https://pre-commit.com/), and so is performed automatically on commit after being installed (`pre-commit install`). The continuous integration also runs these checks. Manual options are available so you don't have to commit: + +```shell +# run all hooks on all files, mirrors what the CI runs +pre-commit run --all-files +# run unit tests only. can also be used for other hooks, e.g. black, flake8, pylint-local +pre-commit run pytest-local +``` + +License +------- + +This library is licensed under the MIT License. diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..5956421 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,42 @@ +[metadata] +license_file = LICENSE +description-file = README.md + +[flake8] +exclude = + .git, + __pycache__, + build, + dist, + *.pyc, + *.egg-info, + .cache, + .eggs, + .tox +max-complexity = 10 +max-line-length = 88 +select = C,E,F,W,B,B950 +# C812, C815, W503 clash with black, F723 false positive +ignore = E501,C812,C815,C816,W503,F723 + +[isort] +line_length = 88 +indent = ' ' +multi_line_output = 3 +default_section = FIRSTPARTY +skip = env +include_trailing_comma = true +combine_as_imports = True +force_grid_wrap = 0 +known_first_party = rpdk +known_third_party = boto3,botocore,jinja2,jsonschema,werkzeug,yaml,requests + +[tool:pytest] +# can't do anything about 3rd party modules, so don't spam us +filterwarnings = + ignore::DeprecationWarning:botocore + ignore::DeprecationWarning:werkzeug + ignore::DeprecationWarning:yaml + +[mypy-setuptools] # don't want to stub external libraries for now +ignore_missing_imports = True diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..36f7e28 --- /dev/null +++ b/setup.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +"""Typescript language support for the CloudFormation CLI""" +import os.path +import re + +from setuptools import setup + +HERE = os.path.abspath(os.path.dirname(__file__)) + + +def read(*parts): + with open(os.path.join(HERE, *parts), "r", encoding="utf-8") as fp: + return fp.read() + + +# https://packaging.python.org/guides/single-sourcing-package-version/ +def find_version(*file_paths): + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + +setup( + name="cloudformation-cli-typescript-plugin", + version=find_version("python", "rpdk", "typescript", "__init__.py"), + description=__doc__, + long_description=read("README.md"), + author="eduardomourar", + url="https://github.com/eduardomourar/cloudformation-cli-typescript-plugin", + packages=["rpdk.typescript"], + package_dir={"": "python"}, + # package_data -> use MANIFEST.in instead + include_package_data=True, + zip_safe=True, + python_requires=">=3.6", + install_requires=["cloudformation-cli>=0.1,<0.2", "docker>=3.7,<3.8"], + entry_points={ + "rpdk.v1.languages": [ + "typescript = rpdk.typescript.codegen:TypescriptLanguagePlugin", + ] + }, + license="MIT", + classifiers=[ + "Development Status :: 2 - Pre-Alpha", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT/X Consortium License", + "Natural Language :: English", + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Code Generators", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + ], + keywords="Amazon Web Services AWS CloudFormation", +)