Wask

webapp2 + flask

Tools for adapting webapp2 code to work with flask with minimal changes.

This repo has two goals:

  • Provide a library that is functionally equivalent to webapp2 but runs flask under the hood

  • Support python2 and python3 simultaneously

You should be able to essentially hotswap webapp2 with wask and expect everything to work the same.



🧰 Usage

First of all, don’t use this library for new endpoints. Just use flask.

Wask doesn’t implement this functionality I want!

The goal of Wask is to take the current state of mainapp and adapt it to work with Flask.

There are some aspects of Webapp2 that we have chosen not to implement in Wask because they are not referenced in mainapp at the time of writing this library.

Instead of modifying Wask to add more functionality for your endpoint, you should just refactor your endpoint into a regular Flask endpoint.

🏗️ Setup

The project has some complicated dependencies due to the fact that we have an ancient version of python and a modern version of python in the same project.

To simplify we have an install script that will setup two virtual environments, wask-2 and wask-3.

./scripts/install

Do all of your development in the python 2 environment (``wask-2``), but to use the modern qa tools (black, flake8, mypy) you will need to use the python 3 environment.

After running the install script you should run:

./scripts/setup_pre_commit_hook

🛠️ Scripts

  • ./scripts/install: Installs all of the things and sets up your environments

  • ./scripts/qa: Runs QA tools on your code including tests for python2 and python3

    • args: –format (optional) Will format your code before running qa checks

  • ./scripts/setup_pre_commit_hook: Sets your pre commit hook file to ./scripts/qa so you don’t get surprised by CI failing

🧪 Testing

🦒 Unit tests

The purpose of wask is to be functionally equivalent to webapp2. So we have included webapp2 in our dev dependencies.

Our testing strategy is to run all of our tests with both our Wask classes and the webapp2 classes they are meant to replicate the behaviour of.

If a test fails when running a webapp2 class, its not webapp2 that is wrong its the test that is wrong. If we find a bug in webapp2 we need to recreate that bug in Wask.

Webapp2 is not compatible with python 3, but we need our library to be compatible with python3. So our unit tests will not run the webapp2 tests when you run pytest with python 3.

To ensure all of the tests are running, make sure to run them with the wask-2 environment.

🤖 Using tox

Make sure your active environment wasn’t activated with pyenv activate ...:

pyenv deactivate

Specify multiple versions with pyenv local so that tox is able to find all the necessary versions of Python:

pyenv local wask-2 3.6 3.7 3.8 3.11

Run tox:

tox