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

Skip to content

Commit f273178

Browse files
authored
Merge pull request #8446 from jkseppan/download-depsy-badge
Download the depsy.org badge when building the html documentation
2 parents a95a278 + ee4ec51 commit f273178

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):
@@ -90,10 +91,38 @@ 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+
request = six.moves.urllib.request.urlopen(DEPSY_URL)
111+
try:
112+
data = request.read().decode('utf-8')
113+
with open(DEPSY_PATH, 'w') as output:
114+
output.write(data)
115+
finally:
116+
request.close()
117+
except six.moves.urllib.error.URLError:
118+
shutil.copyfile(DEPSY_DEFAULT, DEPSY_PATH)
119+
120+
93121
def html(buildername='html'):
94122
"""Build Sphinx 'html' target. """
95123
check_build()
96124
generate_frontpage_pngs()
125+
fetch_depsy_badge()
97126

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

0 commit comments

Comments
 (0)