These guidelines aim to maintain code quality, clearly communicate the state of the codebase, and standardize the development workflow. Use your best judgment, and feel free to propose changes to the guidelines by submitting a pull request.
- Preparing the environment
- Updating dependencies
- Git Workflow
- How to work on a feature branch
- How to deploy
Install Docker Engine using the docker official instructions (avoid snap packages) and the docker compose plugin. No other system dependencies are required.
- First, clone the repository.
git clone https://github.com/GlobalFishingWatch/python-app-template.git- Make sure you can build the docker image:
make docker-build- In order to be able to connect to BigQuery, authenticate and configure the project:
make docker-gcpInstall UV for faster installs (otherwise modify Makefile to use regular pip):
make uv- Create virtual environment and activate it:
make venv
./.venv/bin/activate- Install all dependencies for development and the python package in editable mode:
make install- (Optional) Install pre-commit hooks:
make hooksThis step is strongly recommended to maintain code quality and prevent technical debt,
particularly regarding documentation, PEP8 compliance, spelling, and type-hinting.
If this feels too rigid for your current workflow,
at a minimum, make regular use of the provided Makefile commands:
format, lint, codespell, and typecheck.
PEP8 checks will be enforced in the GitHub CI.
- Make sure you can run unit tests:
make testNote
Alternatively,
you can handle all the development inside a docker container
without installing dependencies in a virtual environment.
Use make docker-shell to enter a docker container.
The requirements.txt file contains all transitive dependencies pinned to specific versions. It is automatically generated using pip-tools, based on the dependencies specified in pyproject.toml. This process ensures reproducibility, allowing the application to run consistently across different environments.
Use pyproject.toml to define high-level dependencies with flexible version constraints (e.g., ~=1.2, >=1.0, <2.0, ...).
To re-compile dependencies, just run
make reqsIf you want to upgrade all dependencies to latest compatible versions, just run:
make reqs-upgradeImportant
Do not modify requirements.txt manually.
Note
Remember that if you change the requirements.txt,
you need to rebuild the docker image (make docker-build) in order to use it locally.
There are two main Git workflows commonly used in software development: Git Flow and GitHub Flow. We encourage using GitHub Flow whenever possible, as it is a lightweight workflow that supports rapid iteration, continuous delivery, and simpler branching. It works especially well for teams that deploy frequently and want to keep their main branch always production-ready. However, if your project involves a long release cycle and a long release process, or you need an unstable shared branch like develop for ongoing integration, then Git Flow may be more appropriate. You can read a summary of both workflows in GITHUB-FLOW.md and GIT-FLOW.md.
To work on a new feature or fix,
create a branch from main or develop,
depending on the workflow your team follows.
Try to follow these guidelines:
-
Branch names should be descriptive and concise, all lowercase and with words separated by hyphens "-". Optionally, feature branch names can be prefixed with JIRA ticket. For example, you can use something like
PIPELINE-2020-name-of-the-branch. -
Write clear commit messages. See How to Write a Git Commit Message.
-
Maintain a clean commit history in your feature branch. Use interactive rebase (
git rebase -i) to squash, reorder, or edit commits.1 -
If you are not using pre-commit hooks, use the provided Makefile commands (
format,lint,codespell,typecheck) as much as possible to maintain code quality. -
Add unit tests for each piece of code:
- Avoid connecting to external services during unit tests. Use mocks as needed.
- Ensure unit tests run as fast as possible.
-
When submitting a Pull Request (PR), ensure it meets the following criteria:
- It targets the correct base branch (depending on the chosen Git Workflow).
- It is focused and limited in scope to simplify the review process.
- Its description includes a link to the related JIRA ticket to support integration between the issue and the PR.
A Google Cloud build that publishes a Docker image is triggered in the following cases:
- When a commit is merged into
mainordevelop. - When a new tag is created.
Footnotes
-
When performing a rebase, it's acceptable to
push --forceto your own feature branch, but never on shared branches. Protectmainand/ordevelopfrom force pushes via GitHub settings. ↩