-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
a2ce73d
to
0abe5f3
Compare
## 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.
## 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.
0abe5f3
to
fbdb341
Compare
…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.
fbdb341
to
85c185e
Compare
@@ -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) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
// Remove once https://github.com/pradyunsg/furo/commit/c8b51d09af3dcaac3046f7e761119e9d1b7c9e37 | ||
// is released. | ||
article { | ||
overflow-wrap: break-word; | ||
} |
There was a problem hiding this comment.
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.
/* 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. | ||
*/ |
There was a problem hiding this comment.
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.
// Import the base Furo style | ||
@import "furo"; |
There was a problem hiding this comment.
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.
# 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. |
There was a problem hiding this comment.
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
.
# This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license. | ||
# It should have no changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing to review here.
{#- | ||
This file is vendored from Furo (created by Pradyun Gedam) and used under the MIT license. | ||
It should have no changes. | ||
-#} |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
Going to close for now. We only want to set Hopefully pradyunsg/furo#674 is merged. If not, we can speed up dev builds by using |
Motivation
We need to change Furo's Python code to work around #328. Its call to
_compute_navigation_tree
with amaxdepth=-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:qiskit_sphinx_theme/src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/theme.conf
Line 2 in 10fff40
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 folderassets/styles/furo
, only in our custom files at the root ofassets/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.