I suggest you to use some lint tools like flake8
to find some PEP8 warnings. Optionally, you can use flake8-black
to automatically find and fix them. This way, you will have a more consistent and unified code style.
- Add
flake8
andflake8-black
(optional) as a dependency torequirements.txt
andtest_requirements.txt
- Create a
.flake8
config file in project's root folderROOT_FOLDER/.flake8
to setup some global flake8 configurations to customize or ignore some warnings/violations (see more here and here).
Example:
# .flake8 file [flake8] ignore = D203, E501, W504, W503, E731, E712 exclude = # No need to traverse our git directory .git, # There's no value in checking cache directories __pycache__, # The conf file is mostly autogenerated, ignore it docs/source/conf.py, *.ipynb_checkpoints*/ # This contains builds of flake8 that we don't want to check dist max-line-length = 111
- Create an entry in
Makefile
to automate lint inspection by running themake lint
on a cmd line terminal:
Example:
# makefile file lint: @flake8 scripts/ tests/
- Optional: To find lint warnings/violations into Drone Pipeline (CI/CD) on a Pull Request, change
./validation/custom_validation.sh
to:
# custom_validation.sh file flake8 ./scripts/
Optional: If you want to automatically find and refactoty code warnings/violations in your local machine:
- Install black for flake8:
pip install flake8-black
(terminal) - Run
black PATH/TO/SOURCE
in a terminal to reformat the code based on PEP8 constraints.