Skip to content

Commit 07b0ed8

Browse files
author
Arnaud Coomans
committed
pep8
1 parent 5a2a88b commit 07b0ed8

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

examples/factory/blog/frontend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class User(object):
15+
1516
def __init__(self, username):
1617
self.username = username
1718
users.append(self)
@@ -22,6 +23,7 @@ def __repr__(self):
2223

2324

2425
class Post(object):
26+
2527
def __init__(self, title, content, author):
2628
self.title = title
2729
self.content = content

examples/simple/blog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
class User(object):
16+
1617
def __init__(self, username):
1718
self.username = username
1819
users.append(self)
@@ -23,6 +24,7 @@ def __repr__(self):
2324

2425

2526
class Post(object):
27+
2628
def __init__(self, title, content, author):
2729
self.title = title
2830
self.content = content

flask_autodoc/autodoc.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ def add_custom_nl2br_filters(self, app):
5151
@app.template_filter()
5252
@evalcontextfilter
5353
def nl2br(eval_ctx, value):
54-
result = '\n\n'.join('%s' % p.replace('\n', '<br>\n') for p in _paragraph_re.split(value))
54+
result = '\n\n'.join('%s' % p.replace('\n', '<br>\n')
55+
for p in _paragraph_re.split(value))
5556
return result
5657

5758
def doc(self, group=None, aa=None, groups=None):
58-
"""Decorator to add flask route to autodoc for automatic documentation\
59+
"""Add flask route to autodoc for automatic documentation
5960
60-
Any route decorated with this method will be added to the list of routes to be documented by the generate() or
61-
html() methods.
61+
Any route decorated with this method will be added to the list of
62+
routes to be documented by the generate() or html() methods.
6263
6364
By default, the route is added to the 'all' group.
64-
By specifying group or groups argument, the route can be added to one or multiple other groups as well, besides
65-
the 'all' group.
65+
By specifying group or groups argument, the route can be added to one
66+
or multiple other groups as well, besides the 'all' group.
6667
"""
6768
def decorator(f):
6869
if groups:
@@ -78,7 +79,8 @@ def decorator(f):
7879
return decorator
7980

8081
def generate(self, group='all', groups=[], sort=None):
81-
"""Returns a list of dict describing the routes specified by the doc() method
82+
"""Return a list of dict describing the routes specified by the
83+
doc() method
8284
8385
Each dict contains:
8486
- methods: the set of allowed methods (ie ['GET', 'POST'])
@@ -88,7 +90,8 @@ def generate(self, group='all', groups=[], sort=None):
8890
- args: function arguments
8991
- defaults: defaults values for the arguments
9092
91-
By specifying the group or groups arguments, only routes belonging to those groups will be returned.
93+
By specifying the group or groups arguments, only routes belonging to
94+
those groups will be returned.
9295
9396
Routes are sorted alphabetically based on the rule.
9497
"""
@@ -101,8 +104,8 @@ def generate(self, group='all', groups=[], sort=None):
101104
func = current_app.view_functions[rule.endpoint]
102105
arguments = rule.arguments if rule.arguments else ['None']
103106

104-
if (groups and [True for g in groups if func in self.groups[g]]) or \
105-
(not groups and func in self.groups[group]):
107+
if (groups and [True for g in groups if func in self.groups[g]]) \
108+
or (not groups and func in self.groups[group]):
106109
links.append(
107110
dict(
108111
methods=rule.methods,
@@ -119,16 +122,20 @@ def generate(self, group='all', groups=[], sort=None):
119122
return sorted(links, key=itemgetter('rule'))
120123

121124
def html(self, template=None, group='all', groups=None, **context):
122-
"""Returns an html string of the routes specified by the doc() method
125+
"""Return an html string of the routes specified by the doc() method
123126
124-
A template can be specified. A list of routes is available under the 'autodoc' value (refer to the documentation
125-
for the generate() for a description of available values). If no template is specified, a default template is
126-
used.
127+
A template can be specified. A list of routes is available under the
128+
'autodoc' value (refer to the documentation for the generate() for a
129+
description of available values). If no template is specified, a
130+
default template is used.
127131
128-
By specifying the group or groups arguments, only routes belonging to those groups will be returned.
132+
By specifying the group or groups arguments, only routes belonging to
133+
those groups will be returned.
129134
"""
130135
if template:
131-
return render_template(template, autodoc=self.generate(group), **context)
136+
return render_template(template,
137+
autodoc=self.generate(group),
138+
**context)
132139
else:
133140
filename = os.path.join(
134141
os.path.dirname(__file__),
@@ -138,4 +145,7 @@ def html(self, template=None, group='all', groups=None, **context):
138145
with open(filename) as file:
139146
content = file.read()
140147
with current_app.app_context():
141-
return render_template_string(content, autodoc=self.generate(group=group, groups=groups), **context)
148+
return render_template_string(
149+
content,
150+
autodoc=self.generate(group=group, groups=groups),
151+
**context)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Flask-Autodoc
33
-------------
44
5-
Flask autodoc automatically creates an online documentation for your flask application.
5+
Flask autodoc automatically creates an online documentation for your flask app.
66
"""
77
from setuptools import setup
88

@@ -21,7 +21,7 @@ def readme():
2121
author_email='arnaud.coomans@gmail.com',
2222
description='Documentation generator for flask',
2323
long_description=readme(),
24-
#py_modules=['flask_autodoc'],
24+
# py_modules=['flask_autodoc'],
2525
# if you would be using a package instead use packages instead
2626
# of py_modules:
2727
packages=['flask_autodoc'],

tests/test_autodoc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def ab(param1, param2):
6868
self.assertIsNone(d['docstring'])
6969

7070
if '/p1/p2' in d['rule']:
71-
self.assertDictEqual(d['defaults'], {'param2': 'b', 'param1': 'a'})
71+
self.assertDictEqual(d['defaults'],
72+
{'param2': 'b', 'param1': 'a'})
7273
elif '/p1/<string:param1>/p2/<int:param2>' in d['rule']:
7374
self.assertFalse(d['defaults'])
7475

@@ -167,7 +168,13 @@ def ab(param1, param2):
167168
doc = self.autodoc.html(title='hello')
168169
self.assertIn('/p1/p2', doc)
169170
if sys.version < '3':
170-
self.assertRegexpMatches(doc, '\/p1\/.*string:param1.*\/p2\/.*int:param2.*')
171+
self.assertRegexpMatches(
172+
doc,
173+
'\/p1\/.*string:param1.*\/p2\/.*int:param2.*'
174+
)
171175
else:
172-
self.assertRegex(doc, '\/p1\/.*string:param1.*\/p2\/.*int:param2.*')
176+
self.assertRegex(
177+
doc,
178+
'\/p1\/.*string:param1.*\/p2\/.*int:param2.*'
179+
)
173180
self.assertIn('Returns arguments', doc)

0 commit comments

Comments
 (0)