Skip to content

Commit 9dd5c5b

Browse files
NelleVtacaswell
authored andcommitted
Merge pull request matplotlib#8446 from jkseppan/download-depsy-badge
Download the depsy.org badge when building the html documentation
1 parent 60162b8 commit 9dd5c5b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

doc/_static/depsy_badge_default.svg

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: 29 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):
@@ -85,10 +86,38 @@ def generate_frontpage_pngs(only_if_needed=True):
8586
os.rename(fn_png, pn_png) # move file to _static/ directory
8687

8788

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

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

0 commit comments

Comments
 (0)