|
29 | 29 | # SPDX-License-Identifier: Apache-2.0 |
30 | 30 | # ============================================================================ |
31 | 31 | # |
| 32 | +from ast import parse as ast_parse, iter_child_nodes, Assign, Constant, Name |
32 | 33 | from pathlib import Path |
33 | 34 | from setuptools import ( |
34 | 35 | setup as setuptools_setup, |
|
37 | 38 |
|
38 | 39 | gitHubNamespace = "pyTooling" |
39 | 40 | projectName = "TerminalUI" |
40 | | -projectNameWithPrefix = "pyTooling." + projectName |
41 | | -version = "1.5.2" |
| 41 | +prefix = "pyTooling" |
| 42 | +projectNameWithPrefix = f"{prefix}.{projectName}" |
| 43 | +__author = None |
| 44 | +__email = None |
| 45 | +__version = None |
| 46 | + |
| 47 | +# Read __version__ from source file |
| 48 | +versionFile = Path(f"{projectName}/__init__.py") |
| 49 | +with versionFile.open("r") as file: |
| 50 | + for item in iter_child_nodes(ast_parse(file.read())): |
| 51 | + if isinstance(item, Assign) and len(item.targets) == 1: |
| 52 | + target = item.targets[0] |
| 53 | + value = item.value |
| 54 | + if isinstance(target, Name) and target.id == "__author__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 55 | + __author = value.value |
| 56 | + if isinstance(target, Name) and target.id == "__email__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 57 | + __email = value.value |
| 58 | + if isinstance(target, Name) and target.id == "__version__" and isinstance(value, Constant) and isinstance(value.value, str): |
| 59 | + __version = value.value |
| 60 | +if __version is None: |
| 61 | + raise AssertionError(f"Could not extract '__version__' from '{versionFile}'.") |
42 | 62 |
|
43 | 63 | # Read README for upload to PyPI |
44 | 64 | readmeFile = Path("README.md") |
|
57 | 77 | # Assemble all package information |
58 | 78 | setuptools_setup( |
59 | 79 | name=projectNameWithPrefix, |
60 | | - version=version, |
61 | | - |
62 | | - author="Patrick Lehmann", |
63 | | - author_email="Paebbels@gmail.com", |
| 80 | + version=__version, |
| 81 | + author=__author, |
| 82 | + author_email=__email, |
64 | 83 | # maintainer="Patrick Lehmann", |
65 | 84 | # maintainer_email="Paebbels@gmail.com", |
66 | | - license='Apache 2.0', |
| 85 | + license='Apache 2.0', |
67 | 86 |
|
68 | 87 | description="A set of helpers to implement a text user interface (TUI) in a terminal.", |
69 | 88 | long_description=long_description, |
|
0 commit comments