8000 Update to Sphinx-Gallery v0.1.11 (#8222) · amueller/scikit-learn@95b61c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95b61c5

Browse files
committed
Update to Sphinx-Gallery v0.1.11 (scikit-learn#8222)
# Conflicts: # doc/sphinxext/sphinx_gallery/__init__.py # doc/sphinxext/sphinx_gallery/_static/gallery.css # doc/sphinxext/sphinx_gallery/docs_resolv.py # doc/sphinxext/sphinx_gallery/downloads.py # doc/sphinxext/sphinx_gallery/gen_gallery.py # doc/sphinxext/sphinx_gallery/gen_rst.py # doc/sphinxext/sphinx_gallery/notebook.py # doc/sphinxext/sphinx_gallery/py_source_parser.py # doc/themes/scikit-learn/static/nature.css_t
1 parent ad367da commit 95b61c5

File tree

11 files changed

+1050
-453
lines changed

11 files changed

+1050
-453
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236

237237
sphinx_gallery_conf = {
238238
'doc_module': 'sklearn',
239+
'backreferences_dir': os.path.join('modules', 'generated'),
239240
'reference_url': {
240241
'sklearn': None,
241242
'matplotlib': 'http://matplotlib.org',

doc/sphinxext/sphinx_gallery/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
==============
32
Sphinx Gallery
43
==============
54
65
"""
76
import os
8-
__version__ = '0.1.2'
7+
__version__ = '0.1.11'
98

109

1110
def glr_path_static():

doc/sphinxext/sphinx_gallery/_static/gallery.css

Lines changed: 73 additions & 8 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,70 @@ thumbnail with its default link Background color */
103103
blockquote.sphx-glr-script-out {
104104
margin-left: 0pt;
105105
}
106-
.sphx-glr-download {
106+
107+
div.sphx-glr-footer {
108+
text-align: center;
109+
}
110+
111+
div.sphx-glr-download {
112+
display: inline-block;
113+
margin: 1em auto 1ex 2ex;
114+
vertical-align: middle;
115+
}
116+
117+
div.sphx-glr-download a {
107118
background-color: #ffc;
108-
border: 1px solid #c2c22d;
119+
background-image: linear-gradient(to bottom, #FFC, #d5d57e);
109120
border-radius: 4px;
110-
margin: 1em auto 1ex auto;
111-
max-width: 45ex;
121+
border: 1px solid #c2c22d;
122+
color: #000;
123+
display: inline-block;
124+
/* Not valid in old browser, hence we keep the line above to override */
125+
display: table-caption;
126+
font-weight: bold;
112127
padding: 1ex;
128+
text-align: center;
129+
}
130+
131+
/* The last child of a download button is the file name */
132+
div.sphx-glr-download a span:last-child {
133+
font-size: smaller;
134+
}
135+
136+
@media (min-width: 20em) {
137+
div.sphx-glr-download a {
138+
min-width: 10em;
139+
}
140+
}
141+
142+
@media (min-width: 30em) {
143+
div.sphx-glr-download a {
144+
min-width: 13em;
145+
}
146+
}
147+
148+
@media (min-width: 40em) {
149+
div.sphx-glr-download a {
150+
min-width: 16em;
151+
}
152+
}
153+
154+
155+
div.sphx-glr-download code.download {
156+
display: inline-block;
157+
white-space: normal;
158+
word-break: normal;
159+
overflow-wrap: break-word;
160+
/* border and background are given by the enclosing 'a' */
161+
border: none;
162+
background: none;
113163
}
114-
.sphx-glr-download a {
115-
color: #4b4600;
164+
165+
div.sphx-glr-download a:hover {
166+
box-shadow: inset 0 1px 0 rgba(255,255,255,.1), 0 1px 5px rgba(0,0,0,.25);
167+
text-decoration: none;
168+
background-image: none;
169+
background-color: #d5d57e;
116170
}
117171

118172
ul.sphx-glr-horizontal {
@@ -125,3 +179,14 @@ ul.sphx-glr-horizontal li {
125179
ul.sphx-glr-horizontal img {
126180
height: auto !important;
127181
}
182+
183+
p.sphx-glr-signature a.reference.external {
184+
-moz-border-radius: 5px;
185+
-webkit-border-radius: 5px;
186+
border-radius: 5px;
187+
padding: 3px;
188+
font-size: 75%;
189+
text-align: right;
190+
margin-left: auto;
191+
display: table;
192+
}

doc/sphinxext/sphinx_gallery/backreferences.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
# Author: Óscar Nájera
33
# License: 3-clause BSD
44
"""
5-
========================
65
Backreferences Generator
76
========================
87
9-
Reviews generated example files in order to keep track of used modules
8+
Parses example file code in order to keep track of used functions
109
"""
1110

1211
from __future__ import print_function
@@ -97,7 +96,10 @@ def identify_names(code):
9796
e.HelloWorld HelloWorld d d
9897
"""
9998
finder = NameFinder()
100-
finder.visit(ast.parse(code))
99+
try:
100+
finder.visit(ast.parse(code))
101+
except SyntaxError:
102+
return {}
101103

102104
example_code_obj = {}
103105
for name, full_name in finder.get_mapping():
@@ -154,6 +156,10 @@ def _thumbnail_div(full_dir, fname, snippet, is_backref=False):
154156
"""Generates RST to place a thumbnail in a gallery"""
155157
thumb = os.path.join(full_dir, 'images', 'thumb',
156158
'sphx_glr_%s_thumb.png' % fname[:-3])
159+
160+
# Inside rst files forward slash defines paths
161+
thumb = thumb.replace(os.sep, "/")
162+
157163
ref_name = os.path.join(full_dir, fname).replace(os.path.sep, '_')
158164

159165
template = BACKREF_THUMBNAIL_TEMPLATE if is_backref else THUMBNAIL_TEMPLATE
@@ -164,17 +170,22 @@ def write_backreferences(seen_backrefs, gallery_conf,
164170
target_dir, fname, snippet):
165171
"""Writes down back reference files, which include a thumbnail list
166172
of examples using a certain module"""
173+
if gallery_conf['backreferences_dir'] is None:
174+
return
175+
167176
example_file = os.path.join(target_dir, fname)
177+
build_target_dir = os.path.relpath(target_dir, gallery_conf['src_dir'])
168178
backrefs = scan_used_functions(example_file, gallery_conf)
169179
for backref in backrefs:
170-
include_path = os.path.join(gallery_conf['mod_example_dir'],
180+
include_path = os.path.join(gallery_conf['src_dir'],
181+
gallery_conf['backreferences_dir'],
171182
'%s.examples' % backref)
172183
seen = backref in seen_backrefs
173184
with open(include_path, 'a' if seen else 'w') as ex_file:
174185
if not seen:
175186
heading = '\n\nExamples using ``%s``' % backref
176187
ex_file.write(heading + '\n')
177188
ex_file.write('^' * len(heading) + '\n')
178-
ex_file.write(_thumbnail_div(target_dir, fname, snippet,
189+
ex_file.write(_thumbnail_div(build_target_dir, fname, snippet,
179190
is_backref=True))
180191
seen_backrefs.add(backref)

0 commit comments

Comments
 (0)
0