Skip to main content

Autodoc extension to pretty print canned SA queries

Project description

author:

Lele Gaifax

contact:

lele@metapensiero.it

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.

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 pglast SQL prettifier over the default one based on sqlparse:

autodoc_sa_prettifier = 'pglast'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metapensiero_sphinx_autodoc_sa-2.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file metapensiero_sphinx_autodoc_sa-2.2.tar.gz.

File metadata

File hashes

Hashes for metapensiero_sphinx_autodoc_sa-2.2.tar.gz
Algorithm Hash digest
SHA256 5caa1df612973ef8527c4cdf23600e3cf39c110c078ba9ef9667b474a083f276
MD5 3f479ffb4b2c288dd119399dcc21b077
BLAKE2b-256 63cfe58fe0fdde0e698031b0fc37de093f323a1a5255337eeeb4fae23e910ff3

See more details on using hashes here.

File details

Details for the file metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for metapensiero_sphinx_autodoc_sa-2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b845fdad56cb953fbc1f9183047a1d5c83044611274630ff1ac9a7ba840cef36
MD5 b6b078781751472612faac14a62c9316
BLAKE2b-256 18843ceb4f6eb64f3e4580d0f8301461d4ab0997b0e36bb60c8ba19d680c3036

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page