Skip to content

Commit d18ddc9

Browse files
humitosagjohnson
authored andcommitted
Config files for auto linting (readthedocs#3264)
* Config files for auto linting autoflake, autopep8, docformatter, isort, yapf * readthedocs.projects.views.base with auto styling applied * readthedocs.core.models auto styling applied * readthedocs.builds.urls with auto styling applied * Do not make multi line summaries * Improve isort settings * Use 80 columns as maximum * pre-commit config file Use the `pre-commit` tool to run some linting commands before each commit: http://pre-commit.com/ * Update yapf config file to 0.20.0 * Add i18n functions to yapf config * Remove django as a special section for isort * Rename config to be automatically discovered * Add annoying as a third party lib for isort * Use the new config for all the files modified as a test I had to add a couple of "trailing commas" to keep the format as we want * Install additional dependencies for each of the hooks Remove the auto-lint.txt requirements file since it's not needed anymore * Use default config name for autopep8 * Include autoflake as pre-commit hook * Exclude D105 from flake8 D105: Missing docstring in magic method * Minor fixes from flake8 * autoflake with --in-place * Arguments for docformatter * Autofix D203 with yapf D203 / 1 blank line required before class docstring * Ignore local_settings.py on prospector
1 parent c0de92d commit d18ddc9

File tree

10 files changed

+351
-46
lines changed

10 files changed

+351
-46
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
ignore = E125,D100,D101,D102,D105,D200,D211,P101,FI15,FI16,FI12,FI11,FI17,FI50,FI53,FI54
3+
max-line-length = 80

.isort.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[settings]
2+
line_length=80
3+
indent=' '
4+
multi_line_output=4
5+
default_section=FIRSTPARTY
6+
known_readthedocs=readthedocs
7+
known_readthedocsinc=readthedocsinc
8+
known_third_party=celery,stripe,requests,pytz,builtins,django,annoying
9+
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
10+
add_imports=from __future__ import division, from __future__ import print_function, from __future__ import unicode_literals

.pep8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pep8]
2+
ignore = E701,E70,E702
3+
max-line-length = 80

.pre-commit-config.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
exclude: '^$'
2+
fail_fast: false
3+
repos:
4+
- repo: [email protected]:pre-commit/pre-commit-hooks
5+
sha: v1.1.1
6+
hooks:
7+
- id: autopep8-wrapper
8+
- id: check-added-large-files
9+
- id: debug-statements
10+
- id: double-quote-string-fixer
11+
- id: end-of-file-fixer
12+
- id: fix-encoding-pragma
13+
- id: flake8
14+
additional_dependencies: [
15+
'flake8-blind-except',
16+
'flake8-coding',
17+
'flake8-comprehensions',
18+
'flake8-debugger',
19+
'flake8-deprecated',
20+
'flake8-docstrings',
21+
'flake8-meiqia',
22+
'flake8-mutable',
23+
'flake8-pep3101',
24+
'flake8-print',
25+
'flake8-quotes',
26+
'flake8-string-format',
27+
'flake8-tidy-imports',
28+
'flake8-todo']
29+
- id: trailing-whitespace
30+
31+
- repo: [email protected]:pre-commit/mirrors-yapf.git
32+
sha: v0.20.0
33+
hooks:
34+
- id: yapf
35+
exclude: 'migrations|settings|scripts'
36+
additional_dependencies: ['futures']
37+
38+
- repo: [email protected]:FalconSocial/pre-commit-python-sorter.git
39+
sha: b57843b0b874df1d16eb0bef00b868792cb245c2
40+
hooks:
41+
- id: python-import-sorter
42+
args: ['--silent-overwrite']
43+
44+
- repo: [email protected]:humitos/mirrors-docformatter.git
45+
sha: v0.8
46+
hooks:
47+
- id: docformatter
48+
args: ['--in-place', '--wrap-summaries=80', '--wrap-descriptions=80', '--pre-summary-newline', '--no-blank']
49+
50+
- repo: [email protected]:humitos/mirrors-autoflake.git
51+
sha: v1.0
52+
hooks:
53+
- id: autoflake
54+
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']

.style.yapf

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# https://github.com/google/yapf
2+
# current version used in this repo
3+
# yapf==0.20.0
4+
5+
6+
[style]
7+
# Align closing bracket with visual indentation.
8+
ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT=True
9+
10+
# Allow lambdas to be formatted on more than one line.
11+
ALLOW_MULTILINE_LAMBDAS=False
12+
13+
# Allow dictionary keys to exist on multiple lines. For example:
14+
#
15+
# x = {
16+
# ('this is the first element of a tuple',
17+
# 'this is the second element of a tuple'):
18+
# value,
19+
# }
20+
ALLOW_MULTILINE_DICTIONARY_KEYS=False
21+
22+
# Insert a blank line before a 'def' or 'class' immediately nested
23+
# within another 'def' or 'class'. For example:
24+
#
25+
# class Foo:
26+
# # <------ this blank line
27+
# def method():
28+
# ...
29+
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=True
30+
31+
# Insert a blank line before a class-level docstring.
32+
BLANK_LINE_BEFORE_CLASS_DOCSTRING=True
33+
34+
# Do not split consecutive brackets. Only relevant when
35+
# dedent_closing_brackets is set. For example:
36+
#
37+
# call_func_that_takes_a_dict(
38+
# {
39+
# 'key1': 'value1',
40+
# 'key2': 'value2',
41+
# }
42+
# )
43+
#
44+
# would reformat to:
45+
#
46+
# call_func_that_takes_a_dict({
47+
# 'key1': 'value1',
48+
# 'key2': 'value2',
49+
# })
50+
COALESCE_BRACKETS=True
51+
52+
# The column limit.
53+
COLUMN_LIMIT=80
54+
55+
# Indent width used for line continuations.
56+
CONTINUATION_INDENT_WIDTH=4
57+
58+
# Put closing brackets on a separate line, dedented, if the bracketed
59+
# expression can't fit in a single line. Applies to all kinds of
60+
# brackets, including function definitions and calls. For example:
61+
#
62+
# config = {
63+
# 'key1': 'value1',
64+
# 'key2': 'value2',
65+
# } # <--- this bracket is dedented and on a separate line
66+
#
67+
# time_series = self.remote_client.query_entity_counters(
68+
# entity='dev3246.region1',
69+
# key='dns.query_latency_tcp',
70+
# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
71+
# start_ts=now()-timedelta(days=3),
72+
# end_ts=now(),
73+
# ) # <--- this bracket is dedented and on a separate line
74+
DEDENT_CLOSING_BRACKETS=False
75+
76+
# Place each dictionary entry onto its own line.
77+
EACH_DICT_ENTRY_ON_SEPARATE_LINE=False
78+
79+
# The regex for an i18n comment. The presence of this comment stops
80+
# reformatting of that line, because the comments are required to be
81+
# next to the string they translate.
82+
I18N_COMMENT=
83+
84+
# The i18n function call names. The presence of this function stops
85+
# reformattting on that line, because the string it has cannot be moved
86+
# away from the i18n comment.
87+
I18N_FUNCTION_CALL=["_", "ugettext", "gettext"]
88+
89+
# Indent the dictionary value if it cannot fit on the same line as the
90+
# dictionary key. For example:
91+
#
92+
# config = {
93+
# 'key1':
94+
# 'value1',
95+
# 'key2': value1 +
96+
# value2,
97+
# }
98+
INDENT_DICTIONARY_VALUE=False
99+
100+
# The number of columns to use for indentation.
101+
INDENT_WIDTH=4
102+
103+
# Join short lines into one line. E.g., single line 'if' statements.
104+
JOIN_MULTIPLE_LINES=True
105+
106+
# Use spaces around the power operator.
107+
SPACES_AROUND_POWER_OPERATOR=True
108+
109+
# Do not include spaces around selected binary operators. For example:
110+
# 1 + 2 * 3 - 4 / 5
111+
# will be formatted as follows when configured with a value "*,/":
112+
# 1 + 2*3 - 4/5
113+
NO_SPACES_AROUND_SELECTED_BINARY_OPERATORS=False
114+
115+
# Set to True to prefer spaces around the assignment operator for
116+
# default or keyword arguments.
117+
SPACES_AROUND_DEFAULT_OR_NAMED_ASSIGN=False
118+
119+
# The number of spaces required before a trailing comment.
120+
SPACES_BEFORE_COMMENT=2
121+
122+
# Insert a space between the ending comma and closing bracket of a list,
123+
# etc.
124+
SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET=False
125+
126+
# Split before arguments if the argument list is terminated by a
127+
# comma.
128+
SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED=True
129+
130+
# Set to True to prefer splitting before '&', '|' or '^' rather than
131+
# after.
132+
SPLIT_BEFORE_BITWISE_OPERATOR=False
133+
134+
# Split before a dictionary or set generator (comp_for). For example,
135+
# note the split before the for:
136+
#
137+
# foo = {
138+
# variable: 'Hello world, have a nice day!'
139+
# for variable in bar if variable != 42
140+
# }
141+
SPLIT_BEFORE_DICT_SET_GENERATOR=True
142+
143+
# Split after the opening paren which surrounds an expression if it doesn't fit on a single line.
144+
SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN=True
145+
146+
# If an argument / parameter list is going to be split, then split
147+
# before the first argument.
148+
SPLIT_BEFORE_FIRST_ARGUMENT=True
149+
150+
# Set to True to prefer splitting before 'and' or 'or' rather than
151+
# after.
152+
SPLIT_BEFORE_LOGICAL_OPERATOR=False
153+
154+
# Split named assignments onto individual lines.
155+
SPLIT_BEFORE_NAMED_ASSIGNS=False
156+
157+
# For list comprehensions and generator expressions with multiple clauses
158+
SPLIT_COMPLEX_COMPREHENSION=False
159+
160+
# The penalty for splitting right after the opening bracket.
161+
SPLIT_PENALTY_AFTER_OPENING_BRACKET=2000
162+
163+
# The penalty for splitting the line after a unary operator.
164+
SPLIT_PENALTY_AFTER_UNARY_OPERATOR=10000
165+
166+
# The penalty for splitting right before an if expression.
167+
SPLIT_PENALTY_BEFORE_IF_EXPR=0
168+
169+
# The penalty of splitting the line around the '&', '|', and '^'
170+
# operators.
171+
SPLIT_PENALTY_BITWISE_OPERATOR=300
172+
173+
# The penalty for splitting a list comprehension or generator expression.
174+
SPLIT_PENALTY_COMPREHENSION=80
175+
176+
# The penalty for characters over the column limit.
177+
SPLIT_PENALTY_EXCESS_CHARACTER=2600
178+
179+
# The penalty incurred by adding a line split to the unwrapped
180+
# line. The more line splits added the higher the penalty.
181+
SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT=30
182+
183+
# The penalty of splitting a list of "import as" names. For example:
184+
#
185+
# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1,
186+
# long_argument_2,
187+
# long_argument_3)
188+
#
189+
# would reformat to something like:
190+
#
191+
# from a_very_long_or_indented_module_name_yada_yad import (
192+
# long_argument_1, long_argument_2, long_argument_3)
193+
SPLIT_PENALTY_IMPORT_NAMES=0
194+
195+
# The penalty of splitting the line around the 'and' and 'or'
196+
# operators.
197+
SPLIT_PENALTY_LOGICAL_OPERATOR=300
198+
199+
# Use the Tab character for indentation.
200+
USE_TABS=False
201+
202+
# Allow splits before the dictionary value.
203+
ALLOW_SPLIT_BEFORE_DICT_VALUE=False

docs/contribute.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,29 @@ label. Those tickets are meant to be standalone and can be worked on ad-hoc.
3434
When contributing code, then please follow the standard Contribution
3535
Guidelines set forth at `contribution-guide.org`_.
3636

37+
We have a strict code style that it's easy to follow since you just
38+
have to run a couple of commands and they will do everything for
39+
you. These commands are a mix between `autoflake`_, `autopep8`_,
40+
`docformatter`_, `isort`_, `unify`_ and `yapf`_::
41+
42+
$ autoflake --remove-all-unused-imports --remove-unused-variables --keep-useless-pass
43+
$ autopep8
44+
$ docformatter --wrap-summaries=80 --wrap-descriptions=80 --pre-summary-newline --no-blank
45+
$ isort
46+
$ unify --quote="'"
47+
$ yapf --exclude=*migrations* --exclude=*settings* --exclude=*scripts* --parallel
48+
3749
.. _Feature Overview: https://github.com/rtfd/readthedocs.org/issues?direction=desc&labels=Feature+Overview&page=1&sort=updated&state=open
3850
.. _Good First Issue: https://github.com/rtfd/readthedocs.org/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22
3951
.. _Sprintable: https://github.com/rtfd/readthedocs.org/issues?q=is%3Aopen+is%3Aissue+label%3ASprintable
4052
.. _contribution-guide.org: http://www.contribution-guide.org/#submitting-bugs
4153

54+
.. _autoflake: https://github.com/myint/autoflake
55+
.. _autopep8: https://github.com/hhatto/autopep8
56+
.. _docformatter: https://github.com/myint/docformatter
57+
.. _unify: https://github.com/myint/unify
58+
.. _yapf: https://github.com/google/yapf
59+
4260
Triaging tickets
4361
----------------
4462

prospector.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ignore-paths:
1212

1313
ignore-patterns:
1414
- /migrations/
15+
- local_settings.py
1516

1617
pep8:
1718
full: true

readthedocs/builds/urls.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
# -*- coding: utf-8 -*-
12
"""URL configuration for builds app."""
3+
from __future__ import (
4+
absolute_import, division, print_function, unicode_literals)
25

3-
from __future__ import absolute_import
46
from django.conf.urls import url
57

68
from .views import builds_redirect_detail, builds_redirect_list
79

8-
910
urlpatterns = [
10-
url(r'^(?P<project_slug>[-\w]+)/(?P<pk>\d+)/$',
11+
url(
12+
r'^(?P<project_slug>[-\w]+)/(?P<pk>\d+)/$',
1113
builds_redirect_detail,
12-
name='old_builds_detail'),
13-
14-
url(r'^(?P<project_slug>[-\w]+)/$',
14+
name='old_builds_detail',
15+
),
16+
url(
17+
r'^(?P<project_slug>[-\w]+)/$',
1518
builds_redirect_list,
16-
name='old_builds_project_list'),
19+
name='old_builds_project_list',
20+
),
1721
]

0 commit comments

Comments
 (0)