LukeCarrier / mkdocs-drawio-exporter

Exports your Draw.io diagrams at build time for easier embedding into your documentation
https://pypi.org/project/mkdocs-drawio-exporter/
MIT License
81 stars 9 forks source link

Fix handling of missing draw.io binary on PATH #3

Closed LukeCarrier closed 4 years ago

LukeCarrier commented 5 years ago

This isn't a great look -- we need to handle the case that drawio_executable is None:

ERROR   -  Subprocess raised exception 
Traceback (most recent call last):
  File "/Users/lukecarrier/Code/AVADO/Infrastructure/Alp/Docs/venv/lib/python3.7/site-packages/mkdocsdrawioexporter/mkdocsdrawioexporter.py", line 83, in on_post_build
    exit_status = subprocess.call(cmd)
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 323, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1436, in _execute_child
    executable = os.fsencode(executable)
  File "/usr/local/bin/../Cellar/python/3.7.4_1/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 809, in fsencode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType
Aminechakr commented 4 years ago

Hello, Any updates on this issue ? facing same issue :

+ xvfb-run -a mkdocs build
ERROR   -  Unable to find Draw.io executable; ensure it's on PATH or set drawio_executable option 
INFO    -  Cleaning site directory 
INFO    -  Building documentation to directory: /tmp/workspace/
INFO    -  The following pages exist in the docs directory, but are not included in the "nav" configuration:
  - index.md
WARNING -  Skipping export of "/tmp/workspace/xxxxxxxxxxxxx/xxx-docs/workspace/xxxxxxxxxxxxx/xxx-docs/src/drawio/jvm_monitoring.drawio" as Draw.io executable not available 
LukeCarrier commented 4 years ago

@Aminechakr the issue is fixed, you're not seeing a traceback. Is the Draw.io binary on your path?

$ which drawio

If not, have you installed the desktop app?

Aminechakr commented 4 years ago

Hello @LukeCarrier, Thank you for your quick feedback, yes we using the drawio desktop app to develop our diagrams and architectures in local. But it seems im facing another issue, we using a markdown documentation, that is running under a docker container. and we wan't to display our drawio diagrams (.drawio) under mkdocs instead of images (.png),

I think i need to add my drawio_executable on my alpine image any references. Thanks.

LukeCarrier commented 4 years ago

Hey @Aminechakr, yup, you'll need to install Draw.io in your Dockerfile. It'll make for a fairly large container. I've started the work to do the exports without the Electron app in #16, so you may want to subscribe to that for updates.

Something like this should work:

Dockerfile ```dockerfile ARG python_version FROM python:${python_version}-slim ARG drawio_version ARG drawio_sha256sum ARG drawio_arch=amd64 EXPOSE 8000 WORKDIR /mkdocs ENTRYPOINT ["xvfb-run", "mkdocs"] CMD ["build"] ADD https://github.com/jgraph/drawio-desktop/releases/download/v${drawio_version}/draw.io-${drawio_arch}-${drawio_version}.deb . RUN apt-get update \ && echo "${drawio_sha256sum} draw.io-${drawio_arch}-${drawio_version}.deb" | sha256sum --check \ && apt-get install -y libasound2 xvfb ./draw.io-${drawio_arch}-${drawio_version}.deb \ && rm -rf draw.io-${drawio_arch}-${drawio_version}.deb /var/lib/apt/lists COPY requirements.txt . RUN pip install --upgrade pip \ && pip install -r requirements.txt \ && rm -f requirements.txt ```
requirements.txt ```requirements click==7.1.1 future==0.18.2 Jinja2==2.11.2 joblib==0.14.1 livereload==2.6.1 lunr==0.5.6 Markdown==3.2.1 MarkupSafe==1.1.1 mkdocs==1.1 mkdocs-drawio-exporter==0.6.1 mkdocs-theme-bootstrap4==0.4.0 nltk==3.5 PyYAML==5.3.1 regex==2020.4.4 six==1.14.0 tornado==6.0.4 tqdm==4.45.0 ```
Aminechakr commented 4 years ago

Thanks @LukeCarrier was really helpful.

It's seems that i end up on an electron issue once i tried to export my Draw.io diagrams on MKdocs 😅 :

Error: Failed to get 'appData' path at App.l._setDefaultAppPaths (electron/js2c/browser_init.js:5:1420) at Object.<anonymous> (electron/js2c/browser_init.js:205:2348) at Object../lib/browser/init.ts (electron/js2c/browser_init.js:205:3577) at __webpack_require__ (electron/js2c/browser_init.js:1:128) at electron/js2c/browser_init.js:1:1200 at electron/js2c/browser_init.js:1:1267

Is this related to #16 ? is there any workarround ?

LukeCarrier commented 4 years ago

@Aminechakr can you try setting the XDG_CONFIG_HOME environment variable in your Dockerfile? If you're not running as a specific user root should do.

The relevant Electron docs: https://github.com/electron/electron/blob/master/docs/api/app.md#appgetpathname

Aminechakr commented 4 years ago

@LukeCarrier Yes ! It's working when setting XDG_CONFIG_HOME on my dockerfile

ENV XDG_CONFIG_HOME=~/.config

And since i am running my MkDocs as a non-privileged user, i had to make some changes for the security context.

DEBUG   -  Exporting "/tmp/workspace/docs/workspace/src/drawio/my_diagrma.drawio" to "/tmp/workspace/docs/workspace/src/drawio-exporter/1e5c3fdc662620e797c25120515c25ffb865fd-0"
DEBUG   -  Using export command ['/usr/bin/drawio', '--export', '/tmp/workspace/docs/workspace/src/drawio/my_diagrma.drawio', '--page-index', '0', '--output', '/tmp/workspace/docs/workspace/src/drawio-exporter/1e5c3fdc662620e797c25120515c25ffb865fd-0', '--format', 'svg', '--no-sandbox'] 
/tmp/workspace/docs/workspace/src/drawio/my_diagrma.drawio -> /tmp/workspace/docs/workspace/src/drawio-exporter/1e5c3fdc662620e797c25120515c25ffb865fd-0
INFO    -  Documentation built in 1.92 seconds 

Big thanks for the support.

👏 🎉

LukeCarrier commented 4 years ago

@Aminechakr awesome -- thanks for reporting back! 👍