daun-io / fussy-lazy-python-styleguide

python styleguide for fussy but lazy people

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fussy lazy python styleguide

Beautiful is better than ugly, Readability counts. But it takes time and efforts to figure out best answers.
We're standing on the shoulders of giants, styling should be easy and fast.

IDE

We recommend vscode for best community supports and latest features

Documented Rules

We use linter to keep rules in mind however you can also check one of best practice

Linter

Use pylint. Pylint is a Python static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells and offers simple refactoring suggestions.

pip install pylint

You can manually lint your scripts before commit like this.

pylint your_script.py

However you'll probably forget about linting if you're doing it manually everytime. You can discover ways of integrating your linter within vscode.
Keep trying to get better scores from pylint so you can achieve better code.

Formatter

Import-order sorting

Use isort. isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type. It provides a command line utility, Python library and plugins for various editors to quickly sort all your imports. It requires Python 3.6+ to run but supports formatting Python 2 code too.

pip install isort

You can manually format your scripts before commit like this.

black your_script.py

Overall formatting

Use 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.

pip install black

You can manually format your scripts before commit like this.

black your_script.py

You should also check for the integration which helps formatting for everytime you save your code.

Although isort and black has different style of formatting for some importing stuffs you can control it by executing isort first and black later.

isort your_script.py && black your_script.py

Docstring

Use autodocstring. autodocstring is a vscode extension to quickly generate docstrings for python functions. Among docstring formats that autodocstring supports, we recommend 'Google' format.

Efforts to cover more laziness

You can also check following toolings.

  • PathIntellisense for autocompleting file path
  • Prettier for formatting surroundings scripts (including .json, .yaml, etc)

About

python styleguide for fussy but lazy people