auto-pytabs


Nameauto-pytabs JSON
Version 0.5.0 PyPI version JSON
download
home_pageNone
SummaryAutomatically generate code examples for different Python versions in mkdocs or Sphinx based documentations
upload_time2024-08-18 13:02:28
maintainerNone
docs_urlNone
authorJanek Nouvertné
requires_python<4.0,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AutoPyTabs

Automatically generate code examples for different Python versions in
[mkdocs](https://www.mkdocs.org) or [Sphinx](https://www.sphinx-doc.org) based documentations, or a plain
[markdown](https://python-markdown.github.io/) workflow, making use of the
[pymdown "tabbed"](https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/) markdown extension for markdown,
and [sphinx{design} tabs](https://sphinx-design.readthedocs.io/en/latest/tabs.html) for Sphinx.

## Rationale

### The problem

Python project documentation typically include code examples. Given that most of the time, a project will support
multiple versions of Python, it would be ideal to showcase the adjustments that can or need to be made for different
Python versions. This can be achieved by including several versions of the example code, conveniently displayed using
the [pymdown "tabbed"](https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/) extension for markdown, or
[sphinx{design} tabs](https://sphinx-design.readthedocs.io/en/latest/tabs.html) for Sphinx.

This, however, raises several problems:

1. Maintaining multiple versions of a single example is tedious and error-prone as they can easily
   become out of sync
2. Figuring out which examples need to be changed for which specific Python version is a labour intensive task
3. Dropping or adding support for Python versions requires revisiting every example in the documentation
4. Checking potentially ~4 versions of a single example into VCS creates unnecessary noise

Given those, it's no surprise that the current standard is to only show examples for the lowest supported version of Python.

### The solution

**AutoPyTabs** aims to solve all of these problems by automatically generating versions (using the awesome
[ruff](https://github.com/charliermarsh/ruff) project) of code examples, targeting different Python versions
**at build-time**, based on a base version (the lowest supported Python version).
This means that:

1. There exists only one version of each example: The lowest supported version becomes the source of truth,
   therefore preventing out-of-sync examples and reducing maintenance burden
2. Dropping or adding support for Python versions can be done via a simple change in a configuration file

<hr>

## Table of contents

1. [Usage with mkdocs / markdown](#usage-markdown)
   1. [Configuration](#markdown-config)
   2. [Differences between the mkdocs plugin vs markdown extension](#differences-between-the-mkdocs-plugin-and-markdown-extension)
   3. [Examples](#markdown-examples)
   4. [Selectively disable](#selectively-disable)
   5. [Compatibility with `pymdownx.snippets`](#compatibility-with-pymdownxsnippets)
2. [Usage with Sphinx](#usage-with-sphinx)
   1. [Configuration](#sphinx-config)
   2. [Directives](#directives)
   3. [Examples](#sphinx-examples)
   4. [Compatibility with other extensions](#compatibility-with-other-extensions)

<hr> 

## Installation

For mkdocs: `pip install auto-pytabs[mkdocs]`
For markdown: `pip install auto-pytabs[markdown]`
For sphinx: `pip install auto-pytabs[sphinx]`

<h2 id="usage-markdown">Usage with mkdocs / markdown</h2>

<h3 id="markdown-config">Configuration</h3>

#### Mkdocs plugin

```yaml
site_name: My Docs
markdown_extensions:
  - pymdownx.tabbed:
plugins:
  - auto_pytabs:
      min_version: "3.7"  # optional
      max_version: "3.12" # optional
      tab_title_template: "Python {min_version}+"  # optional
      no_cache: false  # optional
      default_tab: "highest"  # optional
      reverse_order: false  # optional
```

*Available configuration options*

| Name                 | Default                   | Description                                                                |
| -------------------- | ------------------------- | -------------------------------------------------------------------------- |
| `min_version`        | `(3, 7)`                  | Minimum python version                                                     |
| `max_version`        | `(3, 12)`                 | Maximum python version                                                     |
| `tab_title_template` | `"Python {min_version}+"` | Template for tab titles                                                    |
| `no_cache`           | `False`                   | Disable file system caching                                                |
| `default_tab`        | `highest`                 | (`highest` or `lowest`) Version tab to preselect                           |
| `reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |

#### Markdown extension

```python
import markdown

md = markdown.Markdown(
    extensions=["auto_pytabs"],
    extension_configs={
        "auto_pytabs": {
            "min_version": "3.7",  # optional
            "max_version": "3.12",  # optional
            "tab_title_template": "Python {min_version}+",  # optional
            "default_tab": "highest",  # optional
            "reverse_order": False,  # optional
        }
    },
)
```

*Available configuration options*

| Name                 | Default                   | Description                                                                |
| -------------------- | ------------------------- | -------------------------------------------------------------------------- |
| `min_version`        | `(3, 7)`                  | Minimum python version to generate code for                                |
| `max_version`        | `(3, 7)`                  | Maximum python version to generate code for                                |
| `tab_title_template` | `"Python {min_version}+"` | Template for tab titles                                                    |
| `default_tab`        | `highest`                 | (`highest` or `lowest`) Version tab to preselect                           |
| `reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |

### Differences between the mkdocs plugin and markdown extension

AutoPyTabs ships as a markdown extension and an mkdocs plugin, both of which can be used in mkdocs. The only difference
between them is that the mkdocs plugin supports caching, which can make subsequent builds faster (i.e. when using `mkdocs serve`).
The reason why the markdown extension does not support caching is that `markdown` does not have clearly defined build
steps with wich an extension could interact (like mkdocs [plugin events](https://www.mkdocs.org/dev-guide/plugins/#events)),
making it impossible to know when to persist cached items to disk / evict unused items.

**If you are using mkdocs, the mkdocs plugin is recommended**. If you have caching disabled, there will be no difference either way.

Should you wish to integrate the markdown extension into a build process where you can manually persist the cache after the build,
you can explicitly pass it a cache:

```python
import markdown
from auto_pytabs.core import Cache

cache = Cache()

md = markdown.Markdown(
    extensions=["auto_pytabs"],
    extension_configs={
        "auto_pytabs": {
           "cache": cache
        }
    },
)


def build_markdown() -> None:
    md.convertFile("document.md", "document.html")
    cache.persist()
```

<h3 id="markdown-examples">Examples</h3>

**Input**

<pre>
```python
from typing import Optional, Dict

def foo(bar: Optional[str]) -> Dict[str, str]:
    ...
```
</pre>

**Equivalent markdown**

<pre>
=== "Python 3.7+"
    ```python
    from typing import Optional, Dict

    def foo(bar: Optional[str]) -> Dict[str, str]:
        ...
    ```

=== "Python 3.9+"
    ```python
    from typing import Optional
    
    
    def foo(bar: Optional[str]) -> dict[str, str]:
        ...
    ```

==== "Python 3.10+"
    ```python
    def foo(bar: str | None) -> dict[str, str]:
        ...
    ```
</pre>

#### Nested blocks

Nested tabs are supported as well:

**Input**

<pre>
=== "Level 1-1"

    === "Level 2-1"

        ```python
        from typing import List
        x: List[str]
        ```

    === "Level 2-2"
    
        Hello, world!

=== "Level 1-2"

    Goodbye, world!
</pre>

**Equivalent markdown**

<pre>
=== "Level 1-1"

    === "Level 2-1"

        === "Python 3.7+"
            ```python
            from typing import List
            x: List[str]
            ```
        
        === "Python 3.9+"
            ```python
            x: list[str]
            ```

    === "Level 2-2"

        Goodbye, world!

=== "Level 1-2"
    Hello, world!
    
</pre>

### Selectively disable

You can disable conversion for a single code block:

````
<!-- autopytabs: disable-block -->
```python
from typing import Set, Optional

def bar(baz: Optional[str]) -> Set[str]:
    ...
```
````

Or for whole sections / files

```
<!-- autopytabs: disable -->
everything after this will be ignored
<!-- autopytabs: enable -->
re-enables conversion again
```

### Compatibility with `pymdownx.snippets`

If the `pymdownx.snippets` extension is used, make sure that it runs **before** AutoPyTab

<hr>

## Usage with Sphinx

AutPyTabs provides a Sphinx extension `auto_pytabs.sphinx_ext`, enabling its functionality
for the `.. code-block` and `.. literalinclude` directives.

<h3 id="sphinx-config">Configuration</h3>

#### Example configuration

```python
extensions = ["auto_pytabs.sphinx_ext", "sphinx_design"]

auto_pytabs_min_version = (3, 7)  # optional
auto_pytabs_max_version = (3, 11)  # optional
auto_pytabs_tab_title_template = "Python {min_version}+"  # optional 
# auto_pytabs_no_cache = True  # disabled file system caching
# auto_pytabs_compat_mode = True  # enable compatibility mode
# auto_pytabs_default_tab = "lowest"  # Pre-select the tab with the lowest version
# auto_pytabs_reverse_order = True  # reverse the order of tabs to highest > lowest
```

#### Available configuration options

| Name                             | Default                   | Description                                                                |
| -------------------------------- | ------------------------- | -------------------------------------------------------------------------- |
| `auto_pytabs_min_version`        | `(3, 7)`                  | Minimum python version to generate code for                                |
| `auto_pytabs_max_version`        | `(3, 7)`                  | Maximum python version to generate code for                                |
| `auto_pytabs_tab_title_template` | `"Python {min_version}+"` | Template for tab titles                                                    |
| `auto_pytabs_no_cache`           | `False`                   | Disable file system caching                                                |
| `auto_pytabs_compat_mode`        | `False`                   | Enable [compatibility mode](#compatibility-mode)                           |
| `auto_pytabs_default_tab`        | `highest`                 | Either `highest` or `lowest`. Version tab to preselect                     |
| `auto_pytabs_reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |

<h3 id="sphinx-examples">Examples</h3>

**Input**

```rst
.. code-block:: python

   from typing import Optional, Dict
   
   def foo(bar: Optional[str]) -> Dict[str, str]:
       ...
```

**Equivalent ReST**

```rst
.. tab-set::

   .. tab-item:: Python 3.7+
   
       .. code-block:: python
       
          from typing import Optional, Dict
      
          def foo(bar: Optional[str]) -> Dict[str, str]:
              ...

   .. tab-item:: Python 3.9+
   
      .. code-block:: python
      
          from typing import Optional
          
          
          def foo(bar: Optional[str]) -> dict[str, str]:
              ...

   .. tab-item:: Python 3.10+
   
      .. code-block:: python
      
          def foo(bar: str | None) -> dict[str, str]:
              ...

```

### Directives

AutoPyTabs overrides the built-in `code-block` and `literal-include` directives,
extending them with auto-upgrade and tabbing functionality, which means no special
directives, and therefore changes to existing documents are needed.

Additionally, a `:no-upgrade:` option is added to the directives, which can be used to
selectively fall back the default behaviour.

Two new directives are provided as well:

- `.. pytabs-code-block::`
- `.. pytabs-literalinclude::`

which by default act exactly like `.. code-block` and `.. literalinclude` respectively,
and are mainly to provide AutoPyTab's functionality in [compatibility mode](#compatibility-mode).

### Compatibility mode

If you don't want the default behaviour of directive overrides, and instead wish to use the
`.. pytabs-` directives manually (e.g. because of compatibility issues with other extensions
or because you only want to apply it to select code blocks) you can make use AutoPyTabs' compatibility
mode. To enable it, simply use the `auto_pytabs_compat_mode = True` in `conf.py`. Now, only content within `.. pytabs-`
directives will be upgraded.

### Compatibility with other extensions

Normally the directive overrides don't cause any problems and are very convenient,
since no changes to existing documents have to be made. However, if other extensions are included,
which themselves override one of those directives, one of them will inadvertently override the other,
depending on the order they're defined in `extensions`.

To combat this, you can use the [compatibility mode](#compatibility-mode) extension instead, which
only includes the new directives.

If you control the conflicting overrides, you can alternatively inherit from
`auto_py_tabs.sphinx_ext.CodeBlockOverride` and `auto_py_tabs.sphinx_ext.LiteralIncludeOverride`
instead of `sphinx.directives.code.CodeBlock` and `sphinx.directives.code.LiteralInclude` respectively.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "auto-pytabs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Janek Nouvertn\u00e9",
    "author_email": "provinzkraut@posteo.de",
    "download_url": "https://files.pythonhosted.org/packages/f9/ff/f5752f43f659ee62dd563af5bb0fe0a63111c3ff4708e9596279385f52bb/auto_pytabs-0.5.0.tar.gz",
    "platform": null,
    "description": "# AutoPyTabs\n\nAutomatically generate code examples for different Python versions in\n[mkdocs](https://www.mkdocs.org) or [Sphinx](https://www.sphinx-doc.org) based documentations, or a plain\n[markdown](https://python-markdown.github.io/) workflow, making use of the\n[pymdown \"tabbed\"](https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/) markdown extension for markdown,\nand [sphinx{design} tabs](https://sphinx-design.readthedocs.io/en/latest/tabs.html) for Sphinx.\n\n## Rationale\n\n### The problem\n\nPython project documentation typically include code examples. Given that most of the time, a project will support\nmultiple versions of Python, it would be ideal to showcase the adjustments that can or need to be made for different\nPython versions. This can be achieved by including several versions of the example code, conveniently displayed using\nthe [pymdown \"tabbed\"](https://facelessuser.github.io/pymdown-extensions/extensions/tabbed/) extension for markdown, or\n[sphinx{design} tabs](https://sphinx-design.readthedocs.io/en/latest/tabs.html) for Sphinx.\n\nThis, however, raises several problems:\n\n1. Maintaining multiple versions of a single example is tedious and error-prone as they can easily\n   become out of sync\n2. Figuring out which examples need to be changed for which specific Python version is a labour intensive task\n3. Dropping or adding support for Python versions requires revisiting every example in the documentation\n4. Checking potentially ~4 versions of a single example into VCS creates unnecessary noise\n\nGiven those, it's no surprise that the current standard is to only show examples for the lowest supported version of Python.\n\n### The solution\n\n**AutoPyTabs** aims to solve all of these problems by automatically generating versions (using the awesome\n[ruff](https://github.com/charliermarsh/ruff) project) of code examples, targeting different Python versions\n**at build-time**, based on a base version (the lowest supported Python version).\nThis means that:\n\n1. There exists only one version of each example: The lowest supported version becomes the source of truth,\n   therefore preventing out-of-sync examples and reducing maintenance burden\n2. Dropping or adding support for Python versions can be done via a simple change in a configuration file\n\n<hr>\n\n## Table of contents\n\n1. [Usage with mkdocs / markdown](#usage-markdown)\n   1. [Configuration](#markdown-config)\n   2. [Differences between the mkdocs plugin vs markdown extension](#differences-between-the-mkdocs-plugin-and-markdown-extension)\n   3. [Examples](#markdown-examples)\n   4. [Selectively disable](#selectively-disable)\n   5. [Compatibility with `pymdownx.snippets`](#compatibility-with-pymdownxsnippets)\n2. [Usage with Sphinx](#usage-with-sphinx)\n   1. [Configuration](#sphinx-config)\n   2. [Directives](#directives)\n   3. [Examples](#sphinx-examples)\n   4. [Compatibility with other extensions](#compatibility-with-other-extensions)\n\n<hr> \n\n## Installation\n\nFor mkdocs: `pip install auto-pytabs[mkdocs]`\nFor markdown: `pip install auto-pytabs[markdown]`\nFor sphinx: `pip install auto-pytabs[sphinx]`\n\n<h2 id=\"usage-markdown\">Usage with mkdocs / markdown</h2>\n\n<h3 id=\"markdown-config\">Configuration</h3>\n\n#### Mkdocs plugin\n\n```yaml\nsite_name: My Docs\nmarkdown_extensions:\n  - pymdownx.tabbed:\nplugins:\n  - auto_pytabs:\n      min_version: \"3.7\"  # optional\n      max_version: \"3.12\" # optional\n      tab_title_template: \"Python {min_version}+\"  # optional\n      no_cache: false  # optional\n      default_tab: \"highest\"  # optional\n      reverse_order: false  # optional\n```\n\n*Available configuration options*\n\n| Name                 | Default                   | Description                                                                |\n| -------------------- | ------------------------- | -------------------------------------------------------------------------- |\n| `min_version`        | `(3, 7)`                  | Minimum python version                                                     |\n| `max_version`        | `(3, 12)`                 | Maximum python version                                                     |\n| `tab_title_template` | `\"Python {min_version}+\"` | Template for tab titles                                                    |\n| `no_cache`           | `False`                   | Disable file system caching                                                |\n| `default_tab`        | `highest`                 | (`highest` or `lowest`) Version tab to preselect                           |\n| `reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |\n\n#### Markdown extension\n\n```python\nimport markdown\n\nmd = markdown.Markdown(\n    extensions=[\"auto_pytabs\"],\n    extension_configs={\n        \"auto_pytabs\": {\n            \"min_version\": \"3.7\",  # optional\n            \"max_version\": \"3.12\",  # optional\n            \"tab_title_template\": \"Python {min_version}+\",  # optional\n            \"default_tab\": \"highest\",  # optional\n            \"reverse_order\": False,  # optional\n        }\n    },\n)\n```\n\n*Available configuration options*\n\n| Name                 | Default                   | Description                                                                |\n| -------------------- | ------------------------- | -------------------------------------------------------------------------- |\n| `min_version`        | `(3, 7)`                  | Minimum python version to generate code for                                |\n| `max_version`        | `(3, 7)`                  | Maximum python version to generate code for                                |\n| `tab_title_template` | `\"Python {min_version}+\"` | Template for tab titles                                                    |\n| `default_tab`        | `highest`                 | (`highest` or `lowest`) Version tab to preselect                           |\n| `reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |\n\n### Differences between the mkdocs plugin and markdown extension\n\nAutoPyTabs ships as a markdown extension and an mkdocs plugin, both of which can be used in mkdocs. The only difference\nbetween them is that the mkdocs plugin supports caching, which can make subsequent builds faster (i.e. when using `mkdocs serve`).\nThe reason why the markdown extension does not support caching is that `markdown` does not have clearly defined build\nsteps with wich an extension could interact (like mkdocs [plugin events](https://www.mkdocs.org/dev-guide/plugins/#events)),\nmaking it impossible to know when to persist cached items to disk / evict unused items.\n\n**If you are using mkdocs, the mkdocs plugin is recommended**. If you have caching disabled, there will be no difference either way.\n\nShould you wish to integrate the markdown extension into a build process where you can manually persist the cache after the build,\nyou can explicitly pass it a cache:\n\n```python\nimport markdown\nfrom auto_pytabs.core import Cache\n\ncache = Cache()\n\nmd = markdown.Markdown(\n    extensions=[\"auto_pytabs\"],\n    extension_configs={\n        \"auto_pytabs\": {\n           \"cache\": cache\n        }\n    },\n)\n\n\ndef build_markdown() -> None:\n    md.convertFile(\"document.md\", \"document.html\")\n    cache.persist()\n```\n\n<h3 id=\"markdown-examples\">Examples</h3>\n\n**Input**\n\n<pre>\n```python\nfrom typing import Optional, Dict\n\ndef foo(bar: Optional[str]) -> Dict[str, str]:\n    ...\n```\n</pre>\n\n**Equivalent markdown**\n\n<pre>\n=== \"Python 3.7+\"\n    ```python\n    from typing import Optional, Dict\n\n    def foo(bar: Optional[str]) -> Dict[str, str]:\n        ...\n    ```\n\n=== \"Python 3.9+\"\n    ```python\n    from typing import Optional\n    \n    \n    def foo(bar: Optional[str]) -> dict[str, str]:\n        ...\n    ```\n\n==== \"Python 3.10+\"\n    ```python\n    def foo(bar: str | None) -> dict[str, str]:\n        ...\n    ```\n</pre>\n\n#### Nested blocks\n\nNested tabs are supported as well:\n\n**Input**\n\n<pre>\n=== \"Level 1-1\"\n\n    === \"Level 2-1\"\n\n        ```python\n        from typing import List\n        x: List[str]\n        ```\n\n    === \"Level 2-2\"\n    \n        Hello, world!\n\n=== \"Level 1-2\"\n\n    Goodbye, world!\n</pre>\n\n**Equivalent markdown**\n\n<pre>\n=== \"Level 1-1\"\n\n    === \"Level 2-1\"\n\n        === \"Python 3.7+\"\n            ```python\n            from typing import List\n            x: List[str]\n            ```\n        \n        === \"Python 3.9+\"\n            ```python\n            x: list[str]\n            ```\n\n    === \"Level 2-2\"\n\n        Goodbye, world!\n\n=== \"Level 1-2\"\n    Hello, world!\n    \n</pre>\n\n### Selectively disable\n\nYou can disable conversion for a single code block:\n\n````\n<!-- autopytabs: disable-block -->\n```python\nfrom typing import Set, Optional\n\ndef bar(baz: Optional[str]) -> Set[str]:\n    ...\n```\n````\n\nOr for whole sections / files\n\n```\n<!-- autopytabs: disable -->\neverything after this will be ignored\n<!-- autopytabs: enable -->\nre-enables conversion again\n```\n\n### Compatibility with `pymdownx.snippets`\n\nIf the `pymdownx.snippets` extension is used, make sure that it runs **before** AutoPyTab\n\n<hr>\n\n## Usage with Sphinx\n\nAutPyTabs provides a Sphinx extension `auto_pytabs.sphinx_ext`, enabling its functionality\nfor the `.. code-block` and `.. literalinclude` directives.\n\n<h3 id=\"sphinx-config\">Configuration</h3>\n\n#### Example configuration\n\n```python\nextensions = [\"auto_pytabs.sphinx_ext\", \"sphinx_design\"]\n\nauto_pytabs_min_version = (3, 7)  # optional\nauto_pytabs_max_version = (3, 11)  # optional\nauto_pytabs_tab_title_template = \"Python {min_version}+\"  # optional \n# auto_pytabs_no_cache = True  # disabled file system caching\n# auto_pytabs_compat_mode = True  # enable compatibility mode\n# auto_pytabs_default_tab = \"lowest\"  # Pre-select the tab with the lowest version\n# auto_pytabs_reverse_order = True  # reverse the order of tabs to highest > lowest\n```\n\n#### Available configuration options\n\n| Name                             | Default                   | Description                                                                |\n| -------------------------------- | ------------------------- | -------------------------------------------------------------------------- |\n| `auto_pytabs_min_version`        | `(3, 7)`                  | Minimum python version to generate code for                                |\n| `auto_pytabs_max_version`        | `(3, 7)`                  | Maximum python version to generate code for                                |\n| `auto_pytabs_tab_title_template` | `\"Python {min_version}+\"` | Template for tab titles                                                    |\n| `auto_pytabs_no_cache`           | `False`                   | Disable file system caching                                                |\n| `auto_pytabs_compat_mode`        | `False`                   | Enable [compatibility mode](#compatibility-mode)                           |\n| `auto_pytabs_default_tab`        | `highest`                 | Either `highest` or `lowest`. Version tab to preselect                     |\n| `auto_pytabs_reverse_order`      | `False`                   | Reverse the order of tabs. Default is to go from lowest to highest version |\n\n<h3 id=\"sphinx-examples\">Examples</h3>\n\n**Input**\n\n```rst\n.. code-block:: python\n\n   from typing import Optional, Dict\n   \n   def foo(bar: Optional[str]) -> Dict[str, str]:\n       ...\n```\n\n**Equivalent ReST**\n\n```rst\n.. tab-set::\n\n   .. tab-item:: Python 3.7+\n   \n       .. code-block:: python\n       \n          from typing import Optional, Dict\n      \n          def foo(bar: Optional[str]) -> Dict[str, str]:\n              ...\n\n   .. tab-item:: Python 3.9+\n   \n      .. code-block:: python\n      \n          from typing import Optional\n          \n          \n          def foo(bar: Optional[str]) -> dict[str, str]:\n              ...\n\n   .. tab-item:: Python 3.10+\n   \n      .. code-block:: python\n      \n          def foo(bar: str | None) -> dict[str, str]:\n              ...\n\n```\n\n### Directives\n\nAutoPyTabs overrides the built-in `code-block` and `literal-include` directives,\nextending them with auto-upgrade and tabbing functionality, which means no special\ndirectives, and therefore changes to existing documents are needed.\n\nAdditionally, a `:no-upgrade:` option is added to the directives, which can be used to\nselectively fall back the default behaviour.\n\nTwo new directives are provided as well:\n\n- `.. pytabs-code-block::`\n- `.. pytabs-literalinclude::`\n\nwhich by default act exactly like `.. code-block` and `.. literalinclude` respectively,\nand are mainly to provide AutoPyTab's functionality in [compatibility mode](#compatibility-mode).\n\n### Compatibility mode\n\nIf you don't want the default behaviour of directive overrides, and instead wish to use the\n`.. pytabs-` directives manually (e.g. because of compatibility issues with other extensions\nor because you only want to apply it to select code blocks) you can make use AutoPyTabs' compatibility\nmode. To enable it, simply use the `auto_pytabs_compat_mode = True` in `conf.py`. Now, only content within `.. pytabs-`\ndirectives will be upgraded.\n\n### Compatibility with other extensions\n\nNormally the directive overrides don't cause any problems and are very convenient,\nsince no changes to existing documents have to be made. However, if other extensions are included,\nwhich themselves override one of those directives, one of them will inadvertently override the other,\ndepending on the order they're defined in `extensions`.\n\nTo combat this, you can use the [compatibility mode](#compatibility-mode) extension instead, which\nonly includes the new directives.\n\nIf you control the conflicting overrides, you can alternatively inherit from\n`auto_py_tabs.sphinx_ext.CodeBlockOverride` and `auto_py_tabs.sphinx_ext.LiteralIncludeOverride`\ninstead of `sphinx.directives.code.CodeBlock` and `sphinx.directives.code.LiteralInclude` respectively.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Automatically generate code examples for different Python versions in mkdocs or Sphinx based documentations",
    "version": "0.5.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6edfe76dc1261882283f7ae93ebbf75438e85d8bb713a51dbbd5d17fef29e607",
                "md5": "2ca25783d6e2a6284f3cb944b87d758f",
                "sha256": "e59fb6d2f8b41b05d0906a322dd4bb1a86749d429483ec10036587de3657dcc8"
            },
            "downloads": -1,
            "filename": "auto_pytabs-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ca25783d6e2a6284f3cb944b87d758f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 13748,
            "upload_time": "2024-08-18T13:02:26",
            "upload_time_iso_8601": "2024-08-18T13:02:26.907417Z",
            "url": "https://files.pythonhosted.org/packages/6e/df/e76dc1261882283f7ae93ebbf75438e85d8bb713a51dbbd5d17fef29e607/auto_pytabs-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9fff5752f43f659ee62dd563af5bb0fe0a63111c3ff4708e9596279385f52bb",
                "md5": "ca4c2db7aaea61113db1da61889431f7",
                "sha256": "30087831c8be5b2314e663efd06c96b84c096572a060a492540f586362cc4326"
            },
            "downloads": -1,
            "filename": "auto_pytabs-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ca4c2db7aaea61113db1da61889431f7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 15362,
            "upload_time": "2024-08-18T13:02:28",
            "upload_time_iso_8601": "2024-08-18T13:02:28.437088Z",
            "url": "https://files.pythonhosted.org/packages/f9/ff/f5752f43f659ee62dd563af5bb0fe0a63111c3ff4708e9596279385f52bb/auto_pytabs-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 13:02:28",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "auto-pytabs"
}
        
Elapsed time: 0.31801s