acoomans / flask-autodoc Goto Github PK
View Code? Open in Web Editor NEWFlask autodoc automatically creates an online documentation for your flask application.
License: MIT License
Flask autodoc automatically creates an online documentation for your flask application.
License: MIT License
Using the following:
Python 2.7.6
Flask==0.10.1
Flask-Bootstrap==3.1.1.2
Flask-DebugToolbar==0.9.0
Flask-Login==0.2.11
Flask-Mail==0.9.0
Flask-Principal==0.4.0
Flask-Security==1.7.3
Flask-WTF==0.10.0
Jinja2==2.7.3
MarkupSafe==0.23
WTForms==2.0.1
Werkzeug==0.9.6
blinker==1.3
itsdangerous==0.24
mongoengine==0.8.7
passlib==1.6.2
pymongo==2.7.2
wsgiref==0.1.2
Getting this error when I add the @auto.doc to my endpoints:
Traceback (most recent call last):
File "./agencies.py", line 246, in
@auto.doc
File "/Users/william/code/agencyeditor/agencyweb/lib/python2.7/site-packages/flask/app.py", line 1013, in decorator
self.add_url_rule(rule, endpoint, f, *_options)
File "/Users/william/code/agencyeditor/agencyweb/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, *_kwargs)
File "/Users/william/code/agencyeditor/agencyweb/lib/python2.7/site-packages/flask/app.py", line 984, in add_url_rule
'existing endpoint function: %s' % endpoint)
AssertionError: View function mapping is overwriting an existing endpoint function: decorator
Any idea what the problem is? Thanks!
Hi,
Would you consider releasing the fix for using groups with a custom template to pypi?
Would also greatly appreciate the content of #10 but the bug fix is of more importance ๐
Barak.
I have a message with flask 1.10
/usr/local/lib/python3.4/dist-packages/flask/exthook.py:71: ExtDeprecationWarning: Importing flask.ext.autodoc is deprecated, use flask_autodoc instead.
I test replace in init.py
from flask.ext.autodoc.autodoc import Autodoc
by
from flask_autodoc.autodoc import Autodoc
And is ok. Can you modify your code ?
Thank you for module
Hello
In the 2nd example picture (/doc/private) you have a Form Data section under the Description for the route /post.
I checked the examples, but i can get it to work for me.
I have a template with this
<div class="desc">
Description : {{doc.docstring}}
</div>
that display the content of what i put between """ ... """ in my code, and in your example you do this :
"""Create a new post.
Form Data: title, content, authorid.
"""
'Create a new post ' i corectly going in the description and 'Form Data' i going to form data, however when i do the same thing, both go into the description.
How did you manage to add the FormData rule ?
Thanks
For example, I am using flask-basicauth and my arguments for all endpoints are:
Arguments: args kwargs auth password
I tried to work out and fix the following issue, but couldn't :(
python blog.py
Traceback (most recent call last):
File "blog.py", line 61, in
form_data=['title', 'content', 'authorid'])
TypeError: doc() got an unexpected keyword argument 'form_data'
I installed Flask-Autodoc (0.1.1) like all my packages using : pip install flask-autodoc and python3
When I tried to import Flask-Autodoc , I get this following error :
In [4]: from flask.ext.autodoc import Autodoc
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-b490edb37e00> in <module>()
----> 1 from flask.ext.autodoc import Autodoc
/Users/sacha/dev/wingo-server/venv/lib/python3.4/site-packages/flask/exthook.py in load_module(self, fullname)
79 # is the one from __import__ above which we don't care about
80 if self.is_important_traceback(realname, tb):
---> 81 reraise(exc_type, exc_value, tb.tb_next)
82 continue
83 module = sys.modules[fullname] = sys.modules[realname]
/Users/sacha/dev/wingo-server/venv/lib/python3.4/site-packages/flask/_compat.py in reraise(tp, value, tb)
30 def reraise(tp, value, tb=None):
31 if value.__traceback__ is not tb:
---> 32 raise value.with_traceback(tb)
33 raise value
34
/Users/sacha/dev/wingo-server/venv/lib/python3.4/site-packages/flask_autodoc/__init__.py in <module>()
1 __author__ = 'arnaud'
----> 2 from autodoc import Autodoc
ImportError: No module named 'autodoc'
I want to check that if this extensions support flask-restful, here is my test code:
from flask_autodoc.autodoc import Autodoc
from flask_restful import Resource,Api
class Post(Resource):
@auto.doc()
def get(self):
return 'post'
class Doc(Resource):
def get(self):
return auto.html()
api = Api(app)
api.add_resource(Post,'/post')
api.add_resource(Doc,'/doc')
however, the results shows that it does not support the flask-restful api:
thanks
zhangzheng
This is mainly an issue for local development by running the unittests locally.
Found with Python 2.7.6
To reproduce:
python -m unittest discover
test_autodoc.py
file, run python -m unittest discover
againThis results in the following error:
======================================================================
FAIL: testGet (tests.test_autodoc.TestAutodoc)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/alex/git/flask-autodoc/tests/test_autodoc.py", line 33, in testGet
self.assertIn(__file__, d['location']['filename'])
AssertionError: '/home/alex/git/flask-autodoc/tests/test_autodoc.pyc' not found in '/home/alex/git/flask-autodoc/tests/test_autodoc.py'
======================================================================
FAIL: testPost (tests.test_autodoc.TestAutodoc)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/alex/git/flask-autodoc/tests/test_autodoc.py", line 53, in testPost
self.assertIn(__file__, d['location']['filename'])
AssertionError: '/home/alex/git/flask-autodoc/tests/test_autodoc.pyc' not found in '/home/alex/git/flask-autodoc/tests/test_autodoc.py'
This is due to the tests that verify the location property being run from the compiled .pyc bytecode, therefore making the source of the actual file running the test the .pyc file, which appears as the __file__
attribute in this scenario.
I can see three possible solutions to this:
self.assertIn(d['location']['filename'], __file__)
. This isn't as clear when read, but basically because the expected value '/path/to/project/test/test_autodoc.py' is contained in the string '/path/to/project/test/test_autodoc.pyc', it should pass the assertion.clean
of the environment by removing excess artifacts such as .pyc files.I splitted my whole app into different files within a subfolder. each file consists of a single blueprint. is it possible to create an documentation of all registered blueprints?
I would like to be able to add a custom comment on each API function descriptions that appears in the report. Is it already possible? Would you develop that?
Thanks
I use flask-restful-api and I declare a class
this class has get, post, etc methods.
from flask.ext.restful import Resource
class A(Resource):
....def get():
........lots of code here
and I define the routes later, how would I make autodoc work in this case?
Thanks
Looks like gae limitation
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/alexey/projects/coolproject/main.py", line 35, in <module>
@auto.doc()
File "/Users/alexey/projects/coolproject/lib/flask_autodoc/autodoc.py", line 104, in decorator
caller_frame = inspect.stack()[1]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1055, in stack
return getouterframes(sys._getframe(1), context)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1033, in getouterframes
framelist.append((frame,) + getframeinfo(frame, context))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1008, in getframeinfo
lines, lnum = findsource(frame)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 532, in findsource
module = getmodule(object, file)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 504, in getmodule
main = sys.modules['__main__']
KeyError: '__main__'
Seems like there is a missing filter in autodoc_default.html , which results in error like:
raise TemplateAssertionError(msg, lineno, self.name, self.filename) jinja2.exceptions.TemplateAssertionError: no filter named 'nl2br'
Workaround for this is to add into Flask app:
@app.template_filter()
@evalcontextfilter
def nl2br(eval_ctx, value):
result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n') \
for p in _paragraph_re.split(escape(value)))
if eval_ctx.autoescape:
result = Markup(result)
return result
Python 3.6
pip freeze:
Flask==0.12.2
Jinja2==2.9.6
Flask-Autodoc==0.1.2
Hi,
with Python 3.5.3, Flask 0.12.2 and flask-autodoc 0.1.2.
It seems to me that doc won't generate for a route if the @auto.doc() decorator isn't immediately after the @app.route one.
In the case of multiple decorators, this behavior is a little bit disturbing.
This is not really a bug, but I think it should be mentioned in the documentation.
direct_decorate = auto.doc()
for func in app.view_functions.values():
direct_decorate(func)
The list of arguments is obtained using
func.func_code.co_varnames
in autodoc.py:101
This results in a list that contains more names than the function has arguments. I think you should use the inspect module to abstract away implementation issues, see http://stackoverflow.com/questions/10120974/where-is-the-default-parameter-in-python-function
The formatting works fine with Flask 0.10.1 but with 0.11.1 the embedded HTML tags are displayed instead of being processed as HTML.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.