Git Product home page Git Product logo

sphinxcontrib-drawio's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinxcontrib-drawio's Issues

"Test" Sphinx Project

Included in the CI tests should be a sphinx project which gets built.
This will test that this package actually works.

Could probably integrate a test for #1 .

:format: pdf does not create anything !

Describe the bug

{drawio-image} drawio/test.drawio
:format: pdf

Does not output any file. All other formats are producing files.

To Reproduce

{drawio-image} drawio/test.drawio
:format: pdf

then make html

Expected behaviour
According to documentation, a pdf file should be created.

Setup Information

  • OS: Ubuntu 22.04.3
  • Python: 3.10.12
  • Version: 0.0.16

Make sphinxcontrib-drawio depend on sphinx

As of version 0.0.14, I get:

$ python3 -m pip show sphinxcontrib-drawio
Name: sphinxcontrib-drawio
Version: 0.0.14
Summary: Sphinx Extension to include draw.io files
Home-page: https://github.com/Modelmat/sphinxcontrib-drawio
Author: Modelmat
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires:
Required-by:

But on our build server:

$ python3 -m pip install -r requirements.txt

Results in:

      ...
      File "<frozen importlib._bootstrap>", line 991, in _find_and_load
      File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 848, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/tmp/pip-install-iei10cwa/sphinxcontrib-drawio/sphinxcontrib/drawio/__init__.py", line 16, in <module>
        from sphinx.application import Sphinx
    ModuleNotFoundError: No module named 'sphinx'
    ----------------------------------------

Which is plausible, since pip is permitted to install packages in any order if they don't depend on each other. I guess this is just a missing dependency.

Thanks a lot.

Doesn't seem to convert in parallel

It doesn't seem the extension converts drawio files one at a time, even when Sphinx is run in parallel mode. I thought adding "parallel_write_safe": True might help, but that doesn't seem to have an effect. Any ideas on how to convert drawio files in a parallel manner? On Sphinx projects with a large count of drawio diagrams this can become quite the performance bottleneck.

Improve release versioning & pypi deploys

The current tagged commit system is slightly painful, as if the tags and commits aren't pushed at the same time it sometimes messed up and won't do a deploy.[1]

It would probably be beneficial to have a static version file containing the release version which gets used.

I'm not 100% sure on how we'd get the CI to automatically deploy to pypi [does it need to?] when it changes.

[1] I think, I haven't tested this extensively?
Does GitHub actions support this better?

Start a changelog

We should keep a changelog so that users can see which features/bugfixes a new release brings.

DrawIO fails to run on gitlab-ci docker container

Hi,

I have problems when running drawio within a gitlab-ci test setup. The following error occurs:

Running as root without --no-sandbox is not supported

The issue seems to be related to this issue one from the original drawio repository. A workaround seems to be to use '--no-sandbox --headless --disable-gpu'. These parameters are currently not used, right?

Or am I doing something wrong? This is the relevant snippet of my ci-file:

image: python:latest

build:
stage: build
script:

Fails with DrawIO Error: [WinError 5] Access is denied - because of whitespace in path

using ".. drawio-figure:: test.drawio" directive results in the following error (windows, whitespace in pathname)

DrawIO Error:
draw.io ("C:\Users\AB1234\OneDrive - ABC\repo\needs\docs\utils\draw.io-21.1.2-windows-no-installer.exe" --export --crop --page-index 0 --scale 1.0 --format png --output C
:\Users\AB1234\OneDrive - ABC\repo\needs\docs\build\html.doctrees\drawio\f7cee1ec9581edc5b575d34416e8fd53113b8808\test.png C:\Users\AB1234\OneDrive - ABC\repo
\needs\docs\source\snmp\test.drawio --enable-logging) exited with error:
[WinError 5] Access is denied

To Reproduce
whitespace in sphinx project name path

Setup Information

  • OS: Windows
  • Python: 3.10
  • Version: 0.0.16

Additional context
when i add quotes to export and input path in init.py in drawio_args like this
....
line 261
# str(export_abspath),
# str(input_abspath),
f'"{str(export_abspath)}"',
f'"{str(input_abspath)}"',

then it is working fine

Add azure pipeline file

This should be added and configured to test before it gets migrates to the main organization.

Xvfb Inifinite Loop

I recently ran into an issue where someone had permission issues with Xvfb and it couldn't start up. It seems this line caused an infinite loop in that case, but it was hard to tell what the issue was at first:

while fp.tell() == 0:
sleep(0.01) # wait for Xvfb to start up

I'm not quite sure the best approach, but do you think it would be a good idea to add a counter in the loop and output a "Xvfb is having difficulty starting" log message if it goes over a generous amount? I also don't know if it's possible (or a good idea) to kill the Sphinx process at the same time.

Getting random failures that have an empty stderr/stdout

Occasionally we get a random failure (random in that we can re-run the build and it won't fail the next time), but the [stderr] and [stdout] is empty making it tricky to troubleshoot.

DrawIO Error:
draw.io (/opt/drawio/drawio --export --crop --page-index 0 --scale 1.0 --transparent --format png --output /path/to/image.png /path/to/image.drawio --no-sandbox) exited with error:
[stderr]
b''
[stdout]
b''

It looks like that output comes from these lines of code, do you think the reason they are blank has something to do with the subprocess.run() arguments or subprocess.CalledProcessError? I'm mainly trying to figure out what might be a good place to troubleshoot to find if there is stderr/stdout that is getting lost somewhere.

(Sorry about opening all these issues recently, I love this extension!)

electron-specific arguments

os: archlinux
electron: 8.2.3
drawio: 13.0.1 (both aur/drawio-desktop and aur/drawio-desktop-bin packages)
python: 3.8.2
sphinx: 3.0.3
sphinxcontrib-drawio: 0.0.6

Аргументы командной строки drawio стал обрабатывать неожиданным образом.
Аргумент, предназначенный для electron, не изымается после обработки, а попадает в список неизвестных, становясь на место имени входного файла:
paths: ['--no-sandbox', 'my_file.drawio']
Это порождает Error: input file/directory not found при сборке документации.
Удаление '--no-sandbox' из drawio_args разрешило проблему.

CLI args began to be handled unexpectedly by drawio.
The argument that was intended for the electron is not removed after processing.
It shifts the input file name position, which generates a file search error.
I had to remove the '--no-sandbox' argument from drawio_args for a successful doc build.

Sphinx's caching causes trouble with multiple builders

Steps to reproduce:

  • Build a Sphinx project using the rinoh builder
  • (Sphinx caches the parsed input files in the doctrees directory)
  • Build the same Sphinx project using the html builder
  • (Sphinx will read the cached doctrees which reference the PDF images instead of the SVG images)

I think the proper way to handle this would be to subclass ImageConverter and handle conversion as a post-transform. The drawio exporting should be moved from DrawIOBase to this new class. sphinx.ext.imgconverter is an example of how ImageConverter can be subclassed.

A workaround is to use separate doctrees directories for each builder.

Clarification on Installation step

For step 3 in the Installation section "Add the binary to $PATH", can that be "Add the binary to $PATH or configure drawio_binary_path"? If so, I can make a PR to add that for clarity.

It is not valid to have a sphinxcontrib/__init__.py

sphinxcontrib is a namespace package shared by multiple distributions. I think you should not add an __init__.py in it. I believe this causes the import error on the tag 0.0.11 (released as 0.10.0).

See the section Native namespace packages:

It is extremely important that every distribution that uses the namespace package omits the init.py or uses a pkgutil-style init.py. If any distribution does not, it will cause the namespace logic to fail and the other sub-packages will not be importable.

figure properties set to Path instead of str

When using this extension together with the extension sphinx-imgconvert I get an error due to the fact that at the following lines:

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L160-L165

the candidates and uri properties of the node are set to a Path object created in the _drawio_export function.

I'm not an expert of the docutils/sphinx codebase but I think that Docutils is setting uri for figure nodes to a string here:

https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/directives/images.py#L29

and Sphinx is setting the default candidate to a str here:

https://github.com/sphinx-doc/sphinx/blob/1285e0cabed517d4bf24b00c5fd68804a26e8a91/sphinx/environment/collectors/asset.py#L83

It seems therefore that sphinx-imgconvert is correct in expecting a string and not a Path object.

I think the extension could be adapted by casting the Path object to a str in these two locations:

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L206

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L272

Move the .drawio directory to the build folder?

This would be a more logical location for the exported images. Some thoughts:

  • maybe you don't want it inside the output folder (e.g. build/html) because it makes sense to keep it when deleting the built documentation
  • perhaps the location can be made configurable (like the doctrees directory)?

More a question rather than a bug...

I've a drawio file in an "sphinx" md file.
`
```{drawio-figure} drawio/my_graph.drawio
:alt: My graph
:align: center

My graph
```
`

On default this graph is tranformed as a svg file.

I'd like to make it clickable to download this graph as a pdf.

How could I do that ?
I could call drawio by hand, store the pdf file by hand, .... Is there any "all-in-one" solution, so that sphinxcontrib-drawio creates both file at "once" ?

Thx for your support...

I didn't find any other way to ask my question (The Discussion tab is not available).

add support for "--layers"

Is your feature request related to a problem? Please describe.
I would like to export certain layers to an SVG.
draw.io supports layers, and draw.io CLI allows to specify the layers that shall be exported.

Describe the solution you'd like
sphinxcontrib-drawio should allow to specify the layers that shall be exported, and pass this to draw.io CLI.
It should be similar to --page-index but as a comma separated list.
If the parameter is not specified then it shall not be passed to draw.io in order to export all visible layers (default behavior).

Describe alternatives you've considered
At the moment I export the SVG manually from draw.io, with the desired layers manually made visible.
It does not work well if multiple exports with different layers of the same file are needed.

Additional context
Layer selection in CLI has been added in draw.io v20.6.0.

draw.io counts the layers from 0 where layer 0 is the one at the bottom of the list, usually the Background layer.

draw.io CLI:

-l, --layers <comma separated layer indexes>
selects which layers to export (applies to all pages), if not specified, all layers are selected

xvfb-run doesn't exist on windows

By default, drawio_headless is True. But that triggers errors on windows.

Autodetecting windows and setting drawio_headless to False removes one troubleshooting step for users on windows.

Automatically crop when exporting to PDF?

As far as I can tell, drawio crops the figure when exporting to formats other than PDF. It does offer the --crop command line option to also do this for PDF. Should we make use of it when exporting to PDF? I believe it makes sense to make this behavior consistent regardless of the output format (unlike drawio itself).

Embed text when exporting in svg file format

sphinxcontrib-drawio is an excellent tool, extremely handy when creating images etcetera for documentation. We use Sphinx since it allows us to create documents in different formats using the same source code (*.rst files).

Discovered a minor issue, when exporting images in svg format they look fine in documents exported as HTML whereas the very same images in documents exported as PDF will have a small text stating “Text is not SVG – cannot display”. When exporting images manually from draw.io in svg format and then using those when creating the PDF works fine.

We use simplepdf to create PDF files from .rst source files.

It is not clear to me what settings are used in sphinxcontrib-drawio when exporting in svg format but the only thing I can think of that might cause this is that images and text are not embedded when exporting? Would it be possible to add such a feature?

image

How it looks in the PDF file when using sphinxcontrib-drawio.

image

How it looks like in the PDF file when exporting images manually in draw.io and then include those images in the rst files.

image

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.