comparison mercurial/extensions.py @ 48361:0d0ce2529540

extension: add a `required` suboption to enforce the use of an extensions If `required` is set, failing to load an extensions will abort. See the test and documentation for details. Differential Revision: https://phab.mercurial-scm.org/D11822
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 26 Nov 2021 17:17:49 +0100
parents e4acdf5d94a2
children 7e6488aa1261
comparison
equal deleted inserted replaced
48360:e4acdf5d94a2 48361:0d0ce2529540
312 ) 312 )
313 error_msg %= (name, path, msg) 313 error_msg %= (name, path, msg)
314 else: 314 else:
315 error_msg = _(b'failed to import extension "%s": %s') 315 error_msg = _(b'failed to import extension "%s": %s')
316 error_msg %= (name, msg) 316 error_msg %= (name, msg)
317 ui.warn((b"*** %s\n") % error_msg) 317
318 if isinstance(inst, error.Hint) and inst.hint: 318 ext_options = ui.configsuboptions(b"extensions", name)[1]
319 ui.warn(_(b"*** (%s)\n") % inst.hint) 319 if stringutil.parsebool(ext_options.get(b"required", b'no')):
320 ui.traceback() 320 hint = None
321 if isinstance(inst, error.Hint) and inst.hint:
322 hint = inst.hint
323 if hint is None:
324 hint = _(
325 b"loading of this extension was required, "
326 b"see `hg help config.extensions` for details"
327 )
328 raise error.Abort(error_msg, hint=hint)
329 else:
330 ui.warn((b"*** %s\n") % error_msg)
331 if isinstance(inst, error.Hint) and inst.hint:
332 ui.warn(_(b"*** (%s)\n") % inst.hint)
333 ui.traceback()
321 334
322 ui.log( 335 ui.log(
323 b'extension', 336 b'extension',
324 b'> loaded %d extensions, total time %s\n', 337 b'> loaded %d extensions, total time %s\n',
325 len(_order) - newindex, 338 len(_order) - newindex,