bavovanachte / sphinx-wavedrom

A sphinx extension that allows including wavedrom diagrams by using its text-based representation
MIT License
32 stars 18 forks source link

Relative paths for wavedrom-cli #45

Open bradleyharden opened 2 years ago

bradleyharden commented 2 years ago

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.

bavovanachte commented 2 years ago

Hi!

I don't normally install Node or NPM on my machines.

I don't think you're the only one, so I think it's worth supporting it somehow. I'd be hesitant to just flip the switch on this entirely, but I think we can add an option for it.

Is your approach similar to this one? https://github.com/mvonbun/docker-wavedrom-cli. I'm asking cause I'd like to reproduce the issue and add a link in the readme, as this will likely help others as well.

bradleyharden commented 2 years ago

@bavovanachte, sorry for the delay.

I think my approach is a bit simpler than the one you linked, but I'm not terribly familiar with the NPM ecosystem, so I don't know how they compare.

Here is my Dockerfile:

FROM docker.io/library/node:12.0

RUN npm -g config set user root \
 && npm i wavedrom-cli -g

ENTRYPOINT ["wavedrom-cli"]

And here is my wrapper script:

#!/bin/bash

args=("$@")
for i in "${!args[@]}"; do
  if [[ "${args[$i]}" = /* ]]; then
    args[$i]=$(realpath --relative-to="$PWD" "${args[$i]}")
  fi
done
podman run --rm -v "$PWD":/wavedrom -w /wavedrom localhost/wavedrom-cli ${args[@]}