Mercurial > libervia-backend
changeset 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 (2020-11-16) |
parents | ccb2a7e66f7d |
children | d42b0bc50594 |
files | sat/tools/utils.py |
diffstat | 1 files changed, 23 insertions(+), 21 deletions(-) [+] |
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