How to contribute to Flask

Posted on Sat 13 May 2017 in Software Engineering

I want to contribute to Python Flask microframework. I read its CONTRIBUTING.rst file from GitHub. I encountered few issues because the documentation is not clear for me. It even sounds to be outdated.

I share here the steps that will allow you to later contribute to Flask. I hope they are more straightforward and clear than the official How to contribute to Flask.

Step 1. I cloned the repository:

git clone https://github.com/pallets/flask.git

The cloned repository is called by default flask. I renamed to something else:

mv flask/ contribute_to_flask/

I know it is all Ok to keep the name as it is, but because it contains a subfolder called also flask, I wanted to distinguish the parent from the child folder:

cd contribute_to_flask/ && ls
artwork           docs      Makefile     setup.cfg              tox.ini
AUTHORS           examples  MANIFEST.in  setup.py
CHANGES           flask     README       test-requirements.txt
CONTRIBUTING.rst  LICENSE   scripts      tests

Step 2. I create a virtual environment inside contribute_to_flask folder and installed pytest and tox:

virtualenv my_venv

The virtual environment can be anywhere except inside contribute_to_flask/flask/ folder. This is in order to avoid Flask to think that it's installed rather than running locally. The test doesn't expect the project to appear to be installed1. I then activated the virtual environment:

cd my_venv
source bin/activate

I installed pytest to perform unit testing:

pip install pytest

I also installed tox in order to run all tests against multiple combinations Python versions and dependency versions

pip install tox

Step 3. I installed Flask as an editable package using the current source:

pip install --editable .

Step 4. I installed the test requirements:

pip install -r test-requirements.txt

The -r option is there to specify that pip must is going to install requirements usually listed in a plain text file.

Step 5. I run the tests:

pytest tests/

I got this output: 332 passed, 10 skipped in 32.86 seconds.

Step 6. I installed and run the test coverage:

pip install pytest-cov

The test coverage:

pytest --cov=flask tests/

It seems there is a good code coverage:

----------- coverage: platform linux, python 3.5.2-final-0 -----------
Name                    Stmts   Miss  Cover
-------------------------------------------
flask/__init__.py          17      0   100%
flask/__main__.py           4      4     0%
flask/_compat.py           52     28    46%
flask/app.py              580     42    93%
flask/blueprints.py       159     36    77%
flask/cli.py              275     85    69%
flask/config.py            90      2    98%
flask/ctx.py              151     23    85%
flask/debughelpers.py      91     12    87%
flask/ext/__init__.py       7      0   100%
flask/exthook.py           61      3    95%
flask/globals.py           26      0   100%
flask/helpers.py          324     40    88%
flask/json.py              89     13    85%
flask/logging.py           46      1    98%
flask/sessions.py         143      8    94%
flask/signals.py           29      2    93%
flask/templating.py        82      3    96%
flask/testing.py           65      3    95%
flask/views.py             41      1    98%
flask/wrappers.py          74      4    95%
-------------------------------------------
TOTAL                    2406    310    87%

That is it. Now I am ready to go further.


1 test_main_module_paths fails on RHEL and Ubuntu when using Amazon EC2, #1879