You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Use a code format tool (or tools) to make your life easier
39
39
40
40
We suggest that you use a code format tool, or a set of format tools, because
41
-
manually applying all of the PEP 8 format specifications is time consuming
42
-
for both maintainers and can be a road block for potential new contributors.
41
+
manually applying all of the PEP 8 format specifications is both time consuming
42
+
for maintainers and can be a road block for potential new contributors.
43
43
Code formatters will automagically reformat your code for you, adhering to
44
44
PEP 8 standards and applying consistent style decisions throughout.
45
45
@@ -70,29 +70,29 @@ discussed below, is an example of a commonly-used code linter.
70
70
71
71
### Code Formatters (and stylers)
72
72
73
-
Python focused code formatters often follow PEP 8 standards. However, they also
74
-
make stylistic decisions about code consistency. Code formatters will
75
-
reformat your code for you.
73
+
Code formatters will reformat your code for you. Python focused code formatters
74
+
often follow PEP 8 standards. However, they also make stylistic decisions about
75
+
code consistency.
76
76
77
77
Black is an example of a commonly-used code formatter. Black both applies PEP 8
78
78
standards while also making decisions about things like consistent use of double
79
79
quotes for strings, and spacing of items in lists.
80
80
81
81
You will learn more about Black below.
82
82
83
-
## Code format and style
83
+
## Code linting, formatting and styling tools
84
84
85
85
### Black
86
86
87
87
[Black](https://black.readthedocs.io/en/stable/) is a code
88
88
formatter. Black will automagically (and _unapologetically_)
89
89
fix spacing issues and ensure code format is consistent throughout your
90
-
package. Black also generally adhere to PEP 8 style guidelines with
90
+
package. Black also generally adheres to PEP 8 style guidelines with
91
91
some exceptions. A few examples of those exceptions are below:
92
92
93
93
- Black defaults to a line length of 88 (79 + 10%) rather than the 79 character `PEP 8` specification. However, line length is a setting can be manually overwritten in your Black configuration.
94
94
- Black will not adjust line length in your comments or docstrings.
95
-
- This tool will not review and fix import order (you need _isort_ or _Ruff_ to do that - see below).
95
+
- This tool will not review and fix import order (you need `isort` or `ruff` to do that - see below).
96
96
97
97
```{tip}
98
98
If you are interested in seeing how Black will format your code, you can
@@ -102,7 +102,7 @@ use the [Black playground](https://black.vercel.app/)
102
102
Using a code formatter like Black will leave you more time to work on
103
103
code function rather than worry about format.
104
104
105
-
### flake8 for linting code in Python packages
105
+
### Flake8
106
106
107
107
To adhere to Python `pep8` format standards, you might want to add
108
108
[flake8](https://flake8.pycqa.org/en/latest/) to your code format
@@ -122,9 +122,8 @@ called `stravalib`.
122
122
123
123
The line length standard for PEP 8 is 79 characters.
124
124
125
-
Notice that
126
-
flake8 returns a list of issues that it found in the model.py module in the
127
-
command line. The Python file itself is not modified. Using on this output,
125
+
Notice that flake8 returns a list of issues that it found in the model.py module
126
+
on the command line. The Python file itself is not modified. Using this output,
128
127
you can fix each issue line by line manually.
129
128
130
129
```bash
@@ -152,7 +151,7 @@ your package.
152
151
> - Related third party imports.
153
152
> - Local application/library specific imports.
154
153
155
-
While **flake8** will identify unused imports in your code, it won't
154
+
While `flake8` will identify unused imports in your code, it won't
156
155
fix or identify issues with the order of package imports.
157
156
158
157
`isort` will identify where imports in your code are out of
@@ -164,75 +163,57 @@ up your code.
164
163
165
164
Code imports before `isort` is run:
166
165
167
-
Below, the exc module is a part of starvalib which is a
168
-
third party package. `abc` and `logging` are core `Python` packages
169
-
distributed with `Python`. Also notice that there are extra
170
-
spaces in the imports listed below.
171
-
172
-
```python
173
-
from stravalib import exc
174
-
import abc
175
-
import logging
176
-
177
-
from collections.abc import Sequence
166
+
Below, the `pandas` is a third party package, `typing` is a core `Python`
167
+
package distributed with `Python`, and `examplePy.temperature` is a first-party
168
+
module which means it belongs to the same package as the file doing the import.
169
+
Also notice that there are no spaces in the imports listed below.
0 commit comments