Skip to main content

Sphinx extension to handle Visual Basic Domain.

Project description

sphinx-vb-domain

≫日本語版

Overview

Sphinx extension to handle Visual Basic function directive, and also create the directives from document comments in VB source code.

This project is really experimental. Only features below are working but without any assurance.

Installation

pip

pip install sphinx-vb-domain

rye

rye add --dev sphinx-vb-domain

Usage

conf.py

Add it to extensions.

# conf.py

extensions = [
    'sphinx_vb_domain',
]

Function directive

For example.

.. vb:function:: Private Function getId(ByVal name As String, ByVal age As Integer) As Integer
   :module: Module1

   A simple private function.

   :param name: Name
   :type name: String
   :param age: Age
   :type age: Integer
   :returns: Id
   :rtype: Integer

   Remarks here.

Configuration

The following settings can be used in conf.py.

vb_add_function_labels

vb_add_function_labels = False  # Default: True

Setting to False disables adding target labels to function directives.
If you are using sphinx.ext.autosectionlabel, you may set this to False.
However, labels in sphinx-vb-domain take the form {module_name}.{function_name}, so if multiple modules have functions with the same name, you may take this feature.

vb_encode_invalid_labels

vb_encode_invalid_labels = False  # Default: True

If set to False, function names containing invalid characters for Sphinx target labels will not be hash-encoded.
This setting also applies to explicit labels added to module headings in Autodoc.

vb_add_docname_to_labels

vb_add_docname_to_labels = True  # Default: False

Setting to True adds labels to function directives in the form {filename}-{module_name}.{function_name}, allowing functions with the same name in the same module across multiple files to be distinguished.
This setting also applies to explicit labels added to module headings in Autodoc.

vb_docname_label_delimiter

vb_docname_label_delimiter = '__'  # Default: '-'

vb_add_docname_to_labels sets the delimiter that appears after the filename.
You must specify characters that are valid for Sphinx target labels.
This setting also applies to explicit labels added to module headings in Autodoc.

vb_autodoc_module_labels

vb_autodoc_module_labels = True  # Default: False

Setting to True adds explicit labels to module headings in Autodoc.

Autodoc

To create document from VB document comments, following config is needed.

# conf.py

vb_autodoc_paths = [
    ('vb-src-dir', 'page-path', 'page-title', notes),
]
  • 'vb-src-dir'
    • Path to directory contains VB source, relative from conf.py (e.g. '../../macros').
  • 'page-path'
    • Path to reST file tobe created, relative from Sphinx source directory (e.g. 'modules' will create 'modules.rst').
  • 'page-title'
    • Title (level-1 headline) added to e.g. modules.rst.
  • notes
    • Optional dict to add notes to below targets (dict keys).
      • '__page__': Note to be added under page title.
      • '<Module name>': Note to be added under the module's title.
      • '<Module name>.<Function name>': Note to be added under the function's directive.
    # Example
    # Note: Values can be reST, but you should not use headlines.
    notes = {
        '__page__': 'This is note for the page.',
        'Module1': 'This is note for Module1.',
        'Module1.MyFunction': 'This is note for MyFunction.',
    }
    

Then, run sphinx-build with -D vb_autodoc=1 parameter.

In file at page-path (e.g. 'modules.rst'), Module (level-2 headline) is created per vb file in vb-src-dir, and function directives under the Modules.

Notes from template

You can create a template in reST and convert it to dict as notes.

__page__
========

This is note for the page.

Module1
-------

This is note for Module1.

Module1.MyFunction
~~~~~~~~~~~~~~~~~~

This is note for MyFunction.

Put it in _templates folder, then call notes_from_template() function.

# conf.py
from sphinx_vb_domain.utils import notes_from_template

notes = notes_from_template('notes.rst')

vb_autodoc_paths = [
    ('vb-src-dir', 'page-path', 'page-title', notes),
]

Cross-references

When function directives are rendered, they come with a headline so that the directives appear in toctree.
Also, when vb_add_function_labels is set to True (Default), the headline will be a cross-reference target.

reStructuredText

* :vb:function:`module_name.function_name`
* :any:`module_name.function_name`
* :any:`Link text <module_name.function_name>`

MyST

- {vb:function}`module_name.function_name`
- <project:#module_name.function_name>
- [Link text](#module_name.function_name)

Known issues

  • Function directive always rendered in Japanese like follows.
    Private Function getId(ByVal name As String, ByVal age As Integer) As Integer
    
        A simple private function.
    
        パラメータ: ・name (String) -- Name
                    ・age (Integer) -- Age
        戻り値: Id
        戻り値の型: Integer
    
        Remarks here.
    
    • You can change doc_field_types definition of VBFunction class.

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

sphinx_vb_domain-0.7.0.tar.gz (823.8 kB view details)

Uploaded Source

Built Distribution

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

sphinx_vb_domain-0.7.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_vb_domain-0.7.0.tar.gz.

File metadata

  • Download URL: sphinx_vb_domain-0.7.0.tar.gz
  • Upload date:
  • Size: 823.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for sphinx_vb_domain-0.7.0.tar.gz
Algorithm Hash digest
SHA256 9aff1457d95b3d2244ebe6c3602a77250df81f2163dc7b7b5eb99ec9658c4d3a
MD5 135215544c57fbefbfe927fd56065e6c
BLAKE2b-256 aba320d447eae26656900ae7326bf1e8d892dfc588d38290152e21ed26da7630

See more details on using hashes here.

File details

Details for the file sphinx_vb_domain-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_vb_domain-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f354bd07cb3de9c5d2d717ab1c4850a11470a154d4db8176d990c274f509ad6
MD5 c3eb7fd89f1d7ab29c8314d08d8bee81
BLAKE2b-256 8215ec70dfb4f40cbc6268e917e11a6e9792db17a0f136052344bc2c5b5315b6

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