Set version from git for development
This commit is contained in:
parent
4b91badf30
commit
8341a29a36
1 changed files with 23 additions and 2 deletions
|
@ -3,7 +3,7 @@ import logging
|
|||
from pathlib import Path
|
||||
from typing import Any, Type, Tuple
|
||||
from yaml import safe_load
|
||||
from importlib.metadata import version
|
||||
from importlib.metadata import version as importlib_version
|
||||
|
||||
from xdg import BaseDirectory
|
||||
from pydantic import BaseModel
|
||||
|
@ -14,6 +14,27 @@ from pydantic_settings import (
|
|||
YamlConfigSettingsSource,
|
||||
)
|
||||
|
||||
|
||||
def get_version():
|
||||
version = importlib_version("gisaf-backend")
|
||||
if version == "0.0.0":
|
||||
from subprocess import run
|
||||
|
||||
try:
|
||||
v_git_describe = run(
|
||||
["git", "describe", "--always", "--tags", "--dirty"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=Path(__file__).parent.parent,
|
||||
)
|
||||
v_git_describe.check_returncode()
|
||||
version = v_git_describe.stdout.strip()
|
||||
except Exception:
|
||||
logger.warn("Version not set in Python package and cannot determine ")
|
||||
version = "?"
|
||||
return version
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
ENV = environ.get("env", "prod")
|
||||
|
||||
|
@ -349,7 +370,7 @@ class Config(BaseSettings):
|
|||
plot: Plot = Plot()
|
||||
plugins: dict[str, dict[str, Any]] = {}
|
||||
survey: Survey = Survey()
|
||||
version: str = version("gisaf-backend")
|
||||
version: str = get_version()
|
||||
weather_station: dict[str, dict[str, Any]] = {}
|
||||
widgets: Widgets = Widgets()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue