-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
ENH/MAINT: Version switcher from the sphinx theme #15380
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
Conversation
7f967e4
to
000cd43
Compare
@jorisvandenbossche is this really released (it's live in the doc although there is no doc for 0.7.2, just 0.7.1) or did I miss a step? On master I can see the template but not on the release branch 0.7.x. I get this on 0.7.2 WARNING: unsupported theme option 'switcher' given
...
Reason: TemplateNotFound('version-switcher.html') Also I have a question, for SciPy we have a dynamic url when we make a PR. How should I handle this case? For the dev deployed on our main vs released versions, I think I can use some conditions in the config file as I did now. I could do something a bit more involved with re-writing the json file to also handle PRs. But maybe there is another simpler way to define such things? Last question I have for now, is there an automatic way to style the version switcher? If you look at our current switcher, it would change colour depending on whether it's a release, dev or something too old (and we picked sensible colours for colour deficient readers). |
No, it's not yet released. Hopefully there will be a 0.8.0 shortly that includes this, until then you will have to test with the master branch.
Good question, I am not fully sure what the best solution is. Are you using readthedocs or something like circle ci to host the docs from the PR?
The version switcher block has a specific ids on the different elements that can be used for styling. But that's of course for general styling, identical across all versions (unless you would vary the css depending on the version). |
Ok thanks 🙏 I will play with master then.
It's CircleCI for us and we have a link in the PR to see the artifact.
I thought I could manually rewrite the config by intercepting the final URL. A simpler way would be that if you select a version that does not exists it gives the current build. This way we don't need to know the dynamic url. That would solve everything for us I think 🤔 Because the deployed dev can have a fix
If there is an id we can hack something as it's currently the case (although the release of our doc does not have the version for some reason, another problem...). But yes having an optional flag in the json could be handy. We can change the name already, having other options could. |
something that I think @larsoner suggested was that you could add a
Step 2 requires some new JS in the theme, the rest is done per-project. |
This would be good I think. |
0.8 just got released, I will have a look again. |
I opened an issue at pydata/pydata-sphinx-theme#566 for the version-specific styling |
Thanks @jorisvandenbossche for opening the issue! Can you have a look at this PR? I am not sure if I did it right. It seems to be working like that but I am not sure I understand why because it does select As for CircleCI, once the above is sorted out, I would just have detected that we are in the CI and disabled the version switcher. |
If you check the browser console, you can see something like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://github.com/tupui/scipy/blob/version_switcher/doc/source/_static/version_switcher.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200". |
Thanks @jorisvandenbossche. After disabling CORS it was not working first because the JSON was not loading properly due to an extra comma at the end of the JSON. Maybe some warning would be nice here in case it fails to load the file. That would have helped me.
Anyway, it's working now: when it loads, the current build is live (we are not directly redirected to |
I've fixed the path for this to be merged. To see how it behaves, see the previous CI here |
{ | ||
"name": "1.9.0 (dev)", | ||
"version": "dev" | ||
}, | ||
{ | ||
"name": "1.8.0 (rc)", | ||
"version": "1.8.0" | ||
}, | ||
{ | ||
"name": "1.7.3 (stable)", | ||
"version": "1.7.3" | ||
}, | ||
{ | ||
"version": "1.7.2" | ||
}, | ||
{ | ||
"version": "1.7.1" | ||
}, | ||
{ | ||
"version": "1.7.0" | ||
}, |
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.
These will depends on how we fix the deployment of the live docs. Previous versions' links are resolving properly.
Yay! It is a nice feature. Maybe a subsequent PR can consider an optimal color that will blend in with the rest of the site. |
Yes totally @mattip! Joris opened pydata/pydata-sphinx-theme#566 to do this on the theme side. I would want to set the colours like I did before this (some red, orange, green which are colour deficient friendly). If we don't want to wait, we could tweak the CSS to do it. |
Wondering, how did you do that? (I know we struggled with this while developing the feature in the upstream theme)
That could be a browser console warning?
To be clear, the issue I opened is to have version-dependent colors, but we already added css classes to the dropdown button so you can robustly give it another color (one color for all versions). |
On Safari you have an option in the
Yes would be helpful I think.
I did not think about this point. It might look like a rainbow tree if we allow different colour for different version when you open the list. Sections might be better and maybe then just having the proper colour only for the selected version. |
Thanks for the info on CORS disabling, that's useful :)
Ah, I was actually talking about the color of the "button", not of the entries in the dropdown list. But maybe I misunderstood the original feature request about this. |
[skip ci]
[skip azp] [skip actions]
[skip azp] [skip actions]
This reverts commit c466cc7.
[skip azp] [skip actions]
@rgommers I updated the PR. We still need to decide on the style. There are 2 customisation options: style the button when a version is selected, style the elements in the list. Button style is by default Blue and depending on if it's a dev, stable or old version the background is adjusted in the list (I made a typo in the css this is why dev is not orange). I am not sure about colouring the list. It's a bit too rainbow-ish. Maybe just styling the button when a version is selected would be enough. Or we do more customisation to make it pretty but this is not my strong point 😅 In the end, maybe this would be the simplest with just a change of the button and not the list: /* If the active version has the name "dev", style it orange */
#version_switcher_button[data-active-version-name*="dev"] {
background-color: #E69F00;
}
/* green for `stable` */
#version_switcher_button[data-version-name*="stable"] {
background-color: #009E73;
}
/* red for `old` */
#version_switcher_button[data-version-name*="old"] {
background-color: #980F0F;
} (I still need to find a way to select old versions, so we could remove "old" in the name of old versions.) EDIT: found it What do you think? |
[skip azp] [skip actions]
That color scheme looks good to me, at least for now. It can always be tweaked later. |
Ok then ready on my side @rgommers @tylerjereddy |
I plan to merge it on Saturday night if there are no comment since then. |
* master: (632 commits) Update _dual_annealing.py (scipy#15939) TST: stats: make `check_sample_var` two-sided (scipy#15723) DOC: sparse.linalg: add citations for COLAMD DOC: fix missing comma in conf ENH/MAINT: Version switcher from the sphinx theme (scipy#15380) MAINT: stats: remove support for `_rvs` without `size` parameter (scipy#15917) BUG: Handle base case for scipy.integrate.simpson when span along the axis is 0 (scipy#15824) MAINT: stats: adjust tolerance for failing test only MAINT: stats: adjust tolerance of failing TestTruncnorm MAINT: special: Clean up C style in ndtr.c CI: remove pin on Jinja2 (scipy#15895) STY: Remove white spaces MAINT: stats: exempt gilbrat from refguide_check MAINT: stats: rename continuous_gilbrat->continuous_gibrat MAINT: stats: correct name Gilbrat -> Gibrat [ENH] circvar calculated simply as 1-R (scipy#5747) DEP: deal with deprecation of ndim >1 in bspline MAINT: stats: more specific error type from `rv_continuous.fit` (scipy#15778) DOC: fix import in example in _morestats (scipy#15900) [BUG] make p-values consistent with the literature (scipy#15894) ...
Closes #15377
Use the version switcher provided by the theme instead of our custom CSS/HTML solution.
I added all versions I saw on https://docs.scipy.org. I am still unsure about how to handle the dev and PR versions. Let see how it goes.
Once this is done, we can decide if we want to remove https://docs.scipy.org or not. The caveat of this method is that when switching to an old version, the version switcher will disappear. So we have to go back to latest to change again the switcher if we want to go to another version.