-
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
Use sphinx-theme-builder
to build package
#419
Use sphinx-theme-builder
to build package
#419
Conversation
27422eb
to
af7bee3
Compare
Python's official [packaging guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/) now recommends using the `src/` layout, rather than having a top level module folder called `qiskit_sphinx_theme`. For example, this layout works Out Of The Box with setuptools—we no longer need to explicitly set `packages` in `setup.py`. This change unblocks us from migrating to qiskit-sphinx-theme in #419 because it expects projects to use the standard `src` layout. This has no impact on end-users. It only impacts how we layout our code. When running `python3 -m build`, the final result will strip out the `src/`. ## Also renames top-level folders Before: ``` qiskit_sphinx_theme ├── __init__.py ├── furo │ ├── base # the core qiskit theme │ └── ecosystem └── pytorch ``` After: ``` src └── qiskit_sphinx_theme ├── ecosystem ├── furo # the core qiskit theme └── pytorch ``` When I first set up the folders two months ago, I thought that we would have Theme Variants with Pytorch. I also didn't realize that the Ecosystem Furo theme variant will be so heavily based on the core Furo Qiskit theme; that is, we won't have `furo/base`, `furo/qiskit`, and `furo/ecosystem`. We'll simply have something like `qiskit/` and `ecosystem/`, with the Ecosystem theme based directly off of the Qiskit theme.
`pyproject.toml` is now the standardized way to set packaging metadata for Python packages. When possible, setuptools recommends using it rather than a dynamic `setup.py` time. Switching to `pyproject.toml` specifically unblocks #419. Another benefit is we can deduplicate setting the version in two places. ## Gets rid of "universal" wheel We were incorrectly claiming in `setup.cfg` that the package is "universal", which means it works with both Python 2 and Python 3. That is a lie. We don't support Python 2.
af7bee3
to
9b1160c
Compare
sphinx-theme-builder
to build packagesphinx-theme-builder
to build package
- name: Fix permissions for sphinx-theme-builder | ||
run: chown -R $(id -u):$(id -g) . |
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.
ChatGPT 🙇
def activate_themes(app: sphinx.application.Sphinx, config: sphinx.config.Config) -> None: | ||
if config.html_theme == "_qiskit_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.
So, apparently, the old code I had didn't actually work. Oops. The config.html_theme
was always alabaster
because it was being evaluated too early.
This works!
from furo import ( | ||
WrapTableAndMathInAContainerTransform, | ||
_builder_inited, | ||
_html_page_context, | ||
_overwrite_pygments_css, | ||
) | ||
|
||
app.add_post_transform(WrapTableAndMathInAContainerTransform) | ||
app.connect("html-page-context", _html_page_context) | ||
app.connect("builder-inited", _builder_inited) | ||
app.connect("build-finished", _overwrite_pygments_css) |
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.
Apparently, none of this is necessary. It gets called already because our Furo theme inherits from Furo.
# Our stylesheet takes precedence. | ||
stylesheet = | ||
styles/furo.css, | ||
styles/furo-extensions.css, |
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 don't need to explicitly register furo-extensions.css
apparently. It already gets registered by Furo, thanks to us inheriting Furo.
79cd1bf
to
bfeef13
Compare
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.
Looks good! The Furo theme works correctly for me, and I didn't notice any problems with the diff. Will obviously need review from someone with more sphinx experience than me though.
@@ -102,13 +106,13 @@ To update the top nav bar web component: | |||
1. In https://github.com/Qiskit/web-components, run `npm install` then `npm run build`. | |||
2. There should be a file created at the root of the web components repository called `experimental-bundled-ui-shell.js`. Copy its contents into these files in this theme repository: | |||
1. `src/qiskit_sphinx_theme/pytorch/static/js/web-components/top-nav-bar.js` | |||
2. `src/qiskit_sphinx_theme/furo/static/js/web-components/top-nav-bar.js` | |||
2. `src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/static/js/web-components/top-nav-bar.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.
I have a general q about the new folder structure. src/qiskit_sphinx_theme/theme/qiskit-sphinx-theme/etc
feels very long and repetitive, do we really need so many subfolders? Could it be simplified to src/qiskit_sphinx_theme/theme/etc
or something?
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.
100% agreed. But yes, sphinx-theme-builder is extremely opinionated
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.
hmm that's annoying 🤔 would it be an option to remove a folder layer higher up? So have something like this:
src
├── assets
├── ecosystem
├── pytorch
└── theme
└── qiskit-sphinx-theme
or would that mess things up as well?
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.
That would break how Python packages work. We could no longer import qiskit_sphinx_theme
. And I think sphinx-theme-builder would complain also too hah
|
||
### How to change CSS | ||
Make CSS changes in the file `qiskit_changes.css`. It takes precedence over any CSS rules from Furo. | ||
Make CSS changes in the file `assets/styles/qiskit-sphinx-theme.css`. It takes precedence over any CSS rules from 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.
is it a requirement that the css file is called qiskit-sphinx-theme
? I quite liked the qiskit_custom.css
bc it easily implied that this was where stuff differed from base 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.
Yes. sphinx-theme-builder is extremely opinionated
…inx-theme-builder
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.
LGTM, just left one more question about the folder structure 😅
Closes Qiskit#496. Qiskit#419 accidentally broke Pytorch because it apparently doesn't work to call `app.setup_extension` inside the `config-inited` event. So, we were no longer activating jQuery by default.
sphinx-theme-builder allows us to use JavaScript/NPM in our Python packaging pipeline. Whereas right now we have to write raw CSS and JavaScript files, we can now pre-process those files.
sphinx-theme-builder automates installing Node and NPM for users. It runs
npm run build
to pre-compile our code, which for now simply copies our CSS withcp
to keep the code simple.sphinx-theme-builder gives some benefits:
Changes folder structure
Before:
After: