8000 [MAINT] Upgrade to Sphinx-Gallery 0.1.4 (#7354) · raghavrv/scikit-learn@1054e07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1054e07

Browse files
Titan-Clesteve
authored andcommitted
[MAINT] Upgrade to Sphinx-Gallery 0.1.4 (scikit-learn#7354)
* [MAINT] Upgrade to Sphinx-Gallery 0.1.4 * Don't run flake8 on Sphinx-Gallery * Sphinx-Gallery loads the stylesheet not the layout * Delete old css file of the gallery * Incorporate scikit-learn css to wrap download buttons * flake8 message that sphinx-gallery is not checked
1 parent cefd3ca commit 1054e07

File tree

12 files changed

+535
-265
lines changed

12 files changed

+535
-265
lines changed

build_tools/travis/flake8_diff.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ echo '--------------------------------------------------------------------------
106106
# uses git 1.8.
107107
# We need the following command to exit with 0 hence the echo in case
108108
# there is no match
109-
MODIFIED_FILES=$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' || echo "no_match")
109+
MODIFIED_FILES=$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' | \
110+
grep -v 'doc/sphinxext/sphinx_gallery' || echo "no_match")
110111

111112
if [[ "$MODIFIED_FILES" == "no_match" ]]; then
112-
echo "No file outside sklearn/externals has been modified"
113+
echo "No file outside sklearn/externals and doc/sphinxext/sphinx_gallery has been modified"
113114
else
114115
# Conservative approach: diff without context so that code that
115116
# was not changed does not create failures

doc/sphinxext/sphinx_gallery/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
"""
77
import os
8-
__version__ = '0.1.2'
8+
__version__ = '0.1.4'
99

1010

1111
def glr_path_static():

doc/sphinxext/sphinx_gallery/_static/gallery.css

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
Sphinx-Gallery is has compatible CSS to fix default sphinx themes
2+
Sphinx-Gallery has compatible CSS to fix default sphinx themes
33
Tested for Sphinx 1.3.1 for all themes: default, alabaster, sphinxdoc,
44
scrolls, agogo, traditional, nature, haiku, pyramid
5-
Tested for Read the docs theme 0.1.7 */
5+
Tested for Read the Docs theme 0.1.7 */
66
.sphx-glr-thumbcontainer {
77
background: #fff;
88
border: solid #fff 1px;
@@ -103,16 +103,33 @@ thumbnail with its default link Background color */
103103
blockquote.sphx-glr-script-out {
104104
margin-left: 0pt;
105105
}
106-
.sphx-glr-download {
106+
div.sphx-glr-download {
107+
display: inline-block;
108+
margin: 1em auto 1ex 2ex;
109+
}
110+
111+
div.sphx-glr-download a {
107112
background-color: #ffc;
108-
border: 1px solid #c2c22d;
113+
background-image: linear-gradient(to bottom, #FFC, #d5d57e);
109114
border-radius: 4px;
110-
margin: 1em auto 1ex auto;
115+
border: 1px solid #c2c22d;
116+
color: #000;
117+
display: inline-block;
118+
font-weight: bold;
111119
max-width: 45ex;
112120
padding: 1ex;
121+
text-align: center;
122+
}
123+
124+
div.sphx-glr-download code.download {
125+
display: inline-block;
113126
}
114-
.sphx-glr-download a {
115-
color: #4b4600;
127+
128+
div.sphx-glr-download a:hover {
129+
box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 1px 5px rgba(0,0,0,.25);
130+
text-decoration: none;
131+
background-image: none;
132+
background-color: #d5d57e;
116133
}
117134

118135
ul.sphx-glr-horizontal {
@@ -125,3 +142,12 @@ ul.sphx-glr-horizontal li {
125142
ul.sphx-glr-horizontal img {
126143
height: auto !important;
127144
}
145+
146+
p.sphx-glr-signature a.reference.external {
147+
background-color: #EBECED;
148+
-moz-border-radius: 5px;
149+
-webkit-border-radius: 5px;
150+
border-radius: 5px;
151+
padding: 3px;
152+
font-size: 75%;
153+
}

doc/sphinxext/sphinx_gallery/backreferences.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_short_module_name(module_name, obj_name):
7575
short_name = '.'.join(parts[:i])
7676
try:
7777
exec('from %s import %s' % (short_name, obj_name))
78-
except ImportError:
78+
except Exception: # libraries can throw all sorts of exceptions...
7979
# get the last working module name
8080
short_name = '.'.join(parts[:(i + 1)])
8181
break

doc/sphinxext/sphinx_gallery/docs_resolv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
# Try Python 2 first, otherwise load from Python 3
1515
try:
16-
from StringIO import StringIO
1716
import cPickle as pickle
1817
import urllib2 as urllib
1918
from urllib2 import HTTPError, URLError
2019
except ImportError:
21-
from io import StringIO
2220
import pickle
2321
import urllib.request
2422
import urllib.error
2523
import urllib.parse
2624
from urllib.error import HTTPError, URLError
2725

26+
from io import StringIO
27+
2828

2929
def _get_data(url):
3030
"""Helper function to get data over http or from a local file"""
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# -*- coding: utf-8 -*-
2+
r"""
3+
Utilities for downloadable items
4+
================================
5+
6+
"""
7+
# Author: Óscar Nájera
8+
# License: 3-clause BSD
9+
10+
from __future__ import absolute_import, division, print_function
11+
12+
import os
13+
import zipfile
14+
15+
CODE_DOWNLOAD = """
16+
\n.. container:: sphx-glr-download
17+
18+
:download:`Download Python source code: {0} <{0}>`\n
19+
20+
\n.. container:: sphx-glr-download
21+
22+
:download:`Download Jupyter notebook: {1} <{1}>`\n"""
23+
24+
CODE_ZIP_DOWNLOAD = """
25+
\n.. container:: sphx-glr-download
26+
27+
:download:`Download all examples in Python source code: {0} </{1}>`\n
28+
29+
\n.. container:: sphx-glr-download
30+
31+
:download:`Download all examples in Jupyter notebook files: {2} </{3}>`\n"""
32+
33+
34+
def python_zip(file_list, gallery_path, extension='.py'):
35+
"""Stores all files in file_list into an zip file
36+
37+
Parameters
38+
----------
39+
file_list : list of strings
40+
Holds all the file names to be included in zip file
41+
gallery_path : string
42+
path to where the zipfile is stored
43+
extension : str
44+
'.py' or '.ipynb' In order to deal with downloads of python
45+
sources and jupyter notebooks the file extension from files in
46+
file_list will be removed and replace with the value of this
47+
variable while generating the zip file
48+
Returns
49+
-------
50+
zipname : string
51+
zip file name, written as `target_dir_{python,jupyter}.zip`
52+
depending on the extension
53+
"""
54+
zipname = gallery_path.replace(os.path.sep, '_')
55+
zipname += '_python' if extension == '.py' else '_jupyter'
56+
zipname = os.path.join(gallery_path, zipname + '.zip')
57+
58+
zipf = zipfile.ZipFile(zipname, mode='w')
59+
for fname in file_list:
60+
file_src = os.path.splitext(fname)[0] + extension
61+
zipf.write(file_src)
62+
zipf.close()
63+
64+
return zipname
65+
66+
67+
def list_downloadable_sources(target_dir):
68+
"""Returns a list of python source files is target_dir
69+
70+
Parameters
71+
----------
72+
target_dir : string
73+
path to the directory where python source file are
74+
Returns
75+
-------
76+
list
77+
list of paths to all Python source files in `target_dir`
78+
"""
79+
return [os.path.join(target_dir, fname)
80+
for fname in os.listdir(target_dir)
81+
if fname.endswith('.py')]
82+
83+
84+
def generate_zipfiles(gallery_dir):
85+
"""
86+
Collects all Python source files and Jupyter notebooks in
87+
gallery_dir and makes zipfiles of them
88+
89+
Parameters
90+
----------
91+
gallery_dir : string
92+
path of the gallery to collect downloadable sources
93+
94+
Return
95+
------
96+
download_rst: string
97+
RestructuredText to include download buttons to the generated files
98+
"""
99+
100+
listdir = list_downloadable_sources(gallery_dir)
101+
for directory in sorted(os.listdir(gallery_dir)):
102+
if os.path.isdir(os.path.join(gallery_dir, directory)):
103+
target_dir = os.path.join(gallery_dir, directory)
104+
listdir.extend(list_downloadable_sources(target_dir))
105+
106+
py_zipfile = python_zip(listdir, gallery_dir)
107+
jy_zipfile = python_zip(listdir, gallery_dir, ".ipynb")
108+
109+
dw_rst = CODE_ZIP_DOWNLOAD.format(os.path.basename(py_zipfile),
110+
py_zipfile,
111+
os.path.basename(jy_zipfile),
112+
jy_zipfile)
113+
return dw_rst

0 commit comments

Comments
 (0)
0