- Fork
- Clone
- Branch named as the new feature or bug you are working on
- Python virtual environment setup
- Code with style
- Commit often, create a legible history
- Assert your work with tests
- Prettify your docummentation
- Pull Request
Fire2a org. members can skip this
git clone git@github.com:fire2a/fire2a-lib.git
cd fire2a-lib
# forgot to fork and have local changes? fork and change the remote url
git remote set-url origin git@github.com:<YOUR-USER-HERE>/fire2a-lib.git
git switch --create <feature-issue-branch>
python -m venv --system-site-packages .venv
source .venv/bin/activate
python -m pip install --upgrade pip
# python -m pip install --upgrade -r requirements.txt
pip install --editable .
# use these linters, formatters, fixers:
pip install -r requirements.code.txt
mypy --install-types
# check configurations at [tool.*] in pyproject.toml
# start with the template
cp src/fire2template/template.py src/fire2a/<new-feature-module>.py
- Create a legible history
- Explain your code/changes with multiple commits (atomic, descriptive)
pytest tests/test_<new-feat>.py
pip install pdoc
pdoc --math fire2template fire2a
-
The best code is the easiest to read, not the most efficient
-
Avoid reinventing the wheel: Research alternatives before coding from scratch
-
Each function/method should:
- Do one thing
- Return one type of object
- Avoid void methods, at least return True or 0 for success
-
DRY: Don't repeat yourself, encapsulate/extract methods whenever possible
- move hard-coded strings to configuration files
- prefer functions over classes
-
Naming is key
- Use consistent and descriptive names that your future you would understand reading two months from now
- Avoid abbreviations, search & replace them to something descriptive before sharing the code
- (Python-style) Variable & methods names all lowercase_with_underscores
- (Python-style) Classes names in CamelCase
-
Documenting:
- At first, develop using in line comments (#)
- Afterwards replace them with docstrings and renaming variables
- Follow the template formatting docstring convention, make sure it looks ok on the live server
- The most important is the initial sentence that describes the method, module, class, etc. (Args, Returns, Raises sections can be AI generated)
- Type annotations for functions, classes and notable variables
-
Unit testing
- Avoid generating random test instances (can be non-deterministic when using without a random number seed)
- At first, develop directly using the
if __name__ == '__main__':
section - Then migrate to its own test/test_stuff.py file