8000 [MRG+1] MAINT Use magic to list documentation versions by jnothman · Pull Request #9841 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] MAINT Use magic to list documentation versions #9841

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

Merged
merged 20 commits into from
Nov 20, 2017

Conversation

jnothman
Copy link
Member
@jnothman jnothman commented Sep 27, 2017

Fixes #9838 with the exception of dealing with the NEWS section of index.rst. See #9838 (comment)

This makes the listing of documentation versions dynamic by:

  • using sphinx magic |version|
  • using sphinx javascript variable DOCUMENTATION_OPTIONS.VERSION
  • exploiting the current URL to determine if it's looking at the official current dev or stable dir
  • using CircleCI to construct a catalogue of all currently available documentation on scikit-learn.org, and to store it at http://scikit-learn.org/versions.html (this part could be nicer)
  • linking to versions.html instead of listing previous versions

@jnothman jnothman added this to the 0.19.1 milestone Sep 27, 2017
@jnothman
Copy link
Member Author

Circle and Travis errors are both scikit-learn build errors related to changing g++ versions?

g++: sklearn/svm/src/libsvm/libsvm_template.cpp
g++: error: unrecognized command line option ‘-fstack-protector-strong’
g++: error: unrecognized command line option ‘-fno-plt’
g++: error: unrecognized command line option ‘-fstack-protector-strong’
g++: error: unrecognized command line option ‘-fno-plt’

@lesteve
Copy link
Member
lesteve commented Sep 27, 2017

My personal investigation starts in #9840 (comment). I am still hoping to work around the problem by using an older miniconda installer and not update conda, let's see ...

@jnothman
Copy link
Member Author
jnothman commented Sep 28, 2017

At http://scikit-learn.org/circle?13937/documentation.html, see:

  • page heading
  • documentation menu
  • "other versions" listing

A nicer way to produce the "all versions" page (at least in terms of templating) would be to get sphinx to compile it as part of the dev documentation. This would mean automatically generating it by pulling scikit-learn.github.io and inspecting, which can be slow (although that would change with something like #7887 (comment)). It could alternatively be done with github contents API.

@jnothman
Copy link
Member Author

@lesteve
Copy link
Member
lesteve commented Sep 28, 2017

That seems nice, I'll try to take a look today.

@jnothman
Copy link
Member Author

@lesteve, let me know if this seems reasonable by you or if we're better off just patching up the HTML ad-hoc.

@lesteve
Copy link
Member
lesteve commented Oct 10, 2017

It's definitely on my todo list for the 0.19.1 release but I have not got around to look at it yet. Will try to do it soon.

@jnothman jnothman changed the title [RFC/MRG] MAINT Use magic to list documentation versions [MRG] MAINT Use magic to list documentation versions Oct 16, 2017
@jnothman
Copy link
Member Author

I'm taking this out of 0.19.1 it makes no significant benefit there.

@jnothman jnothman removed this from the 0.19.1 milestone Oct 16, 2017
if suffix == SUFFIXES[0]:
return "%d%s" % (quantity, suffix)
else:
return "%.1f%s" % (quantity, suffix)
Copy link
Member

Choose a reason for hiding this comment

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

Currently, the generated list of versions includes e.g. "(PDF 41.8MB)" I think it would be useful to add a space between the number and the suffix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixing

try:
html = urlopen(RAW_FMT % name).read().decode('utf8')
except Exception:
print('Failed to fetch %s' % (RAW_FMT % name), file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

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

The latest CicleCI log has,

+ python build_tools/circle/list_versions.py
Failed to fetch https://raw.githubusercontent.com/scikit-learn/scikit-learn.github.io/master/circle/documentation.html

that link is not correct.

What happens if fetching a resource fails? Does it mean that one of the linked version will be missing? Or that's not critical?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we're better off with exceptions being critical and having a more curated glob.

<li><a href="http://scikit-learn.org/0.16/documentation.html">scikit-learn 0.16</a></li>
<script>if (VERSION_SUBDIR != "stable") document.write('<li><a href="http://scikit-learn.org/stable/documentation.html">Stable version</a></li>')</script>
<script>if (VERSION_SUBDIR != "dev") document.write('<li><a href="http://scikit-learn.org/dev/documentation.html">Development version</a></li>')</script>
<li><a href="http://scikit-learn.org/dev/versions.html">Previous versions</a></li>
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work for circle ci preview. Can't one use relative paths here i.e. ./versions.html?

Copy link
Member Author
@jnothman jnothman Nov 4, 2017

Choose a reason for hiding this comment

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

As below, it can't be a local link if it's to work on /stable and /0.19, etc. But the moment this is visible for master, the link will also work.

@@ -2,7 +2,7 @@

<div class="container-index">

Documentation of scikit-learn 0.19.dev0
Documentation of scikit-learn |version|
Copy link
Member

Choose a reason for hiding this comment

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

using sphinx magic |version|

Would you have a reference on how this works? Couldn't find it in sphinx docs...

Copy link
Member Author

Choose a reason for hiding this comment

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

Like many things in sphinx I stumbled upon it by accident, so now I can't remember how to get back there!

Copy link
Member Author

Choose a reason for hiding this comment

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

http://www.sphinx-doc.org/en/stable/config.html#confval-version hints at it, but I know it's elsewhere too

A3D4


digit_names = [k for k in dirs if k[:1].isdigit()]
word_names = [k for k in dirs if not k[:1].isdigit()]
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 not really able to follow what's happening in the 6 lines above. Maybe a few additional comments wouldn't hurt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some

<li><a href="http://scikit-learn.org/0.16/documentation.html">Scikit-learn 0.16</a></li>
<li><a href="{{ pathto('_downloads/scikit-learn-docs.pdf', 1) }}">PDF documentation</a></li>
<script>if (VERSION_SUBDIR != "stable") document.write('<li><a href="http://scikit-learn.org/stable/documentation.html">Stable version</a></li>')</script>
<script>if (VERSION_SUBDIR != "dev") document.write('<li><a href="http://scikit-learn.org/dev/documentation.html">Development version</a></li>')</script>
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this be done with sphinx templating ? My concern is that links dynamically changed with javascript are not so friendly toward search engines. Though it might not matter much in the case of scikit-learn...

Copy link
Member Author

Choose a reason for hiding this comment

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

Concern about spidering? Now it would have to spider through versions.html.... but that's not a great deal is it?

Sphinx templating... Lemme think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think for sphinx templating to work, we'd need to set a setting when building as to whether the document will be viewed as stable/dev/other. I don't think this is reasonable. When something moves from stable to historical, we don't want to recompile its docs. That's sort of the point of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

I think for sphinx templating to work, we'd need to set a setting when building as to whether the document will be viewed as stable/dev/other. I don't think this is reasonable.

Aww yes, I see your point.

<li><a href="{{ pathto('_downloads/scikit-learn-docs.pdf', 1) }}">PDF documentation</a></li>
<script>if (VERSION_SUBDIR != "stable") document.write('<li><a href="http://scikit-learn.org/stable/documentation.html">Stable version</a></li>')</script>
<script>if (VERSION_SUBDIR != "dev") document.write('<li><a href="http://scikit-learn.org/dev/documentation.html">Development version</a></li>')</script>
<li><a href="http://scikit-learn.org/dev/versions.html">Previous versions</a></li>
Copy link
Member

Choose a reason for hiding this comment

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

This also could be a local link?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it can't be a local link if it's to work on /stable and /0.19, etc.

@jnothman
Copy link
Member Author
jnothman commented Nov 4, 2017 via email

@codecov
Copy link
codecov bot commented Nov 4, 2017

Codecov Report

Merging #9841 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9841      +/-   ##
==========================================
+ Coverage   96.17%   96.17%   +<.01%     
==========================================
  Files         336      336              
  Lines       62406    62413       +7     
==========================================
+ Hits        60017    60024       +7     
  Misses       2389     2389
Impacted Files Coverage Δ
sklearn/metrics/tests/test_ranking.py 100% <0%> (ø) ⬆️
sklearn/metrics/ranking.py 98.31% <0%> (ø) ⬆️
sklearn/metrics/tests/test_common.py 99.52% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9c79d4...edb44a1. Read the comment docs.

<script>
VERSION_SUBDIR = (function(groups) {
return groups ? groups[1] : null;
})(location.href.match(/^https?:\/\/scikit-learn.org\/([^\/]+)/));
Copy link
Member

Choose a reason for hiding this comment

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

Checked that the above javascript regexp works as expected with the following code (run here),

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Match</button>

<p id="demo"></p>

<script>

var url = "http://scikit-learn.org/0.19/modules/linear_model.html#lars-lasso"

function matchUrl(groups) {
          return groups ? groups[1] : null;
      };
      
function myFunction() {
    var x = matchUrl(url.match(/^https?:\/\/scikit-learn.org\/([^\/]+)/));
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

@rth
Copy link
Member
rth commented Nov 10, 2017

@jnothman Sorry for the late reply.

Thanks for responding to all the comments.

Do you think this is worthwhile overall, or
too magic for new maintainers?

It would require some effort to understand how this works for new maintainers (and I am moderately enthusiastic about JS generated links) but I think it's really useful to have an always up to date list of the documentation for previous versions including the PDF.

Also, I don't have other ideas how the same results could be achieved in a simpler way. So generally this LGTM.

@rth rth changed the title [MRG] MAINT Use magic to list documentation versions [MRG+1] MAINT Use magic to list documentation versions Nov 10, 2017
@jnothman
Copy link
Member Author
jnothman commented Nov 11, 2017 via email

Copy link
Member
@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

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

LGTM

doc/support.rst Outdated
versions can be found here:
This documentation is relative to |release|. Documentation for
other versions can be found `here
<http://scikit-learn.org/dev/documentation.html>`_.
Copy link
Member
@TomDLT TomDLT Nov 17, 2017

Choose a reason for hiding this comment

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

I think http://scikit-learn.org/dev/versions.html would be more direct, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thanks!

@jnothman
Copy link
Member Author

And feel free to merge if that seems to be consensus.

@TomDLT TomDLT merged commit fd25481 into scikit-learn:master Nov 20, 2017
@TomDLT
Copy link
Member
TomDLT commented Nov 20, 2017

Thanks @jnothman !

Copy link
Member
@qinhanmin2014 qinhanmin2014 left a comment

Choose a reason for hiding this comment

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

Will it be worth to also push this PR into 0.19 branch (stable doc)?

@@ -114,6 +114,13 @@ pip install sphinx-gallery numpydoc
# Build and install scikit-learn in dev mode
python setup.py develop

# TO BE UNCOMMENTED BEFORE MERGE
Copy link
Member

Choose a reason for hiding this comment

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

Seems strange for me. Ignore if that's intended.

Copy link
Member

Choose a reason for hiding this comment

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

Yep good catch @qinhanmin2014, I have pushed e2584c3

@lesteve
Copy link
Member
lesteve commented Nov 20, 2017

Will it be worth to also push this PR into 0.19 branch (stable doc)?

Not sure, also I was wondering why the version list is only generated on master and not on 0.X.Y branches (if I am understanding the code correctly):

if [[ "$CIRCLE_BRANCH F438 " =~ ^master$ && -z "$CI_PULL_REQUEST" ]]
then
# List available documentation versions if on master
python build_tools/circle/list_versions.py > doc/versions.rst
fi

@TomDLT
Copy link
Member
TomDLT commented Nov 20, 2017

All generated docs link to the same page:
http://scikit-learn.org/dev/versions.html (#9841 (comment))

@qinhanmin2014
Copy link
Member

@lesteve Thanks :) I advocate to push it to 0.19 branch mainly bacause I think we should provide users a way to get access to the dev doc through the stable doc apart from typing dev in the url.

jnothman added a commit to jnothman/scikit-learn that referenced this pull request Nov 20, 2017
@jnothman
Copy link
Member Author
jnothman commented Nov 20, 2017 via email

@lesteve
Copy link
Member
lesteve commented Nov 20, 2017

Small comment, on the stable doc, I think that "Previous versions" is a bit misleading because its lists 0.20.dev0:
snap

Maybe "Other versions"?

@qinhanmin2014
Copy link
Member

Maybe "Other versions"?

But seems that it lists 0.19.1 itself. Maybe something like "All available versions" ?

@lesteve
Copy link
Member
lesteve commented Nov 20, 2017

But seems that it lists 0.19.1 itself. Maybe something like "All available versions" ?

Good point, your suggestion seems fine. Better suggestions welcome!

@jnothman
Copy link
Member Author
jnothman commented Nov 21, 2017 via email

jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
yarikoptic added a commit to yarikoptic/scikit-learn that referenced this pull request Jul 27, 2018
* tag '0.19.2':
  Release 0.19.2
  [MRG] Fix collections.abc deprecations with Python 3.7 (0.19.X backport) (scikit-learn#11509)
  FIX need to explicitly raise SkipTest
  MAINT disabled some tests failing under macOS and 32-bit Python on windows.
  MNT Release 0.19.2 with python 3.7 support (scikit-learn#11422)
  DOC previous versions -> all available versions (scikit-learn#10179)
  MAINT only build versions list on master branch
  [MRG+1] MAINT Use magic to list documentation versions (scikit-learn#9841)
  DOC Add Examples heading
  minor fixes to whatsnew
  fix release 0.19.1 whatsnew link (scikit-learn#9981)
yarikoptic added a commit to yarikoptic/scikit-learn that referenced this pull request Jul 27, 2018
* releases:
  Release 0.19.2
  [MRG] Fix collections.abc deprecations with Python 3.7 (0.19.X backport) (scikit-learn#11509)
  FIX need to explicitly raise SkipTest
  MAINT disabled some tests failing under macOS and 32-bit Python on windows.
  MNT Release 0.19.2 with python 3.7 support (scikit-learn#11422)
  DOC previous versions -> all available versions (scikit-learn#10179)
  MAINT only build versions list on master branch
  [MRG+1] MAINT Use magic to list documentation versions (scikit-learn#9841)
  DOC Add Examples heading
  minor fixes to whatsnew
  fix release 0.19.1 whatsnew link (scikit-learn#9981)
yarikoptic added a commit to yarikoptic/scikit-learn that referenced this pull request Jul 27, 2018
* dfsg:
  Release 0.19.2
  [MRG] Fix collections.abc deprecations with Python 3.7 (0.19.X backport) (scikit-learn#11509)
  FIX need to explicitly raise SkipTest
  MAINT disabled some tests failing under macOS and 32-bit Python on windows.
  MNT Release 0.19.2 with python 3.7 support (scikit-learn#11422)
  DOC previous versions -> all available versions (scikit-learn#10179)
  MAINT only build versions list on master branch
  [MRG+1] MAINT Use magic to list documentation versions (scikit-learn#9841)
  DOC Add Examples heading
  minor fixes to whatsnew
  fix release 0.19.1 whatsnew link (scikit-learn#9981)
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.

5 participants
0