FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 0b88af1c authored by E. Evstafiev's avatar E. Evstafiev :bulb:
Browse files

feat(settings): add version retrieval from `pyproject.toml`

parent 351c4ac5
No related branches found
No related tags found
1 merge request!52Resolve "Ensure OpenAPI specification is generated correctly"
Pipeline #649608 failed
......@@ -6,6 +6,35 @@ import externalsettings
import structlog
from api.versions import AVAILABLE_VERSIONS
import tomllib
from pathlib import Path
def get_version():
"""
Retrieves the project's version number from pyproject.toml.
This function is intended to ensure that the version is obtained from a
single source of truth (pyproject.toml), avoiding duplication.
Returns:
str: The version number as defined in pyproject.toml (e.g. "0.1.0").
Raises:
FileNotFoundError: If pyproject.toml cannot be found at the expected location.
"""
# Navigate to the pyproject.toml file located in the project root
pyproject_path = Path(__file__).resolve().parents[2] / "pyproject.toml"
# Open and parse the pyproject.toml file using tomllib
with pyproject_path.open("rb") as f:
pyproject_data = tomllib.load(f)
# Return the version number from the [tool.poetry] section
return pyproject_data["tool"]["poetry"]["version"]
# Define the __version__ attribute for the project
__version__ = get_version()
# By default, make use of connection pooling for the default database and use the Postgres engine.
DATABASES = {
......@@ -182,7 +211,7 @@ REST_KNOX = {
SPECTACULAR_SETTINGS = {
"TITLE": "Activate Account",
"DESCRIPTION": "Activate Account API",
"VERSION": "1.0.0",
"VERSION": __version__,
"SERVE_INCLUDE_SCHEMA": False,
"CONTACT": {
"name": "UIS DevOps Division",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment