Skip to content

Commit 5cb5398

Browse files
authored
Use black for formatting the code (#887)
* Add black, isort and pre-commit hooks * Add black configuration * Run black as part of flake8 testenv in tox * Add editorconfig to ensure indent style in tox.ini/setup.cfg * Add pre-commit hooks to check flake8, black, isort and common errors * Update isort configuration to be black-compatible * Update contributing documentation * Add myself to AUTHORS * Skip migrations in black/isort/pre-commit * Run black over the source tree This is the result of running `black .` over the repository. By-hand improvements of the blackened code will be in follow up commits, to make it easier to reapply this commit to future updates, if necessary - IE to remove this commit and re-run black over a fresh tree, rather than trying to merge new changes in to this commit. * Hand tweak some of black's autoformatting Some minor hand tweaks: oauth2_provider/contrib/rest_framework/authentication.py oauth2_provider/oauth2_validators.py Construct OrderedDict in a clearer, still black compliant way (one line per dict entry) tests/test_token_revocation.py Remove empty method docstrings * Apply isort over codebase Co-authored-by: Tom Evans <[email protected]>
1 parent c2f379d commit 5cb5398

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+957
-749
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[{Makefile,tox.ini,setup.cfg}]
12+
indent_style = tab
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/ambv/black
3+
rev: 20.8b1
4+
hooks:
5+
- id: black
6+
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v3.2.0
9+
hooks:
10+
- id: check-ast
11+
- id: trailing-whitespace
12+
- id: check-merge-conflict
13+
- id: check-json
14+
- id: check-xml
15+
- id: check-yaml
16+
- id: mixed-line-ending
17+
args: ['--fix=lf']
18+
- repo: https://github.com/PyCQA/isort
19+
rev: 5.6.3
20+
hooks:
21+
- id: isort
22+
exclude: ^(oauth2_provider/migrations/|tests/migrations/)
23+
- repo: https://gitlab.com/pycqa/flake8
24+
rev: 3.8.4
25+
hooks:
26+
- id: flake8
27+
exclude: ^(oauth2_provider/migrations/|tests/migrations/)

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Stéphane Raimbault
3232
Jun Zhou
3333
David Smith
3434
Łukasz Skarżyński
35+
Tom Evans

docs/conf.py

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,33 @@
3232
# -- General configuration -----------------------------------------------------
3333

3434
# If your documentation needs a minimal Sphinx version, state it here.
35-
#needs_sphinx = '1.0'
35+
# needs_sphinx = '1.0'
3636

3737
# Add any Sphinx extension module names here, as strings. They can be extensions
3838
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
39-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'rfc', 'm2r',]
39+
extensions = [
40+
"sphinx.ext.autodoc",
41+
"sphinx.ext.todo",
42+
"sphinx.ext.coverage",
43+
"rfc",
44+
"m2r",
45+
]
4046

4147
# Add any paths that contain templates here, relative to this directory.
42-
templates_path = ['_templates']
48+
templates_path = ["_templates"]
4349

4450
# The suffix of source filenames.
45-
source_suffix = '.rst'
51+
source_suffix = ".rst"
4652

4753
# The encoding of source files.
48-
#source_encoding = 'utf-8-sig'
54+
# source_encoding = 'utf-8-sig'
4955

5056
# The master toctree document.
51-
master_doc = 'index'
57+
master_doc = "index"
5258

5359
# General information about the project.
54-
project = u'Django OAuth Toolkit'
55-
copyright = u'2013, Evonove'
60+
project = "Django OAuth Toolkit"
61+
copyright = "2013, Evonove"
5662

5763

5864
# The version info for the project you're documenting, acts as replacement for
@@ -66,181 +72,176 @@
6672

6773
# The language for content autogenerated by Sphinx. Refer to documentation
6874
# for a list of supported languages.
69-
#language = None
75+
# language = None
7076

7177
# There are two options for replacing |today|: either, you set today to some
7278
# non-false value, then it is used:
73-
#today = ''
79+
# today = ''
7480
# Else, today_fmt is used as the format for a strftime call.
75-
#today_fmt = '%B %d, %Y'
81+
# today_fmt = '%B %d, %Y'
7682

7783
# List of patterns, relative to source directory, that match files and
7884
# directories to ignore when looking for source files.
79-
exclude_patterns = ['_build']
85+
exclude_patterns = ["_build"]
8086

8187
# The reST default role (used for this markup: `text`) to use for all documents.
82-
#default_role = None
88+
# default_role = None
8389

8490
# If true, '()' will be appended to :func: etc. cross-reference text.
85-
#add_function_parentheses = True
91+
# add_function_parentheses = True
8692

8793
# If true, the current module name will be prepended to all description
8894
# unit titles (such as .. function::).
89-
#add_module_names = True
95+
# add_module_names = True
9096

9197
# If true, sectionauthor and moduleauthor directives will be shown in the
9298
# output. They are ignored by default.
93-
#show_authors = False
99+
# show_authors = False
94100

95101
# The name of the Pygments (syntax highlighting) style to use.
96-
pygments_style = 'sphinx'
102+
pygments_style = "sphinx"
97103

98104
# A list of ignored prefixes for module index sorting.
99-
#modindex_common_prefix = []
105+
# modindex_common_prefix = []
100106

101107
# If true, keep warnings as "system message" paragraphs in the built documents.
102-
#keep_warnings = False
108+
# keep_warnings = False
103109

104110

105111
# http://www.sphinx-doc.org/en/1.5.1/ext/intersphinx.html
106-
extensions.append('sphinx.ext.intersphinx')
107-
intersphinx_mapping = {'python3': ('https://docs.python.org/3.6', None),
108-
'django': ('http://django.readthedocs.org/en/latest/', None)}
109-
112+
extensions.append("sphinx.ext.intersphinx")
113+
intersphinx_mapping = {
114+
"python3": ("https://docs.python.org/3.6", None),
115+
"django": ("http://django.readthedocs.org/en/latest/", None),
116+
}
110117

111118

112119
# -- Options for HTML output ---------------------------------------------------
113120

114121
# The theme to use for HTML and HTML Help pages. See the documentation for
115122
# a list of builtin themes.
116-
#html_theme = 'classic'
123+
# html_theme = 'classic'
117124

118125
# Theme options are theme-specific and customize the look and feel of a theme
119126
# further. For a list of options available for each theme, see the
120127
# documentation.
121-
#html_theme_options = {}
128+
# html_theme_options = {}
122129

123130
# Add any paths that contain custom themes here, relative to this directory.
124-
#html_theme_path = []
131+
# html_theme_path = []
125132

126133
# The name for this set of Sphinx documents. If None, it defaults to
127134
# "<project> v<release> documentation".
128-
#html_title = None
135+
# html_title = None
129136

130137
# A shorter title for the navigation bar. Default is the same as html_title.
131-
#html_short_title = None
138+
# html_short_title = None
132139

133140
# The name of an image file (relative to this directory) to place at the top
134141
# of the sidebar.
135-
#html_logo = None
142+
# html_logo = None
136143

137144
# The name of an image file (within the static path) to use as favicon of the
138145
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
139146
# pixels large.
140-
#html_favicon = None
147+
# html_favicon = None
141148

142149
# Add any paths that contain custom static files (such as style sheets) here,
143150
# relative to this directory. They are copied after the builtin static files,
144151
# so a file named "default.css" will overwrite the builtin "default.css".
145-
#html_static_path = ['_static']
152+
# html_static_path = ['_static']
146153

147154
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
148155
# using the given strftime format.
149-
#html_last_updated_fmt = '%b %d, %Y'
156+
# html_last_updated_fmt = '%b %d, %Y'
150157

151158
# If true, SmartyPants will be used to convert quotes and dashes to
152159
# typographically correct entities.
153-
#html_use_smartypants = True
160+
# html_use_smartypants = True
154161

155162
# Custom sidebar templates, maps document names to template names.
156-
#html_sidebars = {}
163+
# html_sidebars = {}
157164

158165
# Additional templates that should be rendered to pages, maps page names to
159166
# template names.
160-
#html_additional_pages = {}
167+
# html_additional_pages = {}
161168

162169
# If false, no module index is generated.
163-
#html_domain_indices = True
170+
# html_domain_indices = True
164171

165172
# If false, no index is generated.
166-
#html_use_index = True
173+
# html_use_index = True
167174

168175
# If true, the index is split into individual pages for each letter.
169-
#html_split_index = False
176+
# html_split_index = False
170177

171178
# If true, links to the reST sources are added to the pages.
172-
#html_show_sourcelink = True
179+
# html_show_sourcelink = True
173180

174181
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
175-
#html_show_sphinx = True
182+
# html_show_sphinx = True
176183

177184
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
178-
#html_show_copyright = True
185+
# html_show_copyright = True
179186

180187
# If true, an OpenSearch description file will be output, and all pages will
181188
# contain a <link> tag referring to it. The value of this option must be the
182189
# base URL from which the finished HTML is served.
183-
#html_use_opensearch = ''
190+
# html_use_opensearch = ''
184191

185192
# This is the file name suffix for HTML files (e.g. ".xhtml").
186-
#html_file_suffix = None
193+
# html_file_suffix = None
187194

188195
# Output file base name for HTML help builder.
189-
htmlhelp_basename = 'DjangoOAuthToolkitdoc'
196+
htmlhelp_basename = "DjangoOAuthToolkitdoc"
190197

191198

192199
# -- Options for LaTeX output --------------------------------------------------
193200

194201
latex_elements = {
195-
# The paper size ('letterpaper' or 'a4paper').
196-
#'papersize': 'letterpaper',
197-
198-
# The font size ('10pt', '11pt' or '12pt').
199-
#'pointsize': '10pt',
200-
201-
# Additional stuff for the LaTeX preamble.
202-
#'preamble': '',
202+
# The paper size ('letterpaper' or 'a4paper').
203+
#'papersize': 'letterpaper',
204+
# The font size ('10pt', '11pt' or '12pt').
205+
#'pointsize': '10pt',
206+
# Additional stuff for the LaTeX preamble.
207+
#'preamble': '',
203208
}
204209

205210
# Grouping the document tree into LaTeX files. List of tuples
206211
# (source start file, target name, title, author, documentclass [howto/manual]).
207212
latex_documents = [
208-
('index', 'DjangoOAuthToolkit.tex', u'Django OAuth Toolkit Documentation',
209-
u'Evonove', 'manual'),
213+
("index", "DjangoOAuthToolkit.tex", "Django OAuth Toolkit Documentation", "Evonove", "manual"),
210214
]
211215

212216
# The name of an image file (relative to this directory) to place at the top of
213217
# the title page.
214-
#latex_logo = None
218+
# latex_logo = None
215219

216220
# For "manual" documents, if this is true, then toplevel headings are parts,
217221
# not chapters.
218-
#latex_use_parts = False
222+
# latex_use_parts = False
219223

220224
# If true, show page references after internal links.
221-
#latex_show_pagerefs = False
225+
# latex_show_pagerefs = False
222226

223227
# If true, show URL addresses after external links.
224-
#latex_show_urls = False
228+
# latex_show_urls = False
225229

226230
# Documents to append as an appendix to all manuals.
227-
#latex_appendices = []
231+
# latex_appendices = []
228232

229233
# If false, no module index is generated.
230-
#latex_domain_indices = True
234+
# latex_domain_indices = True
231235

232236

233237
# -- Options for manual page output --------------------------------------------
234238

235239
# One entry per manual page. List of tuples
236240
# (source start file, name, description, authors, manual section).
237-
man_pages = [
238-
('index', 'djangooauthtoolkit', u'Django OAuth Toolkit Documentation',
239-
[u'Evonove'], 1)
240-
]
241+
man_pages = [("index", "djangooauthtoolkit", "Django OAuth Toolkit Documentation", ["Evonove"], 1)]
241242

242243
# If true, show URL addresses after external links.
243-
#man_show_urls = False
244+
# man_show_urls = False
244245

245246

246247
# -- Options for Texinfo output ------------------------------------------------
@@ -249,19 +250,25 @@
249250
# (source start file, target name, title, author,
250251
# dir menu entry, description, category)
251252
texinfo_documents = [
252-
('index', 'DjangoOAuthToolkit', u'Django OAuth Toolkit Documentation',
253-
u'Evonove', 'DjangoOAuthToolkit', 'One line description of project.',
254-
'Miscellaneous'),
253+
(
254+
"index",
255+
"DjangoOAuthToolkit",
256+
"Django OAuth Toolkit Documentation",
257+
"Evonove",
258+
"DjangoOAuthToolkit",
259+
"One line description of project.",
260+
"Miscellaneous",
261+
),
255262
]
256263

257264
# Documents to append as an appendix to all manuals.
258-
#texinfo_appendices = []
265+
# texinfo_appendices = []
259266

260267
# If false, no module index is generated.
261-
#texinfo_domain_indices = True
268+
# texinfo_domain_indices = True
262269

263270
# How to display URL addresses: 'footnote', 'no', or 'inline'.
264-
#texinfo_show_urls = 'footnote'
271+
# texinfo_show_urls = 'footnote'
265272

266273
# If true, do not generate a @detailmenu in the "Top" node's menu.
267-
#texinfo_no_detailmenu = False
274+
# texinfo_no_detailmenu = False

docs/contributing.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,34 @@ You can find the list of bugs, enhancements and feature requests on the
2424
`issue tracker <https://github.com/jazzband/django-oauth-toolkit/issues>`_. If you want to fix an issue, pick up one and
2525
add a comment stating you're working on it.
2626

27+
Code Style
28+
==========
29+
30+
The project uses `flake8 <https://flake8.pycqa.org/en/latest/>`_ for linting,
31+
`black <https://black.readthedocs.io/en/stable/>`_ for formatting the code,
32+
`isort <https://pycqa.github.io/isort/>`_ for formatting and sorting imports,
33+
and `pre-commit <https://pre-commit.com/>`_ for checking/fixing commits for
34+
correctness before they are made.
35+
36+
You will need to install ``pre-commit`` yourself, and then ``pre-commit`` will
37+
take care of installing ``flake8``, ``black`` and ``isort``.
38+
39+
After cloning your repository, go into it and run::
40+
41+
pre-commit install
42+
43+
to install the hooks. On the next commit that you make, ``pre-commit`` will
44+
download and install the necessary hooks (a one off task). If anything in the
45+
commit would fail the hooks, the commit will be abandoned. For ``black`` and
46+
``isort``, any necessary changes will be made automatically, but not staged.
47+
Review the changes, and then re-stage and commit again.
48+
49+
Using ``pre-commit`` ensures that code that would fail in QA does not make it
50+
into a commit in the first place, and will save you time in the long run. You
51+
can also (largely) stop worrying about code style, although you should always
52+
check how the code looks after ``black`` has formatted it, and think if there
53+
is a better way to structure the code so that it is more readable.
54+
2755
Pull requests
2856
=============
2957

0 commit comments

Comments
 (0)