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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build_tools/circle/build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

# The pipefail is requested to propagate exit code
set -o pipefail && cd doc && make $MAKE_TARGET 2>&1 | tee ~/log.txt

Expand Down
92 changes: 92 additions & 0 deletions build_tools/circle/list_versions.py
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)
1 change: 0 additions & 1 deletion build_tools/circle/push_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ git config --global push.default matching
git add -f $dir/
git commit -m "$MSG" $dir
git push

echo $MSG
8 changes: 3 additions & 5 deletions 8 doc/developers/maintainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ Making a release

$ git shortlog -ns 0.998..

- edit the doc/conf.py to increase the version number

- edit the doc/themes/scikit-learn/layout.html to change the 'News'
entry of the front page.
- edit the doc/index.rst to change the 'News' entry of the front page.

2. Update the version number in sklearn/__init__.py, the __version__
variable
Expand All @@ -38,7 +35,8 @@ Making a release
$ python setup.py sdist register upload


5. Push the documentation to the website (see README in doc folder)
5. Push the documentation to the website. Circle CI should do this
automatically for master and <N>.<N>.X branches.


6. Build binaries using dedicated CI servers by updating the git submodule
Expand Down
10 changes: 5 additions & 5 deletions doc/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

=======================================

.. raw:: html
Expand All @@ -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>
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.

<li><a href="_downloads/scikit-learn-docs.pdf">PDF documentation</a></li>
</ul>

</div>
Expand Down
12 changes: 4 additions & 8 deletions doc/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,9 @@ client works fine: http://webchat.freenode.net
Documentation resources
=======================

This documentation is relative to |release|. Documentation for other
versions can be found here:
This documentation is relative to |release|. Documentation for
other versions can be found `here
<http://scikit-learn.org/dev/versions.html>`_.

* `0.18 <http://scikit-learn.org/0.18/>`_
* `0.17 <http://scikit-learn.org/0.17/>`_
* `0.16 <http://scikit-learn.org/0.16/>`_
* `0.15 <http://scikit-learn.org/0.15/>`_

Printable pdf documentation for all versions can be found `here
Printable pdf documentation for old versions can be found `here
<https://sourceforge.net/projects/scikit-learn/files/documentation/>`_.
15 changes: 10 additions & 5 deletions doc/themes/scikit-learn/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -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\/([^\/]+)/));
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>

</script>
<link rel="canonical" href="http://scikit-learn.org/stable/{{pagename}}.html" />

<script type="text/javascript">
Expand Down Expand Up @@ -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>
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="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.

<li><a href="{{ pathto('_downloads/scikit-learn-docs.pdf', 1) }}">PDF documentation</a></li>
</ul>
</div>
</li>
Expand Down
0