Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a75d55

Browse files
committed
Download the depsy.org badge when building the html documentation
This should avoid the mixed-content warning at https://matplotlib.org where currently only the Depsy badge is loaded via http. Depsy bug: ourresearch/depsy#77
1 parent a95a278 commit 2a75d55

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Loading

doc/_templates/badgesidebar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
<a href="http://depsy.org/package/python/matplotlib">
3-
<img src="http://depsy.org/api/package/pypi/matplotlib/badge.svg">
3+
<img src="{{ pathto('_static/depsy_badge.svg', 1) }}">
44
</a>
55

66
<br/>

doc/make.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import argparse
1111
import subprocess
1212
import matplotlib
13+
import six
1314

1415

1516
def copy_if_out_of_date(original, derived):
@@ -90,10 +91,35 @@ def generate_frontpage_pngs(only_if_needed=True):
9091
os.rename(fn_png, pn_png) # move file to _static/ directory
9192

9293

94+
DEPSY_PATH = "_static/depsy_badge.svg"
95+
DEPSY_URL = "http://depsy.org/api/package/pypi/matplotlib/badge.svg"
96+
DEPSY_DEFAULT = "_static/depsy_badge_default.svg"
97+
98+
99+
def fetch_depsy_badge():
100+
"""Fetches a static copy of the depsy badge.
101+
102+
If there is any network error, use a static copy from git.
103+
104+
This is to avoid a mixed-content warning when serving matplotlib.org
105+
over https, see https://github.com/Impactstory/depsy/issues/77
106+
107+
The downside is that the badge only updates when the documentation
108+
is rebuilt."""
109+
try:
110+
with six.moves.urllib.request.urlopen(DEPSY_URL) as request:
111+
data = request.read().decode('utf-8')
112+
with open(DEPSY_PATH, 'w') as output:
113+
output.write(data)
114+
except six.moves.urllib.error.URLError:
115+
shutil.copyfile(DEPSY_DEFAULT, DEPSY_PATH)
116+
117+
93118
def html(buildername='html'):
94119
"""Build Sphinx 'html' target. """
95120
check_build()
96121
generate_frontpage_pngs()
122+
fetch_depsy_badge()
97123

98124
rc = '../lib/matplotlib/mpl-data/matplotlibrc'
99125
default_rc = os.path.join(matplotlib._get_data_path(), 'matplotlibrc')

0 commit comments

Comments
 (0)