Требования к питоньему коду
После поста про погружение новых программистов, много ребят попросили выложить наши требования к коду в в mtrl.ai. Я даже не думал, что на канале столько питонистов.
Формальных требований у нас совсем немного — все требования мы стараемся выражать при помощи автоматизированных инструментов в IDE и CI, чтобы несоответствие стандартам выявлялось на этапе написания кода, а не на код ревью.
На питоне вы для этого используем кучу плагинов для flake8, кроме стандартных это commas, bugbear, isort, print. Еще ждем релиза pep8-naming с моим патчем.
С радостью приветствуем установку новых плагинов, с единственным условием — вся доработка кодовой базы под соответствие обновлённым стандартам лежит на разработчике. Это не такая сложная задача, если владеть регулярками.
А вот и сами требования (на английском, по историческим причинам).
Style
— Obey django's style guide.
— Configure your IDE to use flake8 for checking your python code. For running flake8 manualy, do
— Prefer English over your native language in comments and commit messages.
— Commit messages should contain the unique id of issue they are linked to (refs #100500 -- changed smth)
— Every model and a model method should have a docstring.
Testing
— We use TDD, so all of your code (except admin declarations) should be covered by tests.
— Unit tests are split into 4 categories:
— Unit (check at least 90% of the flow graph for every method)
— Functional: business-logic, cross-app relations, testing views
— API
— Integration: integration with other services or complex business-cases, like creating an order with certain payment type and delivery.
Code organisation
— DRY and KISS.
— Obey django best practices.
— Make models fat. No logic is allowed within the views or templates. Only models.
— Use PEP-484 type hints when possible.
— Prefer composition over inheritance.
— Prefer Manager methods over static model methods.
— Obey Attribute\method order for your models.
— Do not use signals for business logic. Signals are good only for notification purposes.
— No l10n is allowed in python code, use django translation.
После поста про погружение новых программистов, много ребят попросили выложить наши требования к коду в в mtrl.ai. Я даже не думал, что на канале столько питонистов.
Формальных требований у нас совсем немного — все требования мы стараемся выражать при помощи автоматизированных инструментов в IDE и CI, чтобы несоответствие стандартам выявлялось на этапе написания кода, а не на код ревью.
На питоне вы для этого используем кучу плагинов для flake8, кроме стандартных это commas, bugbear, isort, print. Еще ждем релиза pep8-naming с моим патчем.
С радостью приветствуем установку новых плагинов, с единственным условием — вся доработка кодовой базы под соответствие обновлённым стандартам лежит на разработчике. Это не такая сложная задача, если владеть регулярками.
А вот и сами требования (на английском, по историческим причинам).
Style
— Obey django's style guide.
— Configure your IDE to use flake8 for checking your python code. For running flake8 manualy, do
cd src && flake8
— Prefer English over your native language in comments and commit messages.
— Commit messages should contain the unique id of issue they are linked to (refs #100500 -- changed smth)
— Every model and a model method should have a docstring.
Testing
— We use TDD, so all of your code (except admin declarations) should be covered by tests.
— Unit tests are split into 4 categories:
— Unit (check at least 90% of the flow graph for every method)
— Functional: business-logic, cross-app relations, testing views
— API
— Integration: integration with other services or complex business-cases, like creating an order with certain payment type and delivery.
Code organisation
— DRY and KISS.
— Obey django best practices.
— Make models fat. No logic is allowed within the views or templates. Only models.
— Use PEP-484 type hints when possible.
— Prefer composition over inheritance.
— Prefer Manager methods over static model methods.
— Obey Attribute\method order for your models.
— Do not use signals for business logic. Signals are good only for notification purposes.
— No l10n is allowed in python code, use django translation.