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

[on hold] Vendor Furo so that we can change its Python code #463

Closed
wants to merge 5 commits into from

Conversation

Eric-Arellano
Copy link
Collaborator

@Eric-Arellano Eric-Arellano commented Jul 6, 2023

Motivation

We need to change Furo's Python code to work around #328. Its call to _compute_navigation_tree with a maxdepth=-1 results in a 3.5 hour build for Terra because Terra has so many pages. While #451 was able to fix the HTML page sizes being huge, it did not fix the build performance because Furo's Python code would still run, and then only be overridden by our code after.

I have not been able to figure out how to disable/override Python code from an inherited Sphinx theme. I couldn't get monkeypatching to work either. This line causes Sphinx to run all of Furo's setup, including the slow _compute_navigation_tree line:

Pre-processing the TOC Tree before it gets to Furo in #474 helped, but it still took 1.5 hours (vs. 3.5 hours), which is too slow. We're planning on restructuring Terra docs to have fewer HTML pages. But even with that, we still will want to make local docs development faster. With local docs, we want to set the navigation_depth to 1 and only use a value like -1 in production builds.

Our hope is that pradyunsg/furo#674 will be accepted, but there is no guarantee and the timeline is out of our control. So, this fork unblocks allowing us to tweak Furo's Python code to avoid the call to _compute_navigation_tree.

If pradyunsg/furo#674 is merged, we will strongly consider reverting this PR.

Fork strategy

We keep a strong emphasis on separating what is base Furo vs. our customization, along with keeping the # of customizations as low as possible.

This PR adds 58 new files, but 57 of them should never have custom changes from us. We make that clear with comments at the top of each file like // This file is vendored from Furo. It should have no changes.. For example, styling changes should never happen in the folder assets/styles/furo, only in our custom files at the root of assets/styles.

This makes it much easier to stay in sync with upstream Furo.

How to sync

We have a new file furo-sync.txt where we write the commit from Furo from the last time we synced.

As before, when we sync, we look closely at every change Furo has made and update our vendored code. This is the same before, only now we need to check more files than before.

Code tweak: only run Furo setup when relevant

We change furo_py/__init__.py to skip its setup when Pytorch is used and when the docs builder is not HTML (e.g. docstest).

Also closes #314

Closes #314 because this hooks up our CSS and JavaScript file to Furo's _add_asset_hashes that adds hashes to the file names so that they are invalidated properly on changes.

Eric-Arellano added a commit that referenced this pull request Jul 6, 2023
## Adds Furo license

It's extra safe to do this because we vendor about 6 files from Furo. 

We use the prior art of Pytorch of including the license directly in
`LICENSE` at the bottom. Pytorch is also an MIT license and we
substantially vendored it, so it's a similar setup.

## Fixes LICENSE inclusion

The switch to `pyproject.toml` accidentally changed us including the
LICENSE file to instead have the text `Apache 2`.

## Adds copyright file headers

We should have been doing this from the start because Qiskit projects
are expected to put copyright headers on every file. This becomes
especially useful if we more substantially vendor Furo code in
#463 to make clear
what is what.

All files that are originally written by Qiskit contributors use the
standard Apache 2 license we already use in this project.

Meanwhile, files that are vendored from Furo now use this standard
notice:

> This file is vendored from Furo (created by Pradyun Gedam) and used
under the MIT license.

Even though the MIT license does not require file headers, and Furo
itself does not use it, it is a good practice to make clear what
originally comes from Furo.

## Also renames `search_sidebar.html`

This file is vendored from Furo, but we had it under
`custom_templates/search_sidebar.html` rather than the original
`sidebar/search.html`. This PR renames the file so that we more properly
attribute Furo and the MIT license.
Eric-Arellano added a commit to Eric-Arellano/qiskit_sphinx_theme that referenced this pull request Jul 6, 2023
## Adds Furo license

It's extra safe to do this because we vendor about 6 files from Furo. 

We use the prior art of Pytorch of including the license directly in
`LICENSE` at the bottom. Pytorch is also an MIT license and we
substantially vendored it, so it's a similar setup.

## Fixes LICENSE inclusion

The switch to `pyproject.toml` accidentally changed us including the
LICENSE file to instead have the text `Apache 2`.

## Adds copyright file headers

We should have been doing this from the start because Qiskit projects
are expected to put copyright headers on every file. This becomes
especially useful if we more substantially vendor Furo code in
Qiskit#463 to make clear
what is what.

All files that are originally written by Qiskit contributors use the
standard Apache 2 license we already use in this project.

Meanwhile, files that are vendored from Furo now use this standard
notice:

> This file is vendored from Furo (created by Pradyun Gedam) and used
under the MIT license.

Even though the MIT license does not require file headers, and Furo
itself does not use it, it is a good practice to make clear what
originally comes from Furo.

## Also renames `search_sidebar.html`

This file is vendored from Furo, but we had it under
`custom_templates/search_sidebar.html` rather than the original
`sidebar/search.html`. This PR renames the file so that we more properly
attribute Furo and the MIT license.
Eric-Arellano added a commit that referenced this pull request Jul 6, 2023
…467)

## Adds Furo license

It's extra safe to do this because we vendor about 6 files from Furo. 

We use the prior art of Pytorch of including the license directly in
`LICENSE` at the bottom. Pytorch is also an MIT license and we
substantially vendored it, so it's a similar setup.

## Fixes LICENSE inclusion

The switch to `pyproject.toml` accidentally changed us including the
LICENSE file to instead have the text `Apache 2`.

## Adds copyright file headers

We should have been doing this from the start because Qiskit projects
are expected to put copyright headers on every file. This becomes
especially useful if we more substantially vendor Furo code in
#463 to make clear
what is what.

All files that are originally written by Qiskit contributors use the
standard Apache 2 license we already use in this project.

Meanwhile, files that are vendored from Furo now use this standard
notice:

> This file is vendored from Furo (created by Pradyun Gedam) and used
under the MIT license.

Even though the MIT license does not require file headers, and Furo
itself does not use it, it is a good practice to make clear what
originally comes from Furo.

## Also renames `search_sidebar.html`

This file is vendored from Furo, but we had it under
`custom_templates/search_sidebar.html` rather than the original
`sidebar/search.html`. This PR renames the file so that we more properly
attribute Furo and the MIT license.
@Eric-Arellano Eric-Arellano changed the title [DO NOT MERGE] Experiment with fully vendoring Furo Vendor Furo so that we can change its Python code Jul 7, 2023
@@ -68,26 +68,13 @@ def remove_thebe_if_not_needed(


def activate_themes(app: sphinx.application.Sphinx, config: sphinx.config.Config) -> None:
if config.html_theme == "qiskit":
# We set a low priority so that our Qiskit CSS file overrides Furo.
app.add_css_file("styles/furo.css", 100)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We no longer need to add furo.css because it gets included in qiskit-sphinx-theme.css thanks to Webpack.



def remove_furo_js(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need to do this anymore.

Comment on lines -69 to -73
// Remove once https://github.com/pradyunsg/furo/commit/c8b51d09af3dcaac3046f7e761119e9d1b7c9e37
// is released.
article {
overflow-wrap: break-word;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are using a commit from Furo that already includes this change.

Comment on lines +1 to +7
/* This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license.
*
* It's only changes are:
*
* 1. Renaming the file from `furo.sass` to `_index.sass`.
* 2. Including furo-extensions.sass directly in it.
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment is worth reading.

But every other file in assets/styles/furo is 100% identical to Furo outside of the copyright comment at the top.

Comment on lines +14 to +15
// Import the base Furo style
@import "furo";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is how we import Furo's style now.

The next file in this PR, furo_py/__init__.py is really important to review btw.

Comment on lines +1 to +4
# This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license.
#
# When making changes, surround it with `QISKIT CHANGE: start` and `QISKIT CHANGE: end` comments.
# We also add MyPy type ignores.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is copied exactly, other than the parts where I put QISKIT CHANGE: start.

Comment on lines +1 to +2
# This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license.
# It should have no changes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing to review here.

Comment on lines +1 to +4
{#-
This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license.
It should have no changes.
-#}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing to review in these new HTML files.

@@ -11,8 +11,9 @@
# that they have been altered from the originals.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is basically copy-and-paste from Furo.

test: /\.scss$/,
test: /\.s[ac]ss$/i,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Furo uses Sass files, so we need to compile both Sass and SCSS.

@Eric-Arellano Eric-Arellano changed the title Vendor Furo so that we can change its Python code [on hold] Vendor Furo so that we can change its Python code Jul 7, 2023
@Eric-Arellano Eric-Arellano added the on hold On hold for now label Jul 7, 2023
@Eric-Arellano
Copy link
Collaborator Author

Going to close for now. We only want to set navigation_depth for dev builds. Prod should still use -1. Qiskit devs have signed off on the plan to speed things up by reducing the # of HTML pages for API docs.

Hopefully pradyunsg/furo#674 is merged. If not, we can speed up dev builds by using sphinx-remove-toctrees. Fully vendoring Furo is not worth the cost solely to speed up dev builds. While navigation_depth is nicer than sphinx-remove-toctrees, the latter is fine enough for dev builds.

@Eric-Arellano Eric-Arellano deleted the EA/fully-vendor-furo branch July 10, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold On hold for now
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate if it's possible in Sphinx to invalidate content when it changes
1 participant