Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use yowasp_yosys instead of system-installed yosys #50

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ Required
.. |yosys| replace:: ``yosys``
.. _yosys: https://github.com/YosysHQ/yosys

By default, `verilog-diagram` uses the `yowasp-yosys` package provided in PyPI. It can be installed by running `pip install -r requirements.txt`.
However, you could also use the `yosys` that is installed on your system, by adding the following line in `setup(app)` inside conf.py.

.. code-block:: py

def setup(app):
...
VerilogDiagram.use_yowasp = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the global settings for the extension should be based on variables added to sphinxconf.py file.
See: https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_config_value

...


Optional
~~~~~~~~

Expand Down
5 changes: 5 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#
import os
import sys
from sphinxcontrib_verilog_diagrams import VerilogDiagram
sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -251,3 +252,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

def setup(app):
# VerilogDiagram.use_yowasp = False
pass
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
- pip
- python=3.7
- sphinx
- yosys
- pip: # Packages installed from PyPI
- -r file:requirements.txt
- -r file:docs/requirements.txt
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ setuptools
docutils
sphinx

yowasp-yosys>=0.9.post4547.dev9

# Needed to upload to PyPi
twine
21 changes: 17 additions & 4 deletions sphinxcontrib_verilog_diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class VerilogDiagram(Directive):

final_argument_whitespace = False

use_yowasp = True

option_spec = {
'type': str,
'module': str,
Expand Down Expand Up @@ -208,9 +210,14 @@ def run(self):


def run_yosys(src, cmd):
ycmd = "yosys -p '{cmd}' {src}".format(src=src, cmd=cmd)
print("Running yosys:", ycmd)
subprocess.check_output(ycmd, shell=True)
print("Running yosys: yosys -q -p", "'{}'".format(cmd), src)
if VerilogDiagram.use_yowasp:
import yowasp_yosys
ycmd = ["-q", "-p", "{}".format(cmd), src]
yowasp_yosys.run_yosys(ycmd)
else:
ycmd = "yosys -p '{cmd}' {src}".format(src=src, cmd=cmd)
subprocess.check_output(ycmd, shell=True)


def diagram_yosys(ipath, opath, module='top', flatten=False):
Expand All @@ -232,6 +239,12 @@ def diagram_yosys(ipath, opath, module='top', flatten=False):
""".format(top=module, flatten=flatten, fmt=oext, oprefix=oprefix).strip(),
)

if VerilogDiagram.use_yowasp:
# somehow yowasp_yosys fails to execute `dot` to convert the dot file to svg,
# which works on native yosys, perhaps a limitation with wasm
svgdata = subprocess.check_output(["dot", "-Tsvg", "{}.dot".format(oprefix)])
open("{}.svg".format(oprefix), "wb").write(svgdata)

assert path.exists(opath), 'Output file {} was not created!'.format(oopath)
print('Output file created: {}'.format(opath))

Expand Down Expand Up @@ -268,7 +281,7 @@ def diagram_netlistsvg(ipath, opath, module='top', flatten=False):
run_yosys(
src=ipath,
cmd = """\
prep -top {top} {flatten}; cd {top}; write_json {ojson}
prep -top {top} {flatten}; cd {top}; write_json -compat-int {ojson}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compatibility mode seems to work incorectly when added to the standard conda Yosys version.

""".format(top=module, flatten=flatten, ojson=ojson).strip())
assert path.exists(ojson), 'Output file {} was not created!'.format(ojson)

Expand Down