|
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):
|
@@ -85,10 +86,38 @@ def generate_frontpage_pngs(only_if_needed=True):
|
85 | 86 | os.rename(fn_png, pn_png) # move file to _static/ directory
|
86 | 87 |
|
87 | 88 |
|
| 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 | + |
88 | 116 | def html(buildername='html'):
|
89 | 117 | """Build Sphinx 'html' target. """
|
90 | 118 | check_build()
|
91 | 119 | generate_frontpage_pngs()
|
| 120 | + fetch_depsy_badge() |
92 | 121 |
|
93 | 122 | rc = '../lib/matplotlib/mpl-data/matplotlibrc'
|
94 | 123 | default_rc = os.path.join(matplotlib._get_data_path(), 'matplotlibrc')
|
|
0 commit comments