timvink / mkdocs-table-reader-plugin

MkDocs plugin that enables a markdown tag like {{ read_csv('table.csv') }} to directly insert various table formats into a page
https://timvink.github.io/mkdocs-table-reader-plugin/
MIT License
117 stars 20 forks source link

FileNotFoundError on mkdocs_path when using `--config-file mkdocs.yml` #16

Closed agjohnson closed 3 years ago

agjohnson commented 3 years ago

When calling mkdocs with a mkdocs.yml in the working dir, the plugin will try to effectively call with cd(''), throwing the attached stack trace.

Mkdocs, version is 1.1.2, and was called with:

python -m mkdocs build --clean --config-file mkdocs.yml --verbose

Calling mkdocs build with --config-file mkdocs.yml, this line returns mkdocs_dir = "", which will fail below at with cd(""):

https://github.com/timvink/mkdocs-table-reader-plugin/blob/master/mkdocs_table_reader_plugin/plugin.py#L99

Local resolution for me was:

mkdocs_dir = os.path.dirname(os.path.abspath(config["config_file_path"]))

I'm not very familiar with mkdocs or mkdocs plugin internals however.

Traceback (most recent call last):
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs/__main__.py", line 192, in <module>
    cli()
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs/__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs/commands/build.py", line 271, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs/commands/build.py", line 168, in _populate_page
    'page_markdown', page.markdown, page=page, config=config, files=files
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs_table_reader_plugin/plugin.py", line 127, in on_page_markdown
    with cd(mkdocs_dir):
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/site-packages/mkdocs_table_reader_plugin/plugin.py", line 50, in __enter__
    os.chdir(self.newPath)
FileNotFoundError: [Errno 2] No such file or directory: ''
timvink commented 3 years ago

Thanks for taking the effort to write up an issue and provide the fix! I just published v0.4.4.