Adam Glos
Careful - OS dependent
OS dependent, because pip is system dependent
code formatters may conflict - it is important to choose a bunch of code formatters which can "cooperate"
Here: isort + black + flake8 + mypy + spelling
isort # for sorting import s
isort --check # for checking if files are sorted
isort --profile black # for consistency with black
black # for formatting
black --check # for checking if files are formatted
flake8 # list all of issues
flake8 only complains - it does not change the code! but looks for fancier issues than black
It's better to first fix with isort and black
mypy only complains - it does not change the code! but looks for fancier issues than black
python -m spelling
One can add file wordlist.txt which will have correct words unknown to spelling
For scientific project:
For python library project:
What if I'm lazy?
You're in the good neighborhood
Flake8 - .flake8
Usually we will need to pass some parameters to formatters - instead one can create configuration files
black and sort - pyproject.toml
Source: https://github.com/euro-hpc-pl/omniqubo (may change over time)
Text
Hide following files from file manager (dangerous)
Text
run black and isort on saving
pre-commit is a tool for verifying the code right before commit
pip install pre-commit
1.
2. Create configuration file .pre-commit-config.yaml
Do on push and commit
isort --check + config file
black --check
remove if not used
3. Install required formatters
pre-commit install
4. run on all files (optional)
pre-commit run --all-files
Cautious - pre-commit DOES NOT use the version installed by you through pip. make sure you have the same version, for example:
Hint: it seems pre-commit can be configured with vsode, but currently it conflicts with conda
Line 3 needs to be removed manually (and isort, black should be run again)
isort
black
commit with pre-commit
manual fixes
Unit test checks a single functionality. In python they should be located in a separate test directory
pytest is a software for automatically running all unit tests
Tests are done through assert if no error is thrown by a function, then the code is "correct"
Note that class and methods begins with test
Hint: "pytest -x" run until the first error
Hint: "pytest -x" run until the first error
Text
Text
test and coverage checking
isort/black/flake8/mypy
Data from GitHub actions
Small projects (<3 small, files mostly self-checking)
medium projects (long-term or big code)
python project