comparison 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
comparison
equal deleted inserted replaced
3419:ccb2a7e66f7d 3420:b526b95f11f2
246 246
247 if not hg_data: 247 if not hg_data:
248 log.debug("Mercurial not available or working, trying package version") 248 log.debug("Mercurial not available or working, trying package version")
249 try: 249 try:
250 import pkg_resources 250 import pkg_resources
251
252 pkg_version = pkg_resources.get_distribution(C.APP_NAME_FILE).version
253 version, local_id = pkg_version.split("+", 1)
254 except ImportError: 251 except ImportError:
255 log.warning("pkg_resources not available, can't get package data") 252 log.warning("pkg_resources not available, can't get package data")
256 except pkg_resources.DistributionNotFound: 253 else:
257 log.warning("can't retrieve package data") 254 try:
258 except ValueError: 255 pkg_version = pkg_resources.get_distribution(C.APP_NAME_FILE).version
259 log.info( 256 version, local_id = pkg_version.split("+", 1)
260 "no local version id in package: {pkg_version}".format( 257 except pkg_resources.DistributionNotFound:
261 pkg_version=pkg_version 258 log.warning("can't retrieve package data")
262 ) 259 except ValueError:
263 ) 260 log.info(
264 else: 261 "no local version id in package: {pkg_version}".format(
265 version = version.replace(".dev0", "D") 262 pkg_version=pkg_version
266 if version != C.APP_VERSION:
267 log.warning(
268 "Incompatible version ({version}) and pkg_version ({pkg_version})".format(
269 version=C.APP_VERSION, pkg_version=pkg_version
270 ) 263 )
271 ) 264 )
272 else: 265 else:
273 try: 266 version = version.replace(".dev0", "D")
274 hg_node, hg_distance = local_id.split(".") 267 if version != C.APP_VERSION:
275 except ValueError: 268 log.warning(
276 log.warning("Version doesn't specify repository data") 269 "Incompatible version ({version}) and pkg_version ({pkg_version})"
277 hg_data = {"node_short": hg_node, "distance": hg_distance} 270 .format(
271 version=C.APP_VERSION, pkg_version=pkg_version
272 )
273 )
274 else:
275 try:
276 hg_node, hg_distance = local_id.split(".")
277 except ValueError:
278 log.warning("Version doesn't specify repository data")
279 hg_data = {"node_short": hg_node, "distance": hg_distance}
278 280
279 repos_cache_dict = hg_data 281 repos_cache_dict = hg_data
280 282
281 if as_string: 283 if as_string:
282 if not hg_data: 284 if not hg_data: