|
3 | 3 | # pylint: skip-file
|
4 | 4 |
|
5 | 5 | import os
|
| 6 | +import os.path as osp |
| 7 | +import shutil |
6 | 8 | import sys
|
7 | 9 |
|
8 | 10 | sys.path.insert(0, os.path.abspath(".."))
|
|
11 | 13 |
|
12 | 14 | os.environ["CDL_DOC"] = "1"
|
13 | 15 |
|
| 16 | + |
| 17 | +# -- Copy CHANGELOG.md to doc/contributing folder ------------------------ |
| 18 | +# |
| 19 | +# Note: An alternative to this could be to create a 'contributing/changelog.rst' file |
| 20 | +# containing the following: |
| 21 | +# |
| 22 | +# .. include:: ../../CHANGELOG.md |
| 23 | +# :parser: myst_parser.sphinx_ |
| 24 | +# |
| 25 | +# But, due to the on-the-fly parsing of the markdown file, this alternative approach |
| 26 | +# is not compatible with the internationalization process of the documentation (see |
| 27 | +# https://github.com./DataLab-Platform/DataLab/issues/108). That is why we copy the |
| 28 | +# CHANGELOG.md file to the doc/contributing folder and remove it after the build. |
| 29 | + |
| 30 | + |
| 31 | +def copy_changelog(app): |
| 32 | + """Copy CHANGELOG.md to doc/contributing folder.""" |
| 33 | + docpath = osp.abspath(osp.dirname(__file__)) |
| 34 | + dest_fname = osp.join(docpath, "contributing", "changelog.md") |
| 35 | + if osp.exists(dest_fname): |
| 36 | + os.remove(dest_fname) |
| 37 | + shutil.copyfile(osp.join(docpath, "..", "CHANGELOG.md"), dest_fname) |
| 38 | + app.env.temp_changelog_path = dest_fname |
| 39 | + |
| 40 | + |
| 41 | +def cleanup_changelog(app, exception): |
| 42 | + """Remove CHANGELOG.md from doc/contributing folder.""" |
| 43 | + try: |
| 44 | + path = getattr(app.env, "temp_changelog_path", None) |
| 45 | + if path and osp.exists(path): |
| 46 | + os.remove(path) |
| 47 | + except Exception as exc: |
| 48 | + print(f"Warning: failed to remove {path}: {exc}") |
| 49 | + finally: |
| 50 | + del app.env.temp_changelog_path |
| 51 | + |
| 52 | + |
| 53 | +def setup(app): |
| 54 | + """Setup function for Sphinx.""" |
| 55 | + app.connect("builder-inited", copy_changelog) |
| 56 | + app.connect("build-finished", cleanup_changelog) |
| 57 | + |
| 58 | + |
14 | 59 | # -- Project information -----------------------------------------------------
|
15 | 60 |
|
16 | 61 | project = "DataLab"
|
|
0 commit comments