Autodoc extension to pretty print canned SA queries
Project description
- author:
Lele Gaifax
- contact:
- license:
GNU General Public License version 3 or later
This is a very simple extension to Sphinx that injects the ability to recognize and pretty print SQLAlchemy statements into its automodule and autoclass directives.
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.
Changes
1.2 (2017-03-22)
Minor tweak, no externally visible changes
1.1 (2017-01-17)
First release on PyPI
1.0 (unreleased)
Polished, tested and extended to support class’ attributes as well
Extracted from metapensiero.sphinx.patchdb
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for metapensiero.sphinx.autodoc_sa-1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fe01e3f5eaed848ded03ca399397e70bcbb8d5d9e9f7d33fea327434b15e70a |
|
MD5 | 7a339041255fb8a782f261760871fe44 |
|
BLAKE2b-256 | b754adbfdd3bc9e95a83c788d1856973de8d8ebaf1d5bf3210182bd9669c17e4 |