Replaces the various repeated format strings throughout the code.
# 'with' statements.
ignored-classes=NominatimArgs,closing
# 'too-many-ancestors' is triggered already by deriving from UserDict
-disable=too-few-public-methods,duplicate-code,too-many-ancestors
+disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value
good-names=i,x,y,fd,db
def nominatim_version_text():
""" Program name and version number as string
"""
- text = 'Nominatim version %s.%s.%s.%s' % version.NOMINATIM_VERSION
+ text = f'Nominatim version {version.version_str()}'
if version.GIT_COMMIT_HASH is not None:
- text += ' (%s)' % version.GIT_COMMIT_HASH
+ text += f' ({version.GIT_COMMIT_HASH})'
return text
def add_subcommand(self, name, cmd):
from nominatim.db.connection import connect
from nominatim.db import status, properties
-from nominatim.version import NOMINATIM_VERSION
+from nominatim.version import version_str
# Do not repeat documentation of subcommand classes.
# pylint: disable=C0111
except Exception as exc: # pylint: disable=broad-except
LOG.error('Cannot determine date of database: %s', exc)
- properties.set_property(conn, 'database_version',
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(NOMINATIM_VERSION))
+ properties.set_property(conn, 'database_version', version_str())
import urllib.request as urlrequest
from urllib.parse import urlencode
-from nominatim.version import NOMINATIM_VERSION
+from nominatim.version import version_str
from nominatim.db.connection import get_pg_env
LOG = logging.getLogger()
def get_url(url):
""" Get the contents from the given URL and return it as a UTF-8 string.
"""
- headers = {"User-Agent": "Nominatim/{0[0]}.{0[1]}.{0[2]}-{0[3]}".format(NOMINATIM_VERSION)}
+ headers = {"User-Agent": f"Nominatim/{version_str()}"}
try:
with urlrequest.urlopen(urlrequest.Request(url, headers=headers)) as response:
from nominatim.db import properties
from nominatim.db.connection import connect
-from nominatim.version import NOMINATIM_VERSION
+from nominatim.version import NOMINATIM_VERSION, version_str
from nominatim.tools import refresh
from nominatim.tokenizer import factory as tokenizer_factory
from nominatim.errors import UsageError
for version, func in _MIGRATION_FUNCTIONS:
if db_version <= version:
LOG.warning("Runnning: %s (%s)", func.__doc__.split('\n', 1)[0],
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(version))
+ '{}.{}.{}-{}'.format(*version))
kwargs = dict(conn=conn, config=config, paths=paths)
func(**kwargs)
conn.commit()
tokenizer = tokenizer_factory.get_tokenizer_for_db(config)
tokenizer.update_sql_functions(config)
- properties.set_property(conn, 'database_version',
- '{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(NOMINATIM_VERSION))
+ properties.set_property(conn, 'database_version', version_str())
conn.commit()
from nominatim.db.utils import execute_file
from nominatim.db.sql_preprocessor import SQLPreprocessor
-from nominatim.version import NOMINATIM_VERSION
+from nominatim.version import version_str
LOG = logging.getLogger()
LOG.info('Creating website directory.')
basedir.mkdir()
- template = dedent("""\
+ template = dedent(f"""\
<?php
@define('CONST_Debug', $_GET['debug'] ?? false);
- @define('CONST_LibDir', '{0}');
- @define('CONST_TokenizerDir', '{2}');
- @define('CONST_NominatimVersion', '{1[0]}.{1[1]}.{1[2]}-{1[3]}');
+ @define('CONST_LibDir', '{config.lib_dir.php}');
+ @define('CONST_TokenizerDir', '{config.project_dir / 'tokenizer'}');
+ @define('CONST_NominatimVersion', '{version_str()}');
- """.format(config.lib_dir.php, NOMINATIM_VERSION,
- config.project_dir / 'tokenizer'))
+ """)
for php_name, conf_name, var_type in PHP_CONST_DEFS:
varout = _quote_php_variable(var_type, config, conf_name)
# cmake/tool-installed.tmpl is used to build the binary 'nominatim'. Inside
# there is a call to set the variable value below.
GIT_COMMIT_HASH = None
+
+
+# pylint: disable=consider-using-f-string
+def version_str():
+ """
+ Return a human-readable string of the version.
+ """
+ return '{}.{}.{}-{}'.format(*NOMINATIM_VERSION)