|
10 | 10 | import argparse
|
11 | 11 | import subprocess
|
12 | 12 | import matplotlib
|
| 13 | +import six |
13 | 14 |
|
14 | 15 |
|
15 | 16 | def copy_if_out_of_date(original, derived):
|
@@ -90,10 +91,38 @@ def generate_frontpage_pngs(only_if_needed=True):
|
90 | 91 | os.rename(fn_png, pn_png) # move file to _static/ directory
|
91 | 92 |
|
92 | 93 |
|
| 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 | + |
93 | 121 | def html(buildername='html'):
|
94 | 122 | """Build Sphinx 'html' target. """
|
95 | 123 | check_build()
|
96 | 124 | generate_frontpage_pngs()
|
| 125 | + fetch_depsy_badge() |
97 | 126 |
|
98 | 127 | rc = '../lib/matplotlib/mpl-data/matplotlibrc'
|
99 | 128 | default_rc = os.path.join(matplotlib._get_data_path(), 'matplotlibrc')
|
|
0 commit comments