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
77 stars 8 forks source link

Not able to find draw.io.exe #18

Closed tpchris1 closed 3 years ago

tpchris1 commented 3 years ago

I just installed with the latest version on pip And I have installed the latest desktop version of draw.io(diagrams.net) and also tried the no-install version. However, when I configured the path in both ways, they just didn't work and kept telling me:

Message: 'Configured Draw.io executable "{}" doesn\'t exist'
Arguments: ('D:\\Program_Files\\draw.io',)

Although, I do have my mkdocs.yml as below:

plugins:
    - search
    - mermaid2
    - drawio-exporter:
        drawio_executable: 'D:\Program_Files\draw.io\draw.io.exe'

And the full path of the error messages are as follow:

--- Logging error ---
Traceback (most recent call last):
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 1034, in emit
    msg = self.format(record)
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 880, in format
    return fmt.format(record)
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 619, in format
    record.message = record.getMessage()
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "d:\program_files\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\program_files\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Program_Files\Anaconda3\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
    sys.exit(cli())
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\__main__.py", line 136, in serve_command
    **kwargs
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 146, in serve
    _livereload(host, port, config, builder, site_dir)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 78, in _livereload
    server.serve(root=site_dir, host=host, port=port, restart_delay=0)
  File "d:\program_files\anaconda3\lib\site-packages\livereload\server.py", line 356, in serve
    IOLoop.instance().start()
  File "d:\program_files\anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "d:\program_files\anaconda3\lib\asyncio\base_events.py", line 539, in run_forever
    self._run_once()
  File "d:\program_files\anaconda3\lib\asyncio\base_events.py", line 1775, in _run_once
    handle._run()
  File "d:\program_files\anaconda3\lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "d:\program_files\anaconda3\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "d:\program_files\anaconda3\lib\site-packages\tornado\ioloop.py", line 907, in _run
    return self.callback()
  File "d:\program_files\anaconda3\lib\site-packages\livereload\handlers.py", line 69, in poll_tasks
    filepath, delay = cls.watcher.examine()
  File "d:\program_files\anaconda3\lib\site-packages\livereload\watcher.py", line 119, in examine
    func()
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 136, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\build.py", line 236, in build
    config = config['plugins'].run_event('config', config)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocsdrawioexporter\plugin.py", line 45, in on_config
    self.exporter.drawio_executable_paths(sys.platform))
  File "d:\program_files\anaconda3\lib\site-packages\mkdocsdrawioexporter\exporter.py", line 135, in prepare_drawio_executable   
    self.log.error('Configured Draw.io executable "{}" doesn\'t exist', executable)
Message: 'Configured Draw.io executable "{}" doesn\'t exist'
Arguments: ('D:\\Program_Files\\draw.io',)
LukeCarrier commented 3 years ago

@tpchris1 I see you're using Anaconda -- can I ask how you installed it, and which version? I'll try to reproduce this as I'm not quite sure from the above.

tpchris1 commented 3 years ago

OS: Win10

Environment: using VS code with anaconda prompt in the terminal of VS code

Anaconda version: 4.7.12

python package version: mkdocs 1.1.2 mkdocs-drawio-exporter 0.6.1 mkdocs-material 5.5.13 mkdocs-material-extensions 1.0.1 mkdocs-mermaid2-plugin 0.4.2

I hope nothing is missed here ; ) Thank you!

LukeCarrier commented 3 years ago

Hey @tpchris1, I tried this out locally and I was able to export diagrams without the drawio_executable option set, as the plugin correctly determined the location:

> mkdocs build -v
[snip]
DEBUG   -  Trying paths ['C:\\Program Files\\draw.io\\draw.io.exe', 'ProgramFiles(x86)\\draw.io\\draw.io.exe'] for platform "win32"
DEBUG   -  Found Draw.io executable for platform "win32" at "C:\Program Files\draw.io\draw.io.exe"
DEBUG   -  Using Draw.io executable "C:\Program Files\draw.io\draw.io.exe", cache directory "\\Mac\Home\Code\avado\sre\docs-anaconda\docs\drawio-exporter" and image regular expression "(<img[^>]+src=")([^">]+)("\s*\/?>)
[snip]

Can you try again without that option set, and if it doesn't work please paste the log of mkdocs build -v?

tpchris1 commented 3 years ago

According to the Debug info, I am assuming that only installed in the default file path as in "C:\Program Files\draw.io\draw.io.exe" is required. However, I installed it in my custom path and it seemed that the package cannot read my passed arguments as following.

plugins:
    - search
    - mermaid2
    - drawio-exporter:
        drawio_executable: 'D:\Program_Files\draw.io\draw.io.exe'

However, I did manage to solve it by installing it in the default path 'C:\\Program Files\\draw.io\\draw.io.exe' and remove the drawio_executable argument.

Is it possible for you to recreate at the drawio_executable part? Or maybe I was doing the wrong way to pass the argument?

Debug info:

DEBUG   -  Config value: 'plugins' = PluginCollection([('search', <mkdocs.contrib.search.SearchPlugin object at 0x000002086BF44438>), ('drawio-exporter', <mkdocsdrawioexporter.plugin.DrawIoExporterPlugin object at 0x000002086F594CC0>)])
DEBUG   -  Trying paths ['C:\\Program Files\\draw.io\\draw.io.exe', 'ProgramFiles(x86)\\draw.io\\draw.io.exe'] for platform "win32"
ERROR   -  Unable to find Draw.io executable; ensure it's on PATH or set drawio_executable option 
DEBUG   -  Using Draw.io executable "None", arguments [], cache directory "D:\tpchris1\programming\ATE\sync\Focus_Docs\docs\drawio-exporter" and image regular expression "(<img[^>]+src=")([^">]+)("\s*\/?>)"
LukeCarrier commented 3 years ago

Could you confirm the location you'd installed Draw.io to for me, was it D:\Program_Files\draw.io\draw.io.exe?

If so, it might be that Python is treating the backslashes in the path as escape sequences -- try using double backslashes? D:\\Program_Files\\draw.io\\draw.io.exe may work.

tpchris1 commented 3 years ago

Yeah, I can confirm. I tried the double back slashes and also the single/double quotation marks. Besides, I also put the install path in the SYSTEM_PATH of Windows 10 However, none of the above worked in my previous trys.

LukeCarrier commented 3 years ago

Wow, looks like there's a corker of a bug there. I think we check that the specified executable is executable and then don't actually use it. I'll fix this and push a release either today (it's nearly 9pm here!) or tomorrow; thanks for your patience @tpchris1.

LukeCarrier commented 3 years ago

@tpchris1 could you give this build a shot? If it works I'll do an 0.7 release. You'll need to unzip this and install the Python wheel inside:

mkdocs-drawio-exporter-issue-18.zip

You should need to do something like the following, inside of your venv if you're using one:

pip uninstall mkdocs-drawio-exporter
pip install mkdocs_drawio_exporter-0.6.1-py3-none-any.whl
tpchris1 commented 3 years ago

Sure! Glad to help a bit. Really like your work here! But I am afraid I won't be able to give it a test until next Monday. I will test it by then and tell you the result! Thank you!

tpchris1 commented 3 years ago

I have tried the issue 18 version and confirmed that it works ! Thanks for the quick fix !

The following are the current log of mkdocs build -V

DEBUG   -  Config value: 'plugins' = PluginCollection([('search', <mkdocs.contrib.search.SearchPlugin object at 0x0000017010674C18>), ('drawio-exporter', <mkdocsdrawioexporter.plugin.DrawIoExporterPlugin object at 0x0000017013CC11D0>), ('mermaid2', <mermaid2.plugin.MarkdownMermaidPlugin object at 0x00000170145064A8>)])
DEBUG   -  Using Draw.io executable "D:\Program_Files\draw.io\draw.io.exe", arguments [], cache directory "D:\tpchris1\programming\ATE\sync\Focus_Docs\docs\drawio-exporter" and image regular expression "(<img[^>]+src=")([^">]+)("\s*\/?>)"
LukeCarrier commented 3 years ago

Neat, cheers @tpchris1. Release 0.7.0 will be out momentarily, so you should be good to go once you're upgraded 👍