Welcome hacker!
This document will make your life easier by helping you setup a development environment, IDEs, tests, coding practices, or anything that will help you be more productive. If you found something is missing or inaccurate, update this guide and send a Pull Request.
Note
You need to have pyenv installed, please see the installation instructions for more information.
make setup
will perform the following steps for you. You can either run make setup
command or perform the
steps manually.
Python 2.7 is our officially supported Python version. We have a future goal to support to Python3.6 but the code base currently does not work with Python3. To make future migration easier, any new code we write must be compatible with Python3. Follow the idioms from this excellent cheatsheet to make sure your code is compatible with both Python versions.
Setup Python locally using pyenv
- Install PyEnv -
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
pyenv install 2.7.14
- Make the Python version available in the project:
pyenv local 2.7.14
Virtualenv allows you to install required libraries outside of the Python installation. A good practice is to setup a different virtualenv for each project. pyenv comes with a handy plugin that can create virtualenv.
- Create new virtualenv if it does not exist:
pyenv virtualenv 2.7.14 samtranslator27
pyenv activate samtranslator27
- [Optional] Automatically activate the virtualenv in for this folder:
pyenv local samtranslator27
Install dependencies by running the following command. Make sure the Virtualenv you created above is active.
pip install -r requirements/base.txt -r requirements/dev.txt
make test
command will run all unit tests. This command is configured to fail when code coverage for package
drops below 95%.
pytest -k "TestMyClass"
command will run all unit tests within the TestMyClass class.
Before sending pull requests make sure to run make pr
command. This will run unit tests, linters, and static
analysis tools to verify that your code changes follow the coding standards required by this package.
It will also fail if unit test coverage drops below 95%. All new code that you write must have 100% unit test coverage. This might sound over-ambitious, especially if you come from Java world, but with Python this is actually realistic. In Python, if you do not test a piece of code, there is zero confidence that the code will ever work in the future. Tests are also a documentation of the success and failure cases, which is crucial when refactoring code in future.
Install snakeviz pip install snakeviz
`
python -m cProfile -o sam_profile_results bin/sam-translate.py translate --input-file=tests/translator/input/alexa_skill.yaml --output-file=cfn-template.json
snakeviz sam_profile_results
`