tetrahedron-technologies / pydhsfw

Python-based Distributed Hardware Server FrameWork for extending DCSS beamline control system and enabling development in python.
MIT License
3 stars 0 forks source link

Implement flake8 and black formatting #104

Open dsclassen opened 3 years ago

dsclassen commented 3 years ago

I would like to implement two features to our development pipeline.

1.) Black Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.

Black makes code review faster by producing the smallest diffs possible.

https://pypi.org/project/black/

2.) Flake8 The Flake8 linter tool which should make our code mote PEP compliant. https://flake8.pycqa.org/en/latest/index.html

I will add a pre-commit also to check that all this formatting is done before performing a git commit. https://pre-commit.com

dsclassen commented 3 years ago

This is how you can configure VSC to use Black as the auto formatter:

https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0

dsclassen commented 3 years ago

Also you can add these setting to the project-specific settings.json to enable linting with flake8 in VSC that is compatible with Black:

    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.flake8Args": [
        "--ignore=E203",
        "--ignore=E266",
        "--ignore=E501",
        "--ignore=W503",
        "--max-line-length=88",
        "--select = B,C,E,F,W,T4,B9",
        "--max-complexity = 18"
    ],

more details here: https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0