-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[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
Changes from all commits
6c4a847
59df779
78ffada
4314706
30254bd
fee8abb
6e80b37
67d0a4b
e7447eb
06f1301
19e02d6
2a4a413
da0e242
2625f24
f562773
c9be779
edb44a1
ef32e8d
fae5176
e372c96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# List all available versions of the documentation | ||
|
||
from urllib.request import urlopen | ||
import json | ||
import re | ||
|
||
from distutils.version import LooseVersion | ||
|
||
|
||
def json_urlread(url): | ||
return json.loads(urlopen(url).read().decode('utf8')) | ||
|
||
|
||
def human_readable_data_quantity(quantity, multiple=1024): | ||
# https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size | ||
if quantity == 0: | ||
quantity = +0 | ||
SUFFIXES = ["B"] + [i + {1000: "B", 1024: "iB"}[multiple] | ||
for i in "KMGTPEZY"] | ||
for suffix in SUFFIXES: | ||
if quantity < multiple or suffix == SUFFIXES[-1]: | ||
if suffix == SUFFIXES[0]: | ||
return "%d %s" % (quantity, suffix) | ||
else: | ||
return "%.1f %s" % (quantity, suffix) | ||
else: | ||
quantity /= multiple | ||
|
||
|
||
def get_pdf_size(version): | ||
api_url = ROOT_URL + '%s/_downloads' % version | ||
for path_details in json_urlread(api_url): | ||
if path_details['name'] == 'scikit-learn-docs.pdf': | ||
return human_readable_data_quantity(path_details['size'], 1000) | ||
|
||
|
||
heading = 'Available documentation for Scikit-learn' | ||
print(heading) | ||
print('=' * len(heading)) | ||
print() | ||
print('Web-based documentation is available for versions listed below:') | ||
print() | ||
|
||
ROOT_URL = 'https://api.github.com/repos/scikit-learn/scikit-learn.github.io/contents/' # noqa | ||
RAW_FMT = 'https://raw.githubusercontent.com/scikit-learn/scikit-learn.github.io/master/%s/documentation.html' # noqa | ||
VERSION_RE = re.compile(r"\bVERSION:\s*'([^']+)'") | ||
NAMED_DIRS = ['dev', 'stable'] | ||
|
||
# Gather data for each version directory, including symlinks | ||
dirs = {} | ||
symlinks = {} | ||
root_listing = json_urlread(ROOT_URL) | ||
for path_details in root_listing: | ||
name = path_details['name'] | ||
if not (name[:1].isdigit() or name in NAMED_DIRS): | ||
continue | ||
if path_details['type'] == 'dir': | ||
html = urlopen(RAW_FMT % name).read().decode('utf8') | ||
version_num = VERSION_RE.search(html).group(1) | ||
pdf_size = get_pdf_size(name) | ||
dirs[name] = (version_num, pdf_size) | ||
|
||
if path_details['type'] == 'symlink': | ||
symlinks[name] = json_urlread(path_details['_links']['self'])['target'] | ||
|
||
|
||
# Symlinks should have same data as target | ||
for src, dst in symlinks.items(): | ||
if dst in dirs: | ||
dirs[src] = dirs[dst] | ||
|
||
# Output in order: dev, stable, decreasing other version | ||
seen = set() 8000 | ||
for name in (NAMED_DIRS + | ||
sorted((k for k in dirs if k[:1].isdigit()), | ||
key=LooseVersion, reverse=True)): | ||
version_num, pdf_size = dirs[name] | ||
if version_num in seen: | ||
# symlink came first | ||
continue | ||
else: | ||
seen.add(version_num) | ||
name_display = '' if name[:1].isdigit() else ' (%s)' % name | ||
path = 'http://scikit-learn.org/%s' % name | ||
out = ('* `Scikit-learn %s%s documentation <%s/documentation.html>`_' | ||
% (version_num, name_display, path)) | ||
if pdf_size is not None: | ||
out += (' (`PDF %s <%s/_downloads/scikit-learn-docs.pdf>`_)' | ||
% (pdf_size, path)) | ||
print(out) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,5 +39,4 @@ git config --global push.default matching | |
git add -f $dir/ | ||
git commit -m "$MSG" $dir | ||
git push | ||
|
||
echo $MSG |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
<div class="container-index"> | ||
|
||
Documentation of scikit-learn 0.19.dev0 | ||
Documentation of scikit-learn |version| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would you have a reference on how this works? Couldn't find it in sphinx docs... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
======================================= | ||
|
||
.. raw:: html | ||
|
@@ -28,10 +28,10 @@ Documentation of scikit-learn 0.19.dev0 | |
<!-- doc versions --> | ||
<h2>Other Versions</h2> | ||
<ul> | ||
<li>scikit-learn 0.19 (development)</li> | ||
<li><a href="http://scikit-learn.org/stable/documentation.html">scikit-learn 0.18 (stable)</a></li> | ||
<li><a href="http://scikit-learn.org/0.17/documentation.html">scikit-learn 0.17</a></li> | ||
<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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
<li><a href="_downloads/scikit-learn-docs.pdf">PDF documentation</a></li> | ||
</ul> | ||
|
||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,11 @@ | |
{% endif %} | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="{{ pathto('_static/js/bootstrap.min.js', 1)}}" type="text/javascript"></script> | ||
<script> | ||
VERSION_SUBDIR = (function(groups) { | ||
return groups ? groups[1] : null; | ||
})(location.href.match(/^https?:\/\/scikit-learn.org\/([^\/]+)/)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
||
</script> | ||
<link rel="canonical" href="http://scikit-learn.org/stable/{{pagename}}.html" /> | ||
|
||
<script type="text/javascript"> | ||
|
@@ -78,17 +83,17 @@ | |
<span class="caret"></span> | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li class="link-title">Scikit-learn 0.19 (development)</li> | ||
<li class="link-title">Scikit-learn <script>document.write(DOCUMENTATION_OPTIONS.VERSION + (VERSION_SUBDIR ? " (" + VERSION_SUBDIR + ")" : ""));</script></li> | ||
<li><a href="{{ pathto('tutorial/index') }}">Tutorials</a></li> | ||
<li><a href="{{ pathto('user_guide') }}">User guide</a></li> | ||
<li><a href="{{ pathto('modules/classes') }}">API</a></li> | ||
<li><a href="{{ pathto('faq') }}">FAQ</a></li> | ||
<li><a href="{{ pathto('developers/contributing') }}">Contributing</a></li> | ||
<li class="divider"></li> | ||
<li><a href="http://scikit-learn.org/stable/documentation.html">Scikit-learn 0.18 (stable)</a></li> | ||
<li><a href="http://scikit-learn.org/0.17/documentation.html">Scikit-learn 0.17</a></li> | ||
<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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Aww yes, I see your point. |
||
<li><a href="http://scikit-learn.org/dev/versions.html">Previous versions</a></li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also could be a local link? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
<li><a href="{{ pathto('_downloads/scikit-learn-docs.pdf', 1) }}">PDF documentation</a></li> | ||
</ul> | ||
</div> | ||
</li> | ||
|
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.
Seems strange for me. Ignore if that's intended.
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.
Yep good catch @qinhanmin2014, I have pushed e2584c3