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

Build: remove append_conf _magic_ from MkDocs #11206

Merged
merged 8 commits into from
Apr 16, 2024

Conversation

humitos
Copy link
Member

@humitos humitos commented Mar 11, 2024

Delete all the magic around MkDocs YAML that processes the mkdocs.yml file and define readthedocs theme automatically based on a feature flag, MKDOCS_THEME_RTD.

This PR removes:

  • automatically defining readthedocs as theme when MKDOCS_THEME_RTD feature flag is defined.
  • processing mkdocs.yml to add internal JS and CSS (embed and analytics) files automatically

This is another step forward on removing all the magic we perform on behalf the users and being more explicit about how to configure each doctool.

Reference:

Closes #8529

Delete all the magic around MkDocs YAML that processes the `mkdocs.yml`.

file and
define `readthedocs` theme automatically based on a feature flag,
`MKDOCS_THEME_RTD`.

This PR removes:

- automatically defining `readthedocs` as theme when `MKDOCS_THEME_RTD` feature
  flag is defined.
- processing `mkdocs.yml` to add internal JS and CSS (embed and analytics) files
  automatically

This is another step forward on removing all the magic we perform on behalf the
users and being more explicit about how to configure each doctool.

Reference:

* readthedocs/addons#72 (comment)

Closes #8529
@humitos humitos requested a review from a team as a code owner March 11, 2024 15:50
@humitos humitos requested a review from stsewd March 11, 2024 15:50
@humitos humitos requested review from ericholscher and removed request for stsewd March 11, 2024 15:50
humitos added 3 commits March 11, 2024 17:15
Listen to `Project.post_save` signal and enable Addons if the project was
created after a specific date, it's MkDocs and it's the first time the
`AddonsConfig` is created.
Comment on lines 44 to 48
if (
project.pub_date
> datetime.datetime(2023, 4, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
and instance.documentation_type == MKDOCS
):
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this logic always run? We are removing the old injection logic completely in this PR, if an old project is build, they won't have the old injections nor the new addons.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have only a few projects on commercial using this feature only, and we plan to contact them telling how to migrate their configuration. Basically, they just need to define theme.name: readthedocs in their mkdocs.yml file.

I used this date here as an example, but we should give them more time than 20 days 😄 to migrate. We will contact them via email and write a blog post about this as well before merging this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I re-read your comment and I think you are right 👍🏼 . I updated this code to remove the datetime limitation.

@humitos humitos added the Status: blocked Issue is blocked on another issue label Mar 11, 2024
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks like a solid change, and a big step forward for Addons & our new build approach ❤️ Not 👍'ing yet until we make a full plan for rolling it out to unblock it.

humitos added a commit to readthedocs/website that referenced this pull request Mar 19, 2024
Blog post announcing the depreaction of the `mkdocs.yml` manipulation done by
Read the Docs at build time, following the plan described.

Related:
* readthedocs/addons#72 (comment)
* readthedocs/readthedocs.org#11206
* readthedocs/readthedocs.org#8529
humitos added a commit to readthedocs/website that referenced this pull request Mar 25, 2024
* Post: MkDocs YAML manipulation

Blog post announcing the depreaction of the `mkdocs.yml` manipulation done by
Read the Docs at build time, following the plan described.

Related:
* readthedocs/addons#72 (comment)
* readthedocs/readthedocs.org#11206
* readthedocs/readthedocs.org#8529

* Use double quotes

The other ones don't render properly.

* Apply suggestions from code review

Co-authored-by: Eric Holscher <[email protected]>

---------

Co-authored-by: Eric Holscher <[email protected]>
@humitos
Copy link
Member Author

humitos commented Mar 26, 2024

Merge this PR on April 15th and deploy it after it.

@humitos humitos removed the Status: blocked Issue is blocked on another issue label Apr 15, 2024
@humitos humitos requested review from ericholscher and stsewd April 15, 2024 09:33
@humitos
Copy link
Member Author

humitos commented Apr 15, 2024

This PR was reviewed but it doesn't have an approval yet. I re-checked the changes and it seems it's fine to be merged and deploy. Please, take a final look at it today since we need to merge and deploy it today/tomorrow as we published in our blog.

@@ -389,8 +178,3 @@ def yaml_load_safely(content):
information loss.
"""
return yaml.load(content, Loader=SafeLoader)
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove all code related to SafeLoader and just call safe_load now.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't yet because it's used to get the final doctype for the version at

config = yaml_load_safely(fh)
use_directory_urls = config.get("use_directory_urls", True)
return MKDOCS if use_directory_urls else MKDOCS_HTML

This code will be eventually removed since the doctype doesn't have too much sense anymore now that we support many doctools more. We should probably need to have a conversation about how to delete doctypes completely in a safe way.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, but don't think you need the custom loader to just read that setting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hrm, but without the safeloader we will executing !!python syntax, which is why we added it, right?

Copy link
Member

Choose a reason for hiding this comment

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

No if you call safe_load()

Copy link
Member

Choose a reason for hiding this comment

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

The custom loader was added to don't set those values to None after reading them (we were using safe_load previously).

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool. Good point! I will delete this chunk of code then 👍🏼

@humitos humitos merged commit 1c0f1c7 into main Apr 16, 2024
7 checks passed
@humitos humitos deleted the humitos/remove-append-conf-mkdocs branch April 16, 2024 08:32
yaml_dump_safely,
yaml_load_safely,
)
from readthedocs.doc_builder.backends.mkdocs import ProxyPythonName, yaml_load_safely

Choose a reason for hiding this comment

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

readthedocs/config/tests/test_yaml_loader.py

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.

mkdocs: Values with special ! syntax are set to null on mkdocs.yml
4 participants