This repo is the home of a proposed standardized development environment for python flask applications. It is meant only to be a starting point (i.e. fork it) rather than an upstream repo that pushes changes down.
The goal is that any developer of any seniority level or familiarity with Python can start from a new Mac and be writing code within 15 minutes.
If you are getting a docker env up for the first time you will first need to install docker and a few other goodies. Otherwise skip to the Dev Env Config section below.
In general, the goal of this project is to separate the code and configuraiton of a service from its run time environment. This allows the run time and configuration to be more easily maintained. (It's a form of loose coupleing)
You will need to install docker on your machine. The preferred way to do so these days is via Homebrew:
brew install --cask docker
!!! note
There are other ways to install Docker, however this one avoids the need for other components such as virtualbox, etc.
!!! warning
The first time you run the docker daemon, launch it via the GUI and accept the terms of service or you'll end up in a bit of a loop trying to trouble- shoot
In order to take advantage of some local feedback loops, and keep git hooks
under source control using the pre-commit
tool:
brew install pre-commit
Now git will look for hooks in .pre-commit-config.yaml
and the team can share changes
to them in the usual way we manage code.
This environment was conceived under the notion that a dev, at any time could start work in a repo based on it within 15 minutes of deciding to do so.
docker build --tag wine-purse .
You can verify you have a good build by running the container interactively:
docker compose up
Visit the fancy app http://127.0.0.1:8000
Docker provides an outstanding GUI for developers to leverage. Find the Docker Desktop application.
- In the left menu, click on the "Containers" icon.
- You will see a list with your one stack in it.
- Click to expand the stack.
- Click on the Name of the container (not the stack)
- you are looking at the container Logs!
- Reload your browser and see a new request come up
- In the upper right are some controls in circles.
- Click on the CLI control and type.
- This leaves you sitting as the
root
user at a shell prompt. Try the following to get an idea of how development will work.- Container: Type
bash
to get a more familiar and functional shell. - Container:
cd /opt/app
- Container:
cat __init__.py
- Local Code Editor: Add the comment
# I am coding
to the top of__init__.py
and save - Container:
cat __init__.py
- Container: Type
- This leaves you sitting as the
- In the running continer issue the command:
env | grep FLASK
- You will see the values that are set in the containers environment
from the
docker-compose.yml
file.
- You will see the values that are set in the containers environment
from the
- Click on the CLI control and type.
- Local Code Editor: Edit app/routes.py and change the string to
"Hello Tackle world"
- Note that when you save the file the logs role to show the server
restarted. This is real time development based on a Flask construct
of running with the
FLASK_ENV
set to "development" - Reload your browser and see that your change took effect. This works because the code on your workstation is mounted as if in the running container. Changes locally are reflected in the container in real time.
- Note that when you save the file the logs role to show the server
restarted. This is real time development based on a Flask construct
of running with the
Once you are done poking around in the container, exit (container will stop) and continue.
pre-commit
must be enabled on a per-repo basis. Before getting started, run
pre-commit install
pre-commit autoupdate
This environment was conceived under the notion that a dev, at any time could start work in a repo based on it within 15 minutes of deciding to do so.
From the tooling tips above, be sure you are familiar with the Docker Desktop and how to find the logs of your running container.
See .pylintrc
for details on opinions.
Manually run the linter with the command:
docker compose run web pylint --recursive=y /opt/service
Output will come directly to your CLI and will be present in the logs of the container you can find in Docker Desktop.
!!! TODO - Need better generalized test invocation.
docker compose run web pytest /opt/service/app/routes.py
!!! Warning
This section is currently chaotic as various integrations are being tried and configs hacked at. YMMV!
System Python on the Mac is generally not supported by IDEs these days. You will need to install Python yourself.
brew install python3
You will then need to install the Python extention to VS code. Click here to go to the website and follow the directions.
Next is to install the linter. We are using pylint
Add
{
"python.linting.pylintEnabled": true,
}
To your settings.json
file.
EOF