[info] using python internal tomllib

This commit is contained in:
wendtalexander 2024-10-11 14:10:43 +02:00
parent f7cfc96dde
commit 1332e067c6

View File

@ -1,29 +1,26 @@
import tomlkit
import tomllib
import pathlib
def load_project_settings(project_root):
print(project_root)
# Read the pyproject.toml file
with open(pathlib.Path.joinpath(project_root, "pyproject.toml"), "r") as f:
pyproject_content = f.read()
pyproject_path = pathlib.Path.joinpath(project_root, "pyproject.toml")
with open(pyproject_path, "rb") as f:
pyproject_content = tomllib.load(f)
# 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["project"]["organization"],
"classifiers": pyproject["tool"]["poetry"]["classifiers"],
"copyright": pyproject["project"]["copyright"],
"repository": pyproject["tool"]["poetry"]["repository"],
info_dict = {
"name": pyproject_content["tool"]["poetry"]["name"],
"version": pyproject_content["tool"]["poetry"]["version"],
"description": pyproject_content["tool"]["poetry"]["description"],
"authors": pyproject_content["tool"]["poetry"]["authors"],
"readme": pyproject_content["tool"]["poetry"]["authors"],
"licence": pyproject_content["tool"]["poetry"]["license"],
"organization": pyproject_content["project"]["organization"],
"classifiers": pyproject_content["tool"]["poetry"]["classifiers"],
"copyright": pyproject_content["project"]["copyright"],
"repository": pyproject_content["tool"]["poetry"]["repository"],
}
return info_dict
_root = pathlib.Path(__file__).parent.parent