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

Simplify how the theme is override #67

Merged
merged 6 commits into from
May 24, 2022

Conversation

aladjadj
Copy link
Contributor

@aladjadj aladjadj commented May 21, 2022

This PR intends to simplify the code to update only the attribute necessary by backstage

Nota: Previously, this PR tried to fix the run-time error fixed by #69

@aladjadj aladjadj requested a review from a team as a code owner May 21, 2022 10:24
@aladjadj
Copy link
Contributor Author

It's necessary to add tests to validate that, I add them when I've some time

@aladjadj aladjadj force-pushed the fix_theme_override branch 3 times, most recently from 4894899 to 1234dab Compare May 21, 2022 17:00
Copy link
Member

@iamEAP iamEAP left a comment

Choose a reason for hiding this comment

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

Hey @aladjadj! I noticed that mkdocs-techdocs-core==1.1.0 was breaking all documentation builds (due to this copy runtime error), so I went in and fixed just the runtime error, without any additional fixes (as you've done here).

My recommendation would be to rebase off of the latest main branch, and fix some of the underlying theme override logic in a new PR.

I've added notes below about what I discovered while testing out your branch; hope they help you get to the solution you're looking for!

src/core.py Outdated Show resolved Hide resolved
src/core.py Outdated Show resolved Hide resolved
src/test_core.py Outdated Show resolved Hide resolved
@aladjadj
Copy link
Contributor Author

Thx for your fix and comments and my apologize for the introduced bug.

If the theme config is all the time an instance of Theme and we want to keep the capability to override this in mkdocs,
we can just update the field we want ?

@aladjadj aladjadj changed the title Fix run-time AttributeError: 'Theme' object has no attribute 'copy' Simplify how the theme is override May 22, 2022
@aladjadj aladjadj force-pushed the fix_theme_override branch 5 times, most recently from 106f891 to 9f9b034 Compare May 22, 2022 18:04
Copy link
Member

@iamEAP iamEAP left a comment

Choose a reason for hiding this comment

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

No worries @aladjadj! I think the simplified approach you've got here is the way to go. I have one comment on logging, and then some test case ideas too.

Lemme know what you think!

Also \cc @camilaibs, who's on community rotation this week.

src/core.py Outdated
Comment on lines 53 to 56
log.info("[mkdocs-techdocs-core] The theme has been replaced by 'material'")
log.info(
"[mkdocs-techdocs-core] Set theme.name to 'material' to override theme options"
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little worried that this will create undesirable noise in logs; my understanding is that most people would not have explicitly set a theme value, if they are using TechDocs, and thus, this message would start appearing on every build for most users.

Perhaps instead, it'd be good to log the opposite? E.g. when the theme name is detected to be material, it's likely that the user intended to override theme settings. In which case, a log message like Overridden theme settings in use (or something similar) would be helpful for them to see.

src/test_core.py Outdated
@@ -51,6 +51,17 @@ def test_override_default_config_with_user_config(self):
self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])

def test_remove_theme_config_with_user_options(self):
Copy link
Member

Choose a reason for hiding this comment

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

The code path that gets run in this case is when config["theme"].name is not material, which results in theme configuration being overridden. ...But it's hard to tell that because the name of the theme is set somewhere else.

Maybe this test case would be clearer if you named it differently? Like test_theme_overrides_removed_when_name_is_not_material or something?

src/test_core.py Show resolved Hide resolved
@aladjadj
Copy link
Contributor Author

Thx for your help @iamEAP , i follow your different feedback to improve the PR.

Copy link
Contributor

@camilaibs camilaibs left a comment

Choose a reason for hiding this comment

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

Looks great to me, could you take a look again @iamEAP ?

Copy link
Member

@iamEAP iamEAP left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks again @aladjadj

Signed-off-by: Camila Belo <camilaibs@gmail.com>
@camilaibs camilaibs merged commit 86723f8 into backstage:main May 24, 2022
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.

None yet

3 participants