]> git.openstreetmap.org Git - nominatim.git/commitdiff
add a function to return a formatted version
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 10 May 2022 21:00:18 +0000 (23:00 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 11 May 2022 07:01:24 +0000 (09:01 +0200)
Replaces the various repeated format strings throughout the code.

.pylintrc
nominatim/cli.py
nominatim/clicmd/setup.py
nominatim/tools/exec_utils.py
nominatim/tools/migration.py
nominatim/tools/refresh.py
nominatim/version.py

index d5c4514fdfbf3650cca0e7aee2503d167bdd6e55..89135138d5c5c183302be40865496c7eef5fd57c 100644 (file)
--- a/.pylintrc
+++ b/.pylintrc
@@ -11,6 +11,6 @@ ignored-modules=icu,datrie
 # '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
index 01eb61190e25d0ecd059052a91bfe73dbce0ed61..f911023b9507fd99fb6115d0c6f015dd9a959088 100644 (file)
@@ -60,9 +60,9 @@ class CommandlineParser:
     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):
index e822cbe51b7a5ba349a14b51e8c8d06093f48995..7968fbcefce40f81684ba79467d101e9c3548077 100644 (file)
@@ -14,7 +14,7 @@ import psutil
 
 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
@@ -213,5 +213,4 @@ class SetupAll:
             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())
index b06b85336a1949b9397b39bfda318bba0829788b..db2a4c2ea05a03c28e5f481ae9cb8923b678a15b 100644 (file)
@@ -12,7 +12,7 @@ import subprocess
 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()
@@ -150,7 +150,7 @@ def run_osm2pgsql(options):
 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:
index 76726e8c59d7ab6d58ca310d77ec41963a04a90f..290016adfefb5d8b252fd345ed7f910e4b00e970 100644 (file)
@@ -11,7 +11,7 @@ import logging
 
 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
@@ -47,7 +47,7 @@ def migrate(config, paths):
         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()
@@ -59,8 +59,7 @@ def migrate(config, paths):
             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()
 
index aacc622b8b634ff284e3f8c0b9c8a105392fd68e..b9a926f221fdea0f214fee663043305b946aa268 100644 (file)
@@ -15,7 +15,7 @@ from psycopg2 import sql as pysql
 
 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()
 
@@ -186,16 +186,15 @@ def setup_website(basedir, config, conn):
         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)
index 47fe3b309e8f2ccab217f54faad430b2cbaff8ff..d4f69da14ff149d57dcec7d77fef82d8360df69e 100644 (file)
@@ -34,3 +34,11 @@ POSTGIS_REQUIRED_VERSION = (2, 2)
 # 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)