pawamoy / mkdocs-coverage

MkDocs plugin to integrate your coverage HTML report into your site.
https://pawamoy.github.io/mkdocs-coverage
ISC License
24 stars 1 forks source link

Build fails when using use_directory_urls: false #5

Closed dtomlinson91 closed 2 years ago

dtomlinson91 commented 3 years ago

Describe the bug When using use_directory_urls: false in mkdocs.yml the build fails with the following error:

INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /Users/dtomlinson/git-repos/projects/tembo/site
Traceback (most recent call last):
  File "/Users/dtomlinson/.pyenv/versions/3.8.11/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 791, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/dtomlinson/git-repos/projects/tembo/site/coverage/index.html' -> '/Users/dtomlinson/git-repos/projects/tembo/site/coverage/tmp.html'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 187, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 317, in build
    config['plugins'].run_event('post_build', config=config)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 104, in run_event
    result = method(**kwargs)
  File "/Users/dtomlinson/git-repos/projects/tembo/.venv/lib/python3.8/site-packages/mkdocs_coverage/plugin.py", line 101, in on_post_build
    shutil.move(site_coverage_dir / "index.html", site_coverage_dir / "tmp.html")
  File "/Users/dtomlinson/.pyenv/versions/3.8.11/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 811, in move
    copy_function(src, real_dst)
  File "/Users/dtomlinson/.pyenv/versions/3.8.11/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 435, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/Users/dtomlinson/.pyenv/versions/3.8.11/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/dtomlinson/git-repos/projects/tembo/site/coverage/index.html'

To Reproduce Steps to reproduce the behavior:

  1. Set use_directory_urls: false in the mkdocs.yml
  2. Run mkdocs build
  3. See error above

Expected behavior The error is complaining that ~/git-repos/projects/tembo/site/coverage/index.html does not exist.

coverage.html is copied to the site directory.

When use_directory_urls: false is set I would expect coverage.html to be coverage/index.html to allow an offline build.

Screenshots N/A

System (please complete the following information):

Additional context I have no idea how mkdocs works internally, is it possible to for a plugin to get the context from the user's .yml?

If so a check for use_directory_urls: false should move the file to coverage/index.html rather than coverage.html.

Thanks 🙂

pawamoy commented 2 years ago

Fixed in e427be0, I'll release as soon as PyPI is up again :slightly_smiling_face: