Skip to content

Commit b6aa48d

Browse files
authored
Formatting for English translation
1 parent d2cdb5d commit b6aa48d

File tree

1 file changed

+106
-40
lines changed

1 file changed

+106
-40
lines changed

EN.md

Lines changed: 106 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -115,55 +115,99 @@ def register_model(self, app_label, model):
115115

116116

117117
### Sizes of methods, functions, and modules
118+
118119
The size limit for a method or function is 50 lines. Reaching the size limit indicates that the function (method) is doing too much — so decompose the actions inside the function (method).
120+
121+
119122
The module size limit is 300 lines. Reaching the size limit indicates that the module has received too much logic — so decompose the module into several ones.
123+
120124
The line length is 100 characters.
121-
Imports
125+
126+
127+
### Imports
128+
122129
The recommended import method is absolute.
130+
123131
Bad ❌:
132+
```python
124133
# spam.py
125134
from . import foo, bar
135+
```
136+
126137
Good ✅:
138+
```python
127139
# spam.py
128140
from some.absolute.path import foo, bar
129-
Why? Because absolute import explicitly defines the location (path) of the module that is being imported. With relative imports, you always need to remember the path and calculate in your mind the location of the modules foo.py, bar.py relative to spam.py
130-
Files __init__.py
131-
Only write imports in __init__.py files.
132-
Why? Because __init__.py is the last place a programmer will look when they read the code in the future.
133-
Docstrings
141+
```
142+
143+
**Why?** Because absolute import explicitly defines the location (path) of the module that is being imported. With relative imports, you always need to remember the path and calculate in your mind the location of the modules `foo.py`, `bar.py` relative to `spam.py`
144+
145+
146+
### Files `__init__.py`
147+
148+
Only write imports in `__init__.py` files.
149+
150+
**Why?** Because `__init__.py` is the last place a programmer will look when they read the code in the future.
151+
152+
153+
### Docstrings
134154
We recommend adding docstrings to functions, methods, and classes.
135-
Why? Because the programmer who sees your code for the first time will be able to quickly understand what is happening in it. Code is read much more than it is written.
136-
About Pull Requests
137-
Creating Pull Requests
138-
1 Pull Request = 1 issue
155+
**Why?** Because the programmer who sees your code for the first time will be able to quickly understand what is happening in it. Code is read much more than it is written.
156+
157+
158+
## About Pull Requests
159+
160+
### Creating Pull Requests
161+
**1 Pull Request = 1 issue**
162+
139163
One Pull Request must solve exactly one issue.
140-
Why? Because it is more difficult for a reviewer to keep the context of several tasks in their head and switch between them. When a PR contains several issues, then the PR often increases and requires more time and effort for the review from the reviewer.
141-
Refactoring and Pull Requests
164+
165+
**Why?** Because it is more difficult for a reviewer to keep the context of several tasks in their head and switch between them. When a PR contains several issues, then the PR often increases and requires more time and effort for the review from the reviewer.
166+
167+
### Refactoring and Pull Requests
142168
Refactoring is best done in a separate Pull Request.
143-
Why? When refactoring goes along with resolving a specific issue, the refactoring blurs the context of the issue and introduces changes that are not related to that PR.
144-
Pull Request Size
169+
170+
**Why?** When refactoring goes along with resolving a specific issue, the refactoring blurs the context of the issue and introduces changes that are not related to that PR.
171+
172+
173+
### Pull Request Size
145174
The resulting PR diff should not exceed +/- 600 changed lines.
146175
Bad ❌:
147-
176+
![bad](https://user-images.githubusercontent.com/8825727/113953748-6fc7ba80-9853-11eb-9673-827995e54f73.png)
177+
```
148178
Diff 444 + 333 = 777
179+
```
149180

150181
Good ✅:
182+
![good](https://user-images.githubusercontent.com/8825727/113953831-a30a4980-9853-11eb-854b-d4c4f6559f2c.png)
183+
```
151184
Diff 222 + 111 = 333
185+
```
152186

153-
Why? Because the more PR involves, the more uncontrollable it becomes, and the merge is made "with eyes closed and ears shut." Also, most reviewers will find it difficult to accept a large volume of changes at once.
154-
About tooling
155-
Testing (pytest)
156-
pytest - code testing framework
157-
Recommended config in pytest.ini:
187+
**Why?** Because the more PR involves, the more uncontrollable it becomes, and the merge is made "with eyes closed and ears shut." Also, most reviewers will find it difficult to accept a large volume of changes at once.
188+
189+
190+
## About tooling
191+
192+
### Testing (pytest)
193+
[pytest](https://pytest.org) - code testing framework
194+
195+
Recommended config in `pytest.ini`:
196+
```ini
158197
[pytest]
159198
DJANGO_SETTINGS_MODULE = settings.local
160199
python_files = tests.py test_*.py *_tests.py
200+
```
161201

162-
Package manager (poetry)
163-
poetry - dependency manager and package builder
164-
Code formatting (Black)
202+
### Package manager (poetry)
203+
[poetry](https://python-poetry.org) - dependency manager and package builder
204+
205+
206+
### Code formatting (Black)
165207
Black - PEP8 code auto-formatter
166-
Recommended config in pyproject.toml:
208+
209+
Recommended config in `pyproject.toml`:
210+
```
167211
[tool.black]
168212
line-length = 100
169213
target-version = ['py38']
@@ -182,10 +226,13 @@ exclude = '''
182226
|dist
183227
)
184228
'''
229+
```
185230

186-
Imports formatting (isort)
187-
isort - import block auto-formatter
188-
Recommended config in pyproject.toml:
231+
### Imports formatting (isort)
232+
[isort](https://pycqa.github.io/isort/) - import block auto-formatter
233+
234+
Recommended config in `pyproject.toml`:
235+
```
189236
[tool.isort]
190237
line_length = 100
191238
sections = ["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
@@ -194,30 +241,42 @@ known_django = "django"
194241
profile = "django"
195242
src_paths = "app"
196243
lines_after_imports = 2
244+
```
197245

198-
Linter (flake8)
199-
flake8 - PEP8 conformance validator
200-
Recommended config in .flake8:
246+
### Linter (flake8)
247+
[flake8](https://flake8.pycqa.org/en/latest/) - PEP8 conformance validator
248+
249+
Recommended config in `.flake8`:
250+
```ini
201251
[flake8]
202252
max-line-length = 100
203253
max-complexity = 5
204254
exclude = .venv,venv,**/migrations/*,snapshots
205255
per-file-ignores =
206256
tests/**: S101
207257
**/tests/**: S101
208-
Type checker (mypy)
209-
mypy - checker for static typing
210-
Recommended config mypy.ini:
258+
```
259+
260+
### Type checker (mypy)
261+
[mypy](http://mypy.readthedocs.io) - checker for static typing
262+
263+
Recommended config `mypy.ini`:
264+
```
211265
[mypy]
212266
ignore_missing_imports = True
213267
allow_untyped_globals = True
214268

215269
[mypy-*.migrations.*]
216270
ignore_errors = True
271+
```
217272

218-
Pre-commit hooks (pre-commit)
219-
pre-commit - framework for managing pre-commit hooks
220-
Recommended config .pre-commit-config.yaml:
273+
### Pre-commit hooks (pre-commit)
274+
275+
[pre-commit](https://pre-commit.com) - framework for managing `pre-commit` hooks
276+
277+
Recommended config `.pre-commit-config.yaml`:
278+
279+
```yaml
221280
default_language_version:
222281
python: python3.8
223282

@@ -241,9 +300,16 @@ repos:
241300
entry: flake8 server
242301
language: python
243302
types: [python]
244-
Other
245-
REST API Documentation
246-
The recommended documentation format is OpenAPI. The schema for OpenAPI should be generated “on the fly” to provide API clients with fresh changes.
247-
Why? Because it's one of the common formats for documenting REST APIs that come out of Swagger. This documentation format is supported by a large number of clients (Swagger, Postman, Insomnia Designer, and many others). Also, handwritten documentation tends to quickly become outdated, and documentation that is generated directly from the code allows you to avoid constantly thinking about updating the documentation.
303+
```
304+
305+
306+
## Other
307+
308+
### REST API Documentation
309+
The recommended documentation format is [OpenAPI](https://www.openapis.org). The schema for OpenAPI should be generated “on the fly” to provide API clients with fresh changes.
310+
311+
**Why?** Because it's one of the common formats for documenting REST APIs that come out of Swagger. This documentation format is supported by a large number of clients (Swagger, Postman, Insomnia Designer, and many others). Also, handwritten documentation tends to quickly become outdated, and documentation that is generated directly from the code allows you to avoid constantly thinking about updating the documentation.
248312

249313

314+
## Спонсор
315+
[<img src="https://evrone.com/logo/evrone-sponsored-logo.png" width=300>](https://evrone.com/?utm_source=github.com&utm_campaign=evrone-python-codestyle)

0 commit comments

Comments
 (0)