File: imageio_ext.py

package info (click to toggle)
python-imageio 2.37.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,016 kB
  • sloc: python: 26,044; makefile: 138
file content (58 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
""" Invoke various functionality for imageio docs.
"""

from pathlib import Path

import imageio


def setup(app):
    app.connect("source-read", rstjinja)


def rstjinja(app, docname, source):
    if docname == "formats/index":
        from imageio.config import known_plugins, extension_list

        src = source[0]
        rendered = app.builder.templates.render_string(
            src, {"formats": extension_list, "plugins": known_plugins}
        )
        source[0] = rendered

    if docname == "formats/video_formats":
        from imageio.config import known_plugins, video_extensions

        src = source[0]
        rendered = app.builder.templates.render_string(
            src, {"formats": video_extensions, "plugins": known_plugins}
        )
        source[0] = rendered

    if docname.endswith("standardimages"):
        from imageio.core.request import EXAMPLE_IMAGES

        src = source[0]
        rendered = app.builder.templates.render_string(
            src,
            {
                "images": EXAMPLE_IMAGES,
                "ordered_keys": sorted(
                    EXAMPLE_IMAGES, key=lambda x: tuple(reversed(x.rsplit(".", 1)))
                ),
                "base_url": "https://github.com/imageio/imageio-binaries/raw/master/images/",
            },
        )
        source[0] = rendered

    if docname == "development/plugins":
        example_plugin = (
            Path(imageio.plugins.__file__).parent / "example.py"
        ).read_text()
        example_plugin = [line.rstrip() for line in example_plugin.splitlines()]

        src = source[0]
        rendered = app.builder.templates.render_string(
            src, {"example_plugin": example_plugin}
        )
        source[0] = rendered