|
10 | 10 | # add these directories to sys.path here. If the directory is relative to the
|
11 | 11 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
12 | 12 | #
|
| 13 | +from ast import parse as ast_parse, iter_child_nodes, Assign, Constant, Name |
13 | 14 | from json import loads
|
14 | 15 | from os.path import abspath
|
15 | 16 | from pathlib import Path
|
|
21 | 22 | sys_path.insert(0, abspath('_extensions'))
|
22 | 23 | #sys_path.insert(0, os.path.abspath('_themes/sphinx_rtd_theme'))
|
23 | 24 |
|
24 |
| - |
25 |
| -# ============================================================================== |
26 |
| -# Project information |
27 |
| -# ============================================================================== |
28 |
| -project = 'pyTooling.TerminalUI' |
29 |
| -copyright = '2007-2021, Patrick Lehmann' |
30 |
| -author = 'Patrick Lehmann' |
31 |
| - |
32 | 25 | # ==============================================================================
|
33 |
| -# Versioning |
| 26 | +# Project information and versioning |
34 | 27 | # ==============================================================================
|
35 | 28 | # The version info for the project you're documenting, acts as replacement for
|
36 | 29 | # |version| and |release|, also used in various other places throughout the
|
37 | 30 | # built documents.
|
38 |
| -from subprocess import check_output |
| 31 | +project = "pyTooling.TerminalUI" |
| 32 | + |
| 33 | +__author = None |
| 34 | +__copyright = None |
| 35 | +__version = None |
| 36 | + |
| 37 | +# Read __version__ from source file |
| 38 | +versionFile = Path(f"../{project.replace('.', '/')}/__init__.py") |
| 39 | +with versionFile.open("r") as file: |
| 40 | + for item in iter_child_nodes(ast_parse(file.read())): |
| 41 | + if isinstance(item, Assign) and len(item.targets) == 1: |
| 42 | + target = item.targets[0] |
| 43 | + value = item.value |
| 44 | + if isinstance(target, Name) and target.id == "__author__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 45 | + __author = value.value |
| 46 | + if isinstance(target, Name) and target.id == "__copyright__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 47 | + __copyright = value.value |
| 48 | + if isinstance(target, Name) and target.id == "__version__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 49 | + __version = value.value |
| 50 | +if __version is None: |
| 51 | + raise AssertionError(f"Could not extract '__version__' from '{versionFile}'.") |
| 52 | + |
| 53 | +author = __author |
| 54 | +copyright = __copyright |
| 55 | +version = ".".join(__version.split(".")[:2]) # e.g. 2.3 The short X.Y version. |
| 56 | +release = __version |
39 | 57 |
|
40 |
| -def _IsUnderGitControl(): |
41 |
| - return (check_output(["git", "rev-parse", "--is-inside-work-tree"], universal_newlines=True).strip() == "true") |
42 |
| - |
43 |
| -def _LatestTagName(): |
44 |
| - return check_output(["git", "describe", "--abbrev=0", "--tags"], universal_newlines=True).strip() |
45 |
| - |
46 |
| -# The full version, including alpha/beta/rc tags |
47 |
| -version = "1.5" # The short X.Y version. |
48 |
| -release = "1.5.2" # The full version, including alpha/beta/rc tags. |
49 |
| -try: |
50 |
| - if _IsUnderGitControl: |
51 |
| - latestTagName = _LatestTagName()[1:] # remove prefix "v" |
52 |
| - versionParts = latestTagName.split("-")[0].split(".") |
53 |
| - |
54 |
| - version = ".".join(versionParts[:2]) |
55 |
| - release = latestTagName # ".".join(versionParts[:3]) |
56 |
| -except: |
57 |
| - pass |
58 | 58 |
|
59 | 59 | # ==============================================================================
|
60 | 60 | # Miscellaneous settings
|
|
0 commit comments