Repository: wireviz/WireViz

Issue #200: [bug] Path to image error when running with -o pointing to a relative folder
Created: 2020-11-27T18:47:17Z
Observed behavior
When parsing the following example.yml file:
connectors:
    X1:
        type: my_connector
        pinlabels: [GND, VCC]
        show_pincount: false
        image: 
            src: my_connector.png
            width: 100

with -o option pointing to a relative path (containing a slash character), like here:
wireviz -o out/example example.yml

an error occurs with the following trace message:
aspect_ratio(): FileNotFoundError: [Errno 2] No such file or directory: '[my project folder here]/out/my_connector.png'
Warning: No such file or directory while opening my_connector.png
Error: No or improper image file="my_connector.png"
in label of node X1
Traceback (most recent call last):
  File "/usr/local/bin/wireviz", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/wireviz/wireviz.py", line 254, in main
    parse(yaml_input, file_out=file_out)
  File "/usr/local/lib/python3.6/dist-packages/wireviz/wireviz.py", line 183, in parse
    harness.output(filename=file_out, fmt=('png', 'svg'), view=False)
  File "/usr/local/lib/python3.6/dist-packages/wireviz/Harness.py", line 290, in output
    graph.render(filename=filename, view=view, cleanup=cleanup)
  File "/usr/local/lib/python3.6/dist-packages/graphviz/files.py", line 209, in render
    quiet=quiet)
  File "/usr/local/lib/python3.6/dist-packages/graphviz/backend.py", line 221, in render
    run(cmd, capture_output=True, cwd=cwd, check=True, quiet=quiet)
  File "/usr/local/lib/python3.6/dist-packages/graphviz/backend.py", line 184, in run
    output=out, stderr=err)
graphviz.backend.CalledProcessError: Command '['dot', '-Tpng', '-O', 'example']' returned non-zero exit status 1. [stderr: b'Warning: No such file or directory while opening my_connector.png\nError: No or improper image file="my_connector.png"\nin label of node X1\n']

Platform

Ubuntu 18.04
python 3.6.9
dependances installed with pip3

Affects

stable 0.2 version
master and dev branch as of 27 Nov 2020

Workaround
It still works correctly when simply changing the target name (no folders) or not using the -o option at all.
wireviz -o my_output example.yml

This is particularly inconvenient when using WireViz in Makefile with separate source and build folders. The only solution I see now is to copy the source first to the build folder and then run wireviz or build in source folder and move the artefacts.

Duplicate issue #284: [bug] Image src path is relative to output location
Created: 2022-06-29T20:11:12Z
wireviz version 0.3.2
python version 3.9.13
I discovered that the image path placed in the YAML file, e.g.
image:
  src: resources/connector.png
is relative to the output directory because of this line:https://github.com/formatc1702/WireViz/blob/b0d0070f08247e132b11bf45e617da9e8e1881f1/src/wireviz/wireviz.py#L62
As you can see the fileout variable that is created based on the output argument is used to prepend to the image src parameter. This means if you provide an output location the image path in the YAML file needs to point to the image as if it is in the output directory.
I believe this is a bug and the fix is to instead pass the filein variable to create the context for finding the image since it makes logical sense that you will put the path to an image relative to where the YAML file lives.
For context I have a repo containing multiple subdirectories all with various YAML files and a single output/ directory that mirrors the source directory hierarchy but only contains the files generated by wireviz. To use the images I would have to add a relative path to the yaml file that would make no sense from a human-readable standpoint.
.
├── README.md
├── connector_pinout_images
│   └── scsi68_pinout.png
├── generate.sh
├── mhr
│   ├── acropack_bob
│   │   ├── acropack_in.yaml -> ../tx_asb_v1/acropack_in.yaml
│   │   └── hd15_txch01.yaml -> ../tgen_v1/hd15_txch01.yaml
│   ├── if_agc
│   │   ├── j10.yaml
│   │   ├── j11.yaml
│   │   └── j12.yaml
│   ├── tgen_v1
│   │   ├── hd15_rxch01.yaml
│   │   ├── hd15_txch01.yaml
│   │   ├── scsi_gpio.yaml
│   │   └── scsi_timing.yaml
│   └── tx_asb_v1
│       └── acropack_in.yaml
├── output
│   └── mhr
│       ├── acropack_bob
│       │   ├── acropack_in.bom.tsv
│       │   ├── acropack_in.gv
│       │   ├── acropack_in.html
│       │   ├── acropack_in.png
│       │   ├── acropack_in.svg
│       │   ├── hd15_txch01.bom.tsv
│       │   ├── hd15_txch01.gv
│       │   ├── hd15_txch01.html
│       │   ├── hd15_txch01.png
│       │   └── hd15_txch01.svg
│       ├── if_agc
│       │   ├── j10.bom.tsv
│       │   ├── j10.gv
│       │   ├── j10.html
│       │   ├── j10.png
│       │   ├── j10.svg
│       │   ├── j11.bom.tsv
│       │   ├── j11.gv
│       │   ├── j11.html
│       │   ├── j11.png
│       │   ├── j11.svg
│       │   ├── j12.bom.tsv
│       │   ├── j12.gv
│       │   ├── j12.html
│       │   ├── j12.png
│       │   └── j12.svg
│       ├── tgen_v1
│       │   ├── hd15_rxch01.bom.tsv
│       │   ├── hd15_rxch01.gv
│       │   ├── hd15_rxch01.html
│       │   ├── hd15_rxch01.png
│       │   ├── hd15_rxch01.svg
│       │   ├── hd15_txch01.bom.tsv
│       │   ├── hd15_txch01.gv
│       │   ├── hd15_txch01.html
│       │   ├── hd15_txch01.png
│       │   ├── hd15_txch01.svg
│       │   ├── scsi_gpio.bom.tsv
│       │   ├── scsi_gpio.gv
│       │   ├── scsi_gpio.html
│       │   ├── scsi_gpio.png
│       │   ├── scsi_gpio.svg
│       │   ├── scsi_timing.bom.tsv
│       │   ├── scsi_timing.gv
│       │   ├── scsi_timing.html
│       │   ├── scsi_timing.png
│       │   └── scsi_timing.svg
│       └── tx_asb_v1
│           ├── acropack_in.bom.tsv
│           ├── acropack_in.gv
│           ├── acropack_in.html
│           ├── acropack_in.png
│           └── acropack_in.svg
└── requirements.txt

Closing comment (2022-07-02T22:16:01Z): Thank you for the detailed bug report. It seems to be very similar to #200. Take a look at the suggestion for that issue.