Cleanup version computation, add gisaf.__version__
All checks were successful
/ test (push) Successful in 31s
/ build (push) Successful in 2m22s

This commit is contained in:
phil 2025-03-16 19:52:28 +01:00
parent a3a2efe471
commit 8d34c450e3
2 changed files with 20 additions and 33 deletions

View file

@ -0,0 +1,11 @@
import importlib.metadata
try:
from dunamai import Version, Style
__version__ = Version.from_git().serialize(style=Style.SemVer, dirty=True)
except ImportError:
# __name__ could be used if the package name is the same
# as the directory - not the case here
# __version__ = importlib.metadata.version(__name__)
__version__ = importlib.metadata.version("gisaf-backend")

View file

@ -14,25 +14,7 @@ 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 run git describe")
version = "?"
return version
from gisaf import __version__
logger = logging.getLogger(__name__)
@ -48,12 +30,8 @@ config_files = [
class DashboardHome(BaseModel):
title: str = "Gisaf - home/dashboards"
content_file: Path = (
Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_content.html"
)
footer_file: Path = (
Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_footer.html"
)
content_file: Path = Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_content.html"
footer_file: Path = Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_footer.html"
class GisafConfig(BaseModel):
@ -141,7 +119,9 @@ class DB(BaseModel):
echo: bool = False
def get_sqla_url(self):
return f"postgresql+asyncpg://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}"
return (
f"postgresql+asyncpg://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}"
)
def get_pg_url(self):
return f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}"
@ -223,9 +203,7 @@ class OGCAPI(BaseModel):
class TileServer(BaseModel):
baseDir: Path = Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_files_dir"
useRequestUrl: bool = False
spriteBaseDir: Path = (
Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_sprites_dir"
)
spriteBaseDir: Path = Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_sprites_dir"
spriteUrl: str = "/tiles/sprite/sprite"
spriteBaseUrl: str = "https://gisaf.example.org"
openMapTilesKey: str | None = None
@ -332,9 +310,7 @@ class Config(BaseSettings):
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]:
configs = [
YamlConfigSettingsSource(settings_cls, yaml_file=cf) for cf in config_files
]
configs = [YamlConfigSettingsSource(settings_cls, yaml_file=cf) for cf in config_files]
return (
env_settings,
init_settings,
@ -370,7 +346,7 @@ class Config(BaseSettings):
plot: Plot = Plot()
plugins: dict[str, dict[str, Any]] = {}
survey: Survey = Survey()
version: str = get_version()
version: str = __version__
weather_station: dict[str, dict[str, Any]] = {}
widgets: Widgets = Widgets()