From 6008cc03d6c6e103e1228acaf22b57df8664367a Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Fri, 27 Sep 2024 09:12:56 +0200 Subject: [PATCH] [project] add info.py that reads the project toml file to set application information --- pyrelacs/info.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pyrelacs/info.py diff --git a/pyrelacs/info.py b/pyrelacs/info.py new file mode 100644 index 0000000..5d5c9a8 --- /dev/null +++ b/pyrelacs/info.py @@ -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"]