|
1 | 1 | STYLE GUIDE
|
2 | 2 | ==============
|
3 | 3 |
|
4 |
| -Use your common sense and have some decency. Also try to stick to the following where reasonable. |
| 4 | +As a rough style guide, please lint your code with pep8:: |
5 | 5 |
|
| 6 | + pip install pep8 |
| 7 | + pep8 --ignore E501,E226,E241 sc2reader |
6 | 8 |
|
7 |
| -Absolute Imports |
8 |
| ----------------------- |
9 | 9 |
|
10 |
| -Always use absolute imports:: |
| 10 | +All files should start with the following:: |
11 | 11 |
|
12 |
| - from __future__ import absolute_import |
| 12 | + # -*- coding: utf-8 -*- |
| 13 | + # |
| 14 | + # Optional Documentation on the module |
| 15 | + # |
| 16 | + from __future__ import absolute_import, print_function, unicode_literals, division |
13 | 17 |
|
14 |
| -That means imports should always start with sc2reader... instead of being relative to the current module. |
| 18 | +All imports should be absolute. |
15 | 19 |
|
16 |
| - from sc2reader.utils import ReplayBuffer |
17 | 20 |
|
| 21 | +All string formatting sound be done in the following style:: |
18 | 22 |
|
19 |
| -Explicit Imports |
20 |
| ---------------------- |
| 23 | + "my {0} formatted {1} string {2}".format("super", "python", "example") |
| 24 | + "the {x} style of {y} is also {z}".format(x="dict", y="arguments", z="acceptable") |
21 | 25 |
|
22 |
| -Prefer explicit imports to globbed imports |
23 |
| - |
24 |
| - from sc2reader.events import ChatEvent |
25 |
| - |
26 |
| -is better than |
27 |
| - |
28 |
| - from sc2reader.events import * |
29 |
| - |
30 |
| - |
31 |
| -Formatting Strings |
32 |
| ------------------------ |
33 |
| - |
34 |
| -Use string.format(args) instead string % (args). |
35 |
| - |
36 |
| -To support python 2.6, use numerical indexes even though it is a pain in the ass:: |
37 |
| - |
38 |
| - "{0} minerals, {1} gas, {2} terrazine, and {3} custom".format(self.minerals, self.vespene, self.terrazine, self.custom) |
| 26 | +The format argument index numbers are important for 2.6 support. ``%`` formatting is not allowed for 3.x support |
39 | 27 |
|
0 commit comments