Cleanup version computation, add gisaf.__version__
This commit is contained in:
parent
a3a2efe471
commit
8d34c450e3
2 changed files with 20 additions and 33 deletions
|
@ -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")
|
|
@ -14,25 +14,7 @@ from pydantic_settings import (
|
||||||
YamlConfigSettingsSource,
|
YamlConfigSettingsSource,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from gisaf import __version__
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -48,12 +30,8 @@ config_files = [
|
||||||
|
|
||||||
class DashboardHome(BaseModel):
|
class DashboardHome(BaseModel):
|
||||||
title: str = "Gisaf - home/dashboards"
|
title: str = "Gisaf - home/dashboards"
|
||||||
content_file: Path = (
|
content_file: Path = Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_content.html"
|
||||||
Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_content.html"
|
footer_file: Path = Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_footer.html"
|
||||||
)
|
|
||||||
footer_file: Path = (
|
|
||||||
Path(Path.cwd().root) / "etc" / "gisaf" / "dashboard_home_footer.html"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GisafConfig(BaseModel):
|
class GisafConfig(BaseModel):
|
||||||
|
@ -141,7 +119,9 @@ class DB(BaseModel):
|
||||||
echo: bool = False
|
echo: bool = False
|
||||||
|
|
||||||
def get_sqla_url(self):
|
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):
|
def get_pg_url(self):
|
||||||
return f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}"
|
return f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}"
|
||||||
|
@ -223,9 +203,7 @@ class OGCAPI(BaseModel):
|
||||||
class TileServer(BaseModel):
|
class TileServer(BaseModel):
|
||||||
baseDir: Path = Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_files_dir"
|
baseDir: Path = Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_files_dir"
|
||||||
useRequestUrl: bool = False
|
useRequestUrl: bool = False
|
||||||
spriteBaseDir: Path = (
|
spriteBaseDir: Path = Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_sprites_dir"
|
||||||
Path(BaseDirectory.xdg_data_home) / "gisaf" / "mbtiles_sprites_dir"
|
|
||||||
)
|
|
||||||
spriteUrl: str = "/tiles/sprite/sprite"
|
spriteUrl: str = "/tiles/sprite/sprite"
|
||||||
spriteBaseUrl: str = "https://gisaf.example.org"
|
spriteBaseUrl: str = "https://gisaf.example.org"
|
||||||
openMapTilesKey: str | None = None
|
openMapTilesKey: str | None = None
|
||||||
|
@ -332,9 +310,7 @@ class Config(BaseSettings):
|
||||||
dotenv_settings: PydanticBaseSettingsSource,
|
dotenv_settings: PydanticBaseSettingsSource,
|
||||||
file_secret_settings: PydanticBaseSettingsSource,
|
file_secret_settings: PydanticBaseSettingsSource,
|
||||||
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
||||||
configs = [
|
configs = [YamlConfigSettingsSource(settings_cls, yaml_file=cf) for cf in config_files]
|
||||||
YamlConfigSettingsSource(settings_cls, yaml_file=cf) for cf in config_files
|
|
||||||
]
|
|
||||||
return (
|
return (
|
||||||
env_settings,
|
env_settings,
|
||||||
init_settings,
|
init_settings,
|
||||||
|
@ -370,7 +346,7 @@ class Config(BaseSettings):
|
||||||
plot: Plot = Plot()
|
plot: Plot = Plot()
|
||||||
plugins: dict[str, dict[str, Any]] = {}
|
plugins: dict[str, dict[str, Any]] = {}
|
||||||
survey: Survey = Survey()
|
survey: Survey = Survey()
|
||||||
version: str = get_version()
|
version: str = __version__
|
||||||
weather_station: dict[str, dict[str, Any]] = {}
|
weather_station: dict[str, dict[str, Any]] = {}
|
||||||
widgets: Widgets = Widgets()
|
widgets: Widgets = Widgets()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue