Autodoc extension to pretty print canned SA queries
author: Lele Gaifax contact: firstname.lastname@example.org license: GNU General Public License version 3 or later
To use it, first of all you must register the extension within the Sphinx environment, adding the full name of the package to the extensions list in the file conf.py, for example:
# Add any Sphinx extension module names here, as strings. extensions = ['metapensiero.sphinx.autodoc_sa']
Without further settings it uses the default SQLAlchemy stringification strategy, but you can explicitly choose the right dialect by setting autodoc_sa_dialect to a string containing its fully qualified name, for example:
autodoc_sa_dialect = 'sqlalchemy.dialects.postgresql.dialect'
Otherwise, you can set it using the -D option of the sphinx-build command, e.g. adding -D autodoc_sa_dialect=my.own.dialect to the SPHINXOPTS of the Makefile created by sphinx-quickstart.
At this point, any documented SQLAlchemy core statement or ORM query, appearing either at the module level or as a class attribute, will be compiled into SQL, beautified using sqlparse.format() and added to the documentation wrapped within a code-block:: sql directive.
If you chose a specific SQLAlchemy dialect, by any chance you may want to select the right Pygments lexer to adjust the highlighting rules, instead of the default sql:
autodoc_sa_pygments_lang = 'postgresql'
If you are using PostgreSQL, you may prefer using the pg_query SQL prettifier over the default based on sqlparse:
autodoc_sa_prettifier = 'pg_query'
- New option autodoc_sa_prettifier_options to pass arbitrary keyword options to the prettifier function
- Replace the dynamic argument placeholders injected by SA with their literal values, leaving the developer’s explicit bindparams alone
- Handle also the pg_query SQL prettifier
- New options, autodoc_sa_prettifier and autodoc_pygments_lang
- Minor tweak, no externally visible changes
- First release on PyPI
- Polished, tested and extended to support class’ attributes as well
- Extracted from metapensiero.sphinx.patchdb
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, Size & Hash SHA256 Hash Help||File Type||Python Version||Upload Date|
(9.0 kB) Copy SHA256 Hash SHA256
|Source||None||Aug 10, 2017|