Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with timvink/mkdocs-git-revision-date-localized-plugin #12

Closed
prcr opened this issue Apr 15, 2020 · 4 comments
Closed

Comments

@prcr
Copy link

prcr commented Apr 15, 2020

Hello,

I was trying to use the MkDocs plugin timvink/mkdocs-git-revision-date-localized-plugin in my project but it always fails with:

$ mkdocs build
INFO    -  Cleaning site directory 
INFO    -  Building documentation to directory: /home/prcr/Codacy/git/docs/site 
ERROR   -  Unable to read git logs of '/tmp/docs_kvh_ua8a/index.md'. To ignore this error, set option 'ignoring_missing_git: true'
ERROR   -  Error reading page 'index.md': Cmd('git') failed due to: exit code(128)
  cmdline: git log --date=short --format=%at -n 1 /tmp/docs_kvh_ua8a/index.md
  stderr: 'fatal: /tmp/docs_kvh_ua8a/index.md: '/tmp/docs_kvh_ua8a/index.md' is outside repository' 
[...]

I was able to pinpoint the issue to the fact that I'm using mkdocs-monorepo-plugin as well. It seems that the plugin copies the *.md files to a temporary directory before building them, and this way the other plugin cannot use git log to find out the last updated date of the Markdown files.

@timvink
Copy link
Contributor

timvink commented Apr 16, 2020

I see that mkdocs-monorepo-plugin copies the contents of multiple docs/ dirs into a temporary docs_/ directory at the MkDocs event on_config().

mkdocs-git-revision-date-localized-plugin uses the event on_page_markdown(), and then specifically the page.file.abs_src_path attribute of a page in order to run git log on the file location. If the file is copied to a temp folder the git info is lost, and the git log fails.

One possible solution might be to use symlinks to the temporary docs_/ folder instead of copying files. That way hopefully the abs_src_path remains intact. So replace:

https://github.com/spotify/mkdocs-monorepo-plugin/blob/3cf93fa0d433a35f3d850ffa13de2d00462e3f68/mkdocs_monorepo_plugin/merger.py#L59

with:

copytree(source_dir, dest_dir, symlinks=True)

I haven't tested this yet, but I am willing to give it a try and provide a PR?

Edit: Another possible solution could be to save during on_config() for each file the source location in a dictionary of the Plugin class. Then use on_pre_page() to "alter the Page instance", in effect replacing the abs_src_path attribute with the original source.

@bih
Copy link
Collaborator

bih commented Apr 17, 2020

@timvink That sounds like an interesting approach and definitely has pros compared to how we do it today of constructing a new docs/ directory in the /tmp temporary filesystem. Looking forward to seeing what your approach is and happy to provide feedback :)

@timvink
Copy link
Contributor

timvink commented Apr 17, 2020

Cool, will pick this up somewhere in next week!

timvink added a commit to timvink/mkdocs-monorepo-plugin that referenced this issue Apr 18, 2020
@timvink
Copy link
Contributor

timvink commented Apr 18, 2020

The symlink approach didn't work, but I got it working with the second idea. Opened #13, let's discuss details there!

@bih bih closed this as completed in 6b53d8f Jun 3, 2020
bih pushed a commit that referenced this issue Jun 4, 2020
* Update page.file source path with original source, fixes #12

* Fix edgecase where monorepo does not copy any files to temp docs dir

* Bump version and add unit tests for git related plugins

* Fix git related unit tests

* Fix keyerrors when docs contained folders

* Fix unit test that was moved

* bump version to 0.4.7

* Python 3.5 compatibility when after using rglob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants