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

Handle plugin generated content and config #79

Merged
merged 16 commits into from
Aug 19, 2023

Conversation

thejcannon
Copy link
Contributor

@thejcannon thejcannon commented Aug 9, 2023

This change allows mkdocs-awesome-pages-plugin to play nicely with mkdocs-gen-files, specifically with generated content (.md) and generated config (.pages).

This is accomplished by:

  1. Defining an on_files in the plugin that synthesizes a File per config in the docs dir. This means we can later unconditionally pull from Files for both in-docs and generated configs.
  2. Passing the Files down the chain to NavigationMeta
    • We can use the Files to validate the "out-of-docs" check, so we also remove the docs_dir arg
    • Additionally, generated files aren't "in-docs", so that check would mean we did't add the generated docs. So removing it is vital to the overall change anyways
  3. Making _gather_metadata operate on a "relative file" abstraction (e.g. the path below "docs_dir)
    • For Pages, that means adding item.file.src_path instead of item.file.abs_src_path
    • For sections, the metadata loading gets tricky. We have to load the absolute path (because that's how the generated files work), but they path should be the relative path so we match correctly later.
  4. Replace Meta.try_load_from with Meta.try_load_from_files such that we always load from Files
    • But as mentioned, if we do successfully load, we need to swap the path attribute with the relative path

That summarizes the package changes, then there was a few test changes top facilitate this change:

  • All the necessary refactoring to handle the swap from docs_dir to files
  • test_meta.py changes for the correct Files lookup, and new method
  • New test infrastructure to have a test define additional Mkdocs plugins, specifically so we can simulate mkdocs-gen-files
  • New tests for the specific use-case of generated files

Fixes #78

@thejcannon thejcannon marked this pull request as draft August 9, 2023 21:16
@thejcannon thejcannon marked this pull request as ready for review August 10, 2023 16:40
@thejcannon
Copy link
Contributor Author

@lukasgeiter This is ready to review.

The je ne sais quoi is boiled down to:

  • Try to refer to everything by a "relative path"
  • Synthesizing a File per config, so there isn't a split codepath

@thejcannon
Copy link
Contributor Author

And to report, this is working as expected on my project 🎉

@lukasgeiter
Copy link
Owner

Thanks for creating this PR! Before I dive into reviewing, I've noticed some formatting changes that shouldn't be there. Please make sure to format the files using black.

@lukasgeiter
Copy link
Owner

Please disregard the failing tests for pypy, they have nothing to do with your PR. I've actually just removed them on master so a rebase should get rid of them. The same does not apply for the failing tests on windows, that seems to be an actual issue 😉

@thejcannon
Copy link
Contributor Author

Thanks for taking a look!

Yeah looks like editor ran black with a different line length (shorter) leading to some spurious reformats. I'll fix those

@thejcannon
Copy link
Contributor Author

@lukasgeiter All tests are passing! Ready for review when you are.

Copy link
Owner

@lukasgeiter lukasgeiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I especially appreciate the added test cases ❤️

mkdocs_awesome_pages_plugin/meta.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/navigation.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/navigation.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/plugin.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/tests/e2e/base.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/tests/e2e/test_gen_files.py Outdated Show resolved Hide resolved
mkdocs_awesome_pages_plugin/tests/navigation/test_meta.py Outdated Show resolved Hide resolved
@thejcannon
Copy link
Contributor Author

@lukasgeiter I think that should cover those comments. Happy for another look

Copy link
Owner

@lukasgeiter lukasgeiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there now 😅

@lukasgeiter lukasgeiter merged commit e679f2c into lukasgeiter:master Aug 19, 2023
11 checks passed
@lukasgeiter
Copy link
Owner

Released with version 2.9.2. Thanks again for your work!

@thejcannon
Copy link
Contributor Author

Thank you for accepting it, and reviewing it

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

Successfully merging this pull request may close these issues.

Allow mkdocs-gen-files generated content
2 participants