1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Version information for the Nominatim core package.
10 from typing import NamedTuple, Optional
12 NOMINATIM_CORE_VERSION = '4.4.99'
14 class NominatimVersion(NamedTuple):
15 """ Version information for Nominatim. We follow semantic versioning.
17 Major, minor and patch_level refer to the last released version.
18 The database patch level tracks important changes between releases
19 and must always be increased when there is a change to the database or code
20 that requires a migration.
22 When adding a migration on the development branch, raise the patch level
23 to 99 to make sure that the migration is applied when updating from a
24 patch release to the next minor version. Patch releases usually shouldn't
25 have migrations in them. When they are needed, then make sure that the
26 migration can be reapplied and set the migration version to the appropriate
27 patch level when cherry-picking the commit with the migration.
33 db_patch_level: Optional[int]
35 def __str__(self) -> str:
36 if self.db_patch_level is None:
37 return f"{self.major}.{self.minor}.{self.patch_level}"
39 return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
41 def release_version(self) -> str:
42 """ Return the release version in semantic versioning format.
44 The release version does not include the database patch version.
46 return f"{self.major}.{self.minor}.{self.patch_level}"
49 def parse_version(version: str) -> NominatimVersion:
50 """ Parse a version string into a version consisting of a tuple of
51 four ints: major, minor, patch level, database patch level
53 This is the reverse operation of `version_str()`.
55 parts = version.split('.')
56 return NominatimVersion(*[int(x) for x in parts[:2] + parts[2].split('-')])