mikitex70 / plantuml-markdown

PlantUML plugin for Python-Markdown
BSD 2-Clause "Simplified" License
198 stars 55 forks source link

cannot source puml file when using mkdocs-multirepo-plugin #100

Closed davama closed 3 months ago

davama commented 4 months ago

Good day,

Not sure if this is the right place to put this but I am using mkdocs-multirepo-plugin along with this plugin and when I source a .puml file i get an error:

ERROR   -  Error reading page 'docker/test.md': [Errno 2] No such file or directory: './sources/test.puml'
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
✅ repos/docker/docker-redis (6.107 secs)
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/__main__.py", line 268, in serve_command
    serve.serve(**kwargs)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 85, in serve
    builder(config)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.render(config, files)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/structure/pages.py", line 285, in render
    self.content = md.convert(self.markdown)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/markdown/core.py", line 354, in convert
    self.lines = prep.run(self.lines)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/plantuml_markdown/plantuml_markdown.py", line 155, in run
    text1, idx1 = self._replace_block(text[idx:])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/plantuml_markdown/plantuml_markdown.py", line 212, in _replace_block
    with open(os.path.join(self._base_dir, source), 'r', encoding=self._encoding) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './sources/test.puml'

Here is my config:

markdown_extensions:
...
  - plantuml_markdown:
      server: https://puml.domain.net
      insecure: True
      cachedir: /tmp
      base_dir: .
      config:
      format: png
      classes: class1,class2
      encoding: utf-8
      title: UML diagram
      alt: UML diagram image
      image_maps: True
      priority: 30
      http_method: GET
      fallback_to_get: True
      theme: bluegray
      #server_include_whitelist: [r'^c4.*$']
      puml_notheme_cmdlist: [
                              'version',
                              'listfonts',
                              'stdlib',
                              'license'
                            ]
plugins:
...
  - multirepo:
      cleanup: false
      keep_docs_dir: true
      repos:
        - section: docker-redis
          import_url: 'https://git.domain.net/docker/docker-redis?branch=my_dev&keep_docs_dir=True'
          section_path: repos/docker

This is my test.md file inside the docker-redis repo.

test.md


# test

full path - source image

relative path - source image

normal markdown source image

images


> test.puml 

@startuml Bob -> Alice : hello @enduml


The `temp_dir` directory comes from the multirepo plugin

Here is how  the `test.md` file is rendered when i fix the `relative path` section.

![2024-07-29_14-32](https://github.com/user-attachments/assets/60231ce4-b2ca-40a8-a9e0-381c7c78ac78)

Wondering if there is a way to work around this.
Perhaps

base_dir:

Versions:

plantuml-markdown                         3.9.7
mkdocs-multirepo-plugin                   0.8.2
mkdocs                                    1.6.0

Any input is appreciated!

Best, Dave

mikitex70 commented 4 months ago

Hi @davama, thank you for the detailed report, I was able to reproduce your problem. Unfortunately, I have no way to trace the path to the current file (the plugin only gets a list of lines), so I cannot resolve relative paths. Give me some time, I'll see if I can implement your idea by expanding base_dir to support a list of paths.

davama commented 4 months ago

@mikitex70 Appreciate your quick response! Please let me know if you want me to test anything Best

mikitex70 commented 4 months ago

Hi @davama, I've pushed on develop branch an enhancement which allows to specify a list of paths in the base_dir configuration property. In your case it should be something like:

base_dir:
  - .
  - temp_dir/repos/docker/docker-redis/docs

Give it a try and let me known if there is something to fix.

davama commented 4 months ago

@mikitex70 Worked like a charm!

2024-08-01_10-16

Thank you!

davama commented 3 months ago

@mikitex70 Thank you for the new release

I believe there might be a bug.

This is what I get when I try the new version 3.10.1, when sourcing a puml file using the multirepo plugin.

2024-08-08_11-25

But this even broke the regular source=file.puml functionality when using the local docs repo. The output is the same as above.

Hope I made sense

Thank you

davama commented 3 months ago

sorry, there was an issue with my container. @mikitex70

all is well Thank you!

Closing