Code Monkey home page Code Monkey logo

sphinx-wavedrom's Introduction

Sphinx wavedrom extension

A sphinx extension that allows including wavedrom diagrams by using its text-based representation

Wavedrom online editor and tutorial: https://wavedrom.com/

image

image

Installation

The wavedrom extension can be installed using pip:

pip install sphinxcontrib-wavedrom

and by adding 'sphinxcontrib.wavedrom' to the extensions list in your conf.py file.

Directives

The extension is useable in the form of an extra wavedrom directive, as shown below.

.. wavedrom::

    { "signal": [
        { "name": "clk",  "wave": "P......" },
        { "name": "bus",  "wave": "x.==.=x", "data": ["head", "body", "tail", "data"] },
        { "name": "wire", "wave": "0.1..0." }
    ]}

Alternatively, it can read the json from a file:

.. wavedrom:: mywave.json

When configured to generate images (see Configuration) the directive will generate an image and include it into the input. It allows for the same configuration as the image directive:

.. wavedrom:: mywave.json
    :height: 100px
    :width: 200 px
    :scale: 50 %
    :alt: alternate text
    :align: right

The image can be turned into a figure by adding a caption:

.. wavedrom:: mywave.json
    :caption: My wave figure

The extension can be configured (see Configuration) to not generate an image out of the diagram description itself, but to surround it with some html and js tags in the final html document that allow the images to be rendered by the browser. This is the currently the default for HTML output.

Configuration

The following decision tree gives an overview of which configurations to make in different use cases:

Decision tree for configuration settings

The extension can be configured to either directly output images or by emitting the javascript to live-render the wavedrom code, which obviously only works for HTML output. All other outputs (most notably latexpdf) embed a generated image in any case, but this is only supported when using Python 3.

Depending on the output you're building, the plugin will automatically choose the appropriate image rendering method (HTML defaults to browser rendering, pdf to build-time image generation). You can force the generation of build-time images by adding the following configuration to your conf.py:

wavedrom_html_jsinline = False

This may be interesting in case you are building for various output targets and want to ensure consistent diagrams between all output formats

Build-time image generation through wavedrompy or wavedrom-cli

2 Tools are available for the build-time generation of images:

  • wavedrom-cli: The default builder. This is the tool maintained by the wavedrom team itself. More bloaty than wavedrompy as it requires node.js and npm to install and use, but more likely to render consistent images w.r.t. the browser-rendered version.
  • wavedrompy: A python "clone" of wavedrompy. The goal of the project is to stay as close as possible to the JS implementation, but offer a solution that doesn't require node.js or npm to be installed.

As mentioned, wavedrom-cli is the default builder. If you want to select wavedrompy instead, add render_using_wavedrompy = True to your conf.py:

Wavedrompy is imported as a python module and requires no further configuration. Wavedrom-cli is executed using system calls. The default command is npx wavedrom-cli, but this can be overwritten using the wavedrom_cli configuration parameter in conf.py

Browser-rendered images through inline Javascript

When HTML building is configured to inline the javascript (default), the extension can work in 2 modes:

  • Online mode: the extension links to the javascript file(s) hosted on the wavedrom server or your own server
  • Offline mode: the extension uses the javascript file(s) that are saved locally on your drive.

The online mode is the default one. In case you want to use the js files hosted on the wavedrom server, no configuration is needed. However, in case the desired JS files are hosted on a custom server (or on localhost) add the following to conf.py:

  • online_wavedrom_js_url : the url of the server hosting the javascript files. The plugin will look for 2 files:

    • {online_wavedrom_js_url}/skins/default.js
    • {online_wavedrom_js_url}/wavedrom.min.js

Warning: A full URI is needed when configuring. "http://www.google.com" will work but "www.google.com" won't.

If offline mode is desired, the following configuration parameters need to be provided:

The paths given for these configurations need to be relative to the configuration directory (the directory that contains conf.py)

Examples

In the example folder, you can find a couple of examples (taken from the wavedrom tutorial), illustration the use of the extension.

sphinx-wavedrom's People

Contributors

bavovanachte avatar jdillard avatar joshuascheid avatar newam avatar oharboe avatar steinheselmans avatar umarcor avatar wallento avatar zegervdv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sphinx-wavedrom's Issues

Read wavedrom from file

Hi,

it would be great if it where possible to read the data from a file.

like:
.. wavedrom:: wavedrom.json

Relative paths for wavedrom-cli

I don't normally install Node or NPM on my machines. I didn't want to install it purely for wavedrom-cli, so I tried to use a Docker container. I was able to pull a Node container and install wavedrom-cli within it. Then I created a little wrapper script to use the container as if it were an executable. With that approach, I was able to produce SVGs at the command line.

Unfortunately, I was not able to use it with this plugin. The problem is one of absolute vs. relative paths. Because I have to mount a host directory into the container, I need to know the relative path to the input file, not the absolute path. Yet the current implementation uses an absolute path.

Would you consider making these paths relative? Do you think it could break anything?

For the moment, I'm using realpath --relative-to="$PWD" in my wrapper script. It works, but it's not the most robust solution. I thought I would at least ask to see if there might be a better approach.

Make the wavedrom link configurable

As I understand, the wavedrom link to the JavaScript file is hard-coded.
I had a recent issue with github page that can't render the wavedrom diagram (mixed content error -> try to download http content in a https page).
There are several work-arround (offline wavedrom), but i think the best way is to leave the user specify (if needed) the link to the necessary scripts in the conf.py.

Can this extension be marked parallel read and/or write safe?

I get the following warning:

WARNING: the sphinxcontrib.wavedrom extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit

Adding parallel_read_safe (and parallel_write_safe if that is also true) to the setup definition will fix that warning:

return {
    'parallel_read_safe': True,
    'parallel_write_safe': True
}

If that is the case, I don't mind making a PR to add them.

Release

can you please release? There were some updates right after the last release. Thanks!

Latest Wavedrom release (v2.0.0) broken with Sphinx v3.0

Yesterday Sphinx released v3.0 which removes support for 'copy_static_entry' from 'sphinx.util'. The latest pypi build of sphinx-wavedrom still uses these function and is now broken when using the latest sphinx release.

The dependency on this function was already removed in issue #16, but no official release of this tool was made since that change.

Can a new pypi package be created which includes (at least) this fix?

Fall back to wavedrompy, or give more helpful error message

When I updated to version 3.x I got failing ReadTheDocs builds with wavedrom command 'npx wavedrom-cli' cannot be run, which is due to the default being now wavedrom CLI being used, which cannot be installed on ReadTheDocs.

To improve user experience, would it be possible to

  • either give a better error message, indicating how one can switch back to the previous default of wavedrompy? (e.g. "Unable to use wavedrom-cli. Set render_using_wavedrompy = True to use a Python implementation of Wavedrom instead.")
  • or fall back automatically?

wavedrom not working with make latexpdf

Hi, I'm using this extension to generate the html with Sphinx and everything works fine. When I try to generate a pdf with make latexpdf I get a timeout after 120sec.

Is this a bug in the extension?

Unable to install: Issues in installing cairo dependency

The documentation says that to install, one must run pip install sphinxcontrib-wavedrom. However, that is causing errors:

[6:19:58 pm] ~/Documents/Code/doctest> pip install sphinxcontrib-wavedrom
Collecting sphinxcontrib-wavedrom
  Using cached https://files.pythonhosted.org/packages/5b/ee/7f8a4cf6a590fcf060ca4bde188cb5afaade80e1155e93d9a32545272127/sphinxcontrib_wavedrom-2.0.0-py3-none-any.whl

Requirement already satisfied: Sphinx>=1.8 in c:\python37\lib\site-packages (from sphinxcontrib-wavedrom) (2.2.0)
Requirement already satisfied: xcffib; python_version >= "3.3" in c:\python37\lib\site-packages (from sphinxcontrib-wavedrom) (0.8.1)
Collecting wavedrom>=0.1 (from sphinxcontrib-wavedrom)
  Using cached https://files.pythonhosted.org/packages/07/e2/7e71626b60e5549d0dd2d07dd15569d71dbda4d648fc77293aa528dc6c49/wavedrom-2.0.3.post2.tar.gz
Collecting cairosvg>=2; python_version >= "3.3" (from sphinxcontrib-wavedrom)
  Using cached https://files.pythonhosted.org/packages/8e/3a/762f9272c20db092f4d537aaf364dd0770ecf8f7101b58c4e933e99ee2f6/CairoSVG-2.4.2-py3-none-any.whl
Requirement already satisfied: sphinxcontrib-htmlhelp in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.0.2)
Requirement already satisfied: setuptools in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (40.8.0)
Requirement already satisfied: sphinxcontrib-jsmath in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.0.1)
Requirement already satisfied: packaging in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (19.1)
Requirement already satisfied: imagesize in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.1.0)
Requirement already satisfied: sphinxcontrib-devhelp in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.0.1)
Requirement already satisfied: Pygments>=2.0 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (2.4.2)
Requirement already satisfied: sphinxcontrib-applehelp in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.0.1)
Requirement already satisfied: alabaster<0.8,>=0.7 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (0.7.12)
Requirement already satisfied: babel!=2.0,>=1.3 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (2.7.0)
Requirement already satisfied: requests>=2.5.0 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (2.22.0)
Requirement already satisfied: Jinja2>=2.3 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (2.10.1)
Requirement already satisfied: snowballstemmer>=1.1 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.9.1)
Requirement already satisfied: sphinxcontrib-qthelp in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.0.2)
Requirement already satisfied: docutils>=0.12 in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (0.15.2)
Requirement already satisfied: colorama>=0.3.5; sys_platform == "win32" in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (0.3.9)
Requirement already satisfied: sphinxcontrib-serializinghtml in c:\python37\lib\site-packages (from Sphinx>=1.8->sphinxcontrib-wavedrom) (1.1.3)
Requirement already satisfied: six in c:\python37\lib\site-packages (from xcffib; python_version >= "3.3"->sphinxcontrib-wavedrom) (1.11.0)
Requirement already satisfied: cffi>=1.1.0 in c:\python37\lib\site-packages (from xcffib; python_version >= "3.3"->sphinxcontrib-wavedrom) (1.12.3)
Collecting svgwrite (from wavedrom>=0.1->sphinxcontrib-wavedrom)
  Using cached https://files.pythonhosted.org/packages/4f/2e/f36cfec1da6162055b884e6366074cff18475a9538559ceae0c0bc58e186/svgwrite-1.3.1-py2.py3-none-any.whl
Collecting attrdict (from wavedrom>=0.1->sphinxcontrib-wavedrom)
  Using cached https://files.pythonhosted.org/packages/ef/97/28fe7e68bc7adfce67d4339756e85e9fcf3c6fd7f0c0781695352b70472c/attrdict-2.0.1-py2.py3-none-any.whl
Requirement already satisfied: pillow in c:\python37\lib\site-packages (from cairosvg>=2; python_version >= "3.3"->sphinxcontrib-wavedrom) (6.1.0)
Requirement already satisfied: defusedxml in c:\python37\lib\site-packages (from cairosvg>=2; python_version >= "3.3"->sphinxcontrib-wavedrom) (0.6.0)
Requirement already satisfied: tinycss2 in c:\python37\lib\site-packages (from cairosvg>=2; python_version >= "3.3"->sphinxcontrib-wavedrom) (1.0.2)
Collecting cairocffi (from cairosvg>=2; python_version >= "3.3"->sphinxcontrib-wavedrom)
  Using cached https://files.pythonhosted.org/packages/f7/99/b3a2c6393563ccbe081ffcceb359ec27a6227792c5169604c1bd8128031a/cairocffi-1.1.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\smcro\AppData\Local\Temp\pip-install-7h7b4601\cairocffi\setup.py", line 13, in <module>
        'cairocffi/ffi_build.py:ffi_pixbuf']
      File "c:\python37\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "c:\python37\lib\distutils\core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "c:\python37\lib\site-packages\setuptools\dist.py", line 447, in __init__
        k: v for k, v in attrs.items()
      File "c:\python37\lib\distutils\dist.py", line 292, in __init__
        self.finalize_options()
      File "c:\python37\lib\site-packages\setuptools\dist.py", line 739, in finalize_options
        ep.load()(self, ep.name, value)
      File "c:\python37\lib\site-packages\cffi\setuptools_ext.py", line 217, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "c:\python37\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "c:\python37\lib\site-packages\cffi\setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "cairocffi/ffi_build.py", line 32, in <module>
        from xcffib.ffi_build import ffi as xcb_ffi
      File "c:\python37\lib\site-packages\xcffib\__init__.py", line 38, in <module>
        lib = ffi.dlopen(soname)
    OSError: cannot load library 'libxcb.dll': error 0x7e

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\smcro\AppData\Local\Temp\pip-install-7h7b4601\cairocffi\
You are using pip version 19.0.3, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
[6:20:07 pm] ~/Documents/Code/doctest>

Wavedrom seems to have additional requirements that are not mentioned here, and their installation method is not documented.

Feature request - support .yaml files as well as .json files for input

It would be simple to support both. Would such a PR be considered?

yaml and json are equivalent, but I find yaml can be easier on the eye:

{ "signal": [
        { "name": "clk",  "wave": "P......" },
        { "name": "bus",  "wave": "x.==.=x", "data": ["head", "body", "tail", "data"] },
        { "name": "wire", "wave": "0.1..0." }
]}

vs

signal:
  - name: clk
    wave: P......
  - name: bus
    wave: x.==.=x
    data:
      - head
      - body
      - tail
      - data
  - name: wire
    wave: 0.1..0.

Python3.10 issue: ImportError: cannot import name 'Mapping' from 'collections'

When trying to use sphinxcontrib-wavedrom with Python3.10 I get the following traceback:

Python 3.10.0 (default, Nov 10 2021, 13:56:10) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sphinxcontrib.wavedrom
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.10/site-packages/sphinxcontrib/wavedrom.py", line 15, in <module>
    from .wavedrom_render_image import render_wavedrom_image
  File ".../python3.10/site-packages/sphinxcontrib/wavedrom_render_image.py", line 7, in <module>
    from wavedrom import render
  File ".../python3.10/site-packages/wavedrom/__init__.py", line 29, in <module>
    from .waveform import WaveDrom
  File ".../python3.10/site-packages/wavedrom/waveform.py", line 33, in <module>
    from attrdict import AttrDict
  File ".../python3.10/site-packages/attrdict/__init__.py", line 5, in <module>
    from attrdict.mapping import AttrMap
  File ".../python3.10/site-packages/attrdict/mapping.py", line 4, in <module>
    from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (.../python3.10/collections/__init__.py)

This seems to be related to the attrdict requirement, which was archived by the owner and therefore unlikely to be updated for Python3.10.

Plugin does not work in combination with hieroglyph

I wanted to use the wavedrom plugin in a slideshow hieroglyph project (https://github.com/nyergler/hieroglyph)

I get the error

Exception occurred:
  File "/usr/local/lib/python3.6/dist-packages/sphinx/writers/html.py", line 833, in unknown_visit
    raise NotImplementedError('Unknown node: ' + node.__class__.__name__)
NotImplementedError: Unknown node: wavedromnode

Not sure whether it is an issue at wavedrom side, or at hieroglyph side. Feel free to move the issue.

Projects with sphinxcontrib.wavedrom extension fail to build on Mac with M2 chip

Hi,

I have changed to a Mac with M2 silicon and started to have problems building some documentation.

In particular, when building documentation for a project that includes sphinxcontrib.wavedrom, the build process fails with the following error:

en/esp32: Exception occurred:
en/esp32:   File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cffi/api.py", line 827, in _load_backend_lib
en/esp32:     raise OSError(msg)
en/esp32: OSError: cannot load library 'libxcb.dylib': dlopen(libxcb.dylib, 0x0002): tried: 'libxcb.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibxcb.dylib' (no such file), '/usr/lib/libxcb.dylib' (no such file, not in dyld cache), 'libxcb.dylib' (no such file), '/usr/lib/libxcb.dylib' (no such file, not in dyld cache).  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libxcb.dylib'
en/esp32: The full traceback has been saved in /var/folders/yp/p7hd77l93n58x0q7g3bvhnmc0000gp/T/sphinx-err-8e6xl5cc.log, if you want to report the issue to the developers.

This problem does not occur for earlier hw versions of Mac including M1 and Intel silicon.
After removing the extension from conf.py the project builds correctly.

Do you see similar issues? Is there anything I can do to make my project build on Mac M2?

No tag with id="pmx" found

Building pdf document from rst file with wavedrom diagram give error with specific wave.

Error:

Exception occurred:
  File "/usr/local/lib/python3.5/dist-packages/cairosvg/parser.py", line 414, in __init__
    'No tag with id="{}" found.'.format(element_id))
TypeError: No tag with id="pmx" found.

Wave example:

{ "signal": [
        { "name": "nibble", "wave": "xpx" }
]}

Build script:

sphinx-build -b latex -E -D wavedrom_html_jsinline=0 source/

As I understood that exception occurred only when you put "x" after "p" in wave (any amount of "." maybe added between "x" and "p" -- exception still there)

Can you adjust the scale of live-rendered waveforms?

I would prefer to live-render waveforms with inline javascript. But in some cases, the waveform is slightly wider than the page width. In those cases, I would prefer to scale down the image slightly, rather than use a scroll bar. I can accomplish this by switching to images, but it looks like images are generated using the wavedrompy library, which is out of date. I get very different results when rendering as an image.

Is it possible to scale the rendered javascript? It looks like the image options have no effect when inline javascript is enabled. If this isn't possible right now, is that a feature that could be implemented?

Graph is not drawing without name

If "name" field in wavedrom json file is empty that line of graph will not shown in pdf file.

In next example first line will not shown. But if add anything as a name it will start drawing correctly.

{ "signal": [
        { "name": "",  "wave": "x3...4.....|5...x", "data": ["16bit", "Nbit", "16bit"]},
        { "name": "b",  "wave": "x3...4.....|5...x", "data": ["header", "payload", "crc"]},
]}

Screenshot_20190522_190254

Add support for the wavedrom CLI

As mentioned in #22, it would be nice to have full control over the rendered image, as if it were inserted with an image directive. Unfortunately, this is not possible with wavedrom's current implementation of live-rendering. wavedrompy is a workaround, but it has become out of date. Instead, we can provide support for the wavedrom CLI. We can use it to generate images locally and insert them as we do with images from wavedrompy.

My plan is to make this completely opt-in. Users will need to install the wavedrom CLI themselves and make sure it is available on the PATH. I will add another configuration option to enable the CLI instead of the existing wavedrompy.

I already have a working prototype of this that I created for my own use. I need to clean it up, add some error checking and add the configuration variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.