diff sat/tools/utils.py @ 3420:b526b95f11f2

tools(utils): fixed error catching when getting repository data with `pkg_resources`
author Goffi <goffi@goffi.org>
date Mon, 16 Nov 2020 14:44:43 +0100
parents e86b71b1aa31
children be6d91572633
line wrap: on
line diff
--- a/sat/tools/utils.py	Sun Nov 15 17:05:47 2020 +0100
+++ b/sat/tools/utils.py	Mon Nov 16 14:44:43 2020 +0100
@@ -248,33 +248,35 @@
         log.debug("Mercurial not available or working, trying package version")
         try:
             import pkg_resources
-
-            pkg_version = pkg_resources.get_distribution(C.APP_NAME_FILE).version
-            version, local_id = pkg_version.split("+", 1)
         except ImportError:
             log.warning("pkg_resources not available, can't get package data")
-        except pkg_resources.DistributionNotFound:
-            log.warning("can't retrieve package data")
-        except ValueError:
-            log.info(
-                "no local version id in package: {pkg_version}".format(
-                    pkg_version=pkg_version
-                )
-            )
         else:
-            version = version.replace(".dev0", "D")
-            if version != C.APP_VERSION:
-                log.warning(
-                    "Incompatible version ({version}) and pkg_version ({pkg_version})".format(
-                        version=C.APP_VERSION, pkg_version=pkg_version
+            try:
+                pkg_version = pkg_resources.get_distribution(C.APP_NAME_FILE).version
+                version, local_id = pkg_version.split("+", 1)
+            except pkg_resources.DistributionNotFound:
+                log.warning("can't retrieve package data")
+            except ValueError:
+                log.info(
+                    "no local version id in package: {pkg_version}".format(
+                        pkg_version=pkg_version
                     )
                 )
             else:
-                try:
-                    hg_node, hg_distance = local_id.split(".")
-                except ValueError:
-                    log.warning("Version doesn't specify repository data")
-                hg_data = {"node_short": hg_node, "distance": hg_distance}
+                version = version.replace(".dev0", "D")
+                if version != C.APP_VERSION:
+                    log.warning(
+                        "Incompatible version ({version}) and pkg_version ({pkg_version})"
+                        .format(
+                            version=C.APP_VERSION, pkg_version=pkg_version
+                        )
+                    )
+                else:
+                    try:
+                        hg_node, hg_distance = local_id.split(".")
+                    except ValueError:
+                        log.warning("Version doesn't specify repository data")
+                    hg_data = {"node_short": hg_node, "distance": hg_distance}
 
     repos_cache_dict = hg_data