2
0
forked from awendt/pyrelacs

[project] add info.py that reads the project toml file to set application information

This commit is contained in:
Jan Grewe 2024-09-27 09:12:56 +02:00
parent 938d70fbac
commit 6008cc03d6

37
pyrelacs/info.py Normal file
View File

@ -0,0 +1,37 @@
import tomlkit
import pathlib
def load_project_settings(project_root):
# Read the pyproject.toml file
with open(pathlib.Path.joinpath(project_root, 'pyproject.toml'), 'r') as f:
pyproject_content = f.read()
# Parse the toml content
pyproject = tomlkit.parse(pyproject_content)
# Access project settings
return {
'name': pyproject['tool']['poetry']['name'],
'version': pyproject['tool']['poetry']['version'],
'description': pyproject['tool']['poetry']['description'],
'authors': pyproject['tool']['poetry']['authors'],
'readme': pyproject['tool']['poetry']['authors'],
'licence': pyproject['tool']['poetry']['license'],
'organization': pyproject['tool']['poetry']['organization'],
'classifiers': pyproject['tool']['poetry']['classifiers'],
'copyright': pyproject['tool']['poetry']['copyright'],
"repository": pyproject['tool']['poetry']['repository'],
}
_root = pathlib.Path(__file__).parent.parent
_infodict = load_project_settings(_root)
NAME = _infodict["name"]
VERSION = _infodict["version"]
AUTHORS = _infodict["authors"]
COPYRIGHT = _infodict["copyright"]
HOMEPAGE = _infodict["repository"]
CLASSIFIERS = _infodict["classifiers"]
DESCRIPTION = _infodict["description"]
ORGANIZATION = _infodict["organization"]