|
14 | 14 |
|
15 | 15 | import os
|
16 | 16 | import re
|
17 |
| -import shutil |
18 | 17 | import sys
|
19 | 18 |
|
20 | 19 | from recommonmark.transform import AutoStructify
|
21 | 20 |
|
22 |
| -# Work around https://github.com/readthedocs/recommonmark/issues/152 |
23 |
| -new_readme = [] |
| 21 | +# -- |
| 22 | +# Copy README.md, CONTRIBUTING.md to source/ directory and replace |
| 23 | +# all paths to point github files. |
| 24 | +def _copy_with_converting_link_to_repo(filename, new_filename): |
| 25 | + base_url = 'https://github.com/kubernetes-client/python/blob/master/' |
24 | 26 |
|
25 |
| -with open("../../README.md", "r") as r: |
26 |
| - lines = r.readlines() |
27 |
| - for l in lines: |
28 |
| - nl = re.sub("\[!\[[\w\s]+\]\(", "[ |
29 |
| - new_readme.append(nl) |
| 27 | + def subf(subs): |
| 28 | + label, url = subs.groups() |
| 29 | + if not url.startswith('http://') and not url.startswith('https://'): |
| 30 | + url = base_url + url |
| 31 | + return label + '(' + url + ')' |
30 | 32 |
|
31 |
| -with open("README.md", "w") as n: |
32 |
| - n.writelines(new_readme) |
| 33 | + with open(filename, "r") as r: |
| 34 | + data = re.sub("(\[[^\]]+\])\(([^\)]+)\)", subf, r.read()) |
33 | 35 |
|
34 |
| -# apparently index.rst can't search for markdown not in the same directory |
35 |
| -shutil.copy("../../CONTRIBUTING.md", ".") |
| 36 | + with open(new_filename, "w") as w: |
| 37 | + w.write(data) |
| 38 | + |
| 39 | +_copy_with_converting_link_to_repo("../../README.md", "README.md") |
| 40 | +_copy_with_converting_link_to_repo("../../CONTRIBUTING.md", "CONTRIBUTING.md") |
| 41 | +# -- |
36 | 42 |
|
37 | 43 | sys.path.insert(0, os.path.abspath('../..'))
|
38 | 44 | # -- General configuration ----------------------------------------------------
|
|
0 commit comments