Recommendations
Automate your tests
Your code should not only run on your machine. To make sure this is the case you can use tools like tox.
Personally, I prefer nox, because it uses standard python files for configuration.
(And on top of that I also use nox-poetry to ensure versions from my poetry.lock
file are respected)
Test your code
If you use a tool like recite
you probably do not need somebody to tell you, that you should write tests for your code. I like to use pytest.
Style-guide and other quality checks
You should ensure your Python code adheres to the style guide according to PEP 8. To check this you should use flake8. There are a ton of plugins, to enhance this. I like to use the following:
name | description |
---|---|
flake8-eradicate | Find commented out or dead code |
flake8-isort | Check if code is sorted according to isort |
flake8-debugger | Check for debugger statements |
flake8-comprehensions | Write better list/set/dict comprehensions |
flake8-print | Check for print statements (you should use logging in most cases) |
flake8-black | Check if code is formatted according to black's style |
flake8-bugbear | Find likely bugs and design problems |
darglint | Check that docstring matches the definition |
pydocstyle | Check for compliance with python docstring convention |
Since flake8 cannot be configured via pyproject.toml
I use pyproject-flake8 to have all configuration in one place.
Furthermore I use pyroma to make sure my project complies with the best practices of the python packaging ecosystem.
Static type-checking via mypy can in many cases find bugs early.