mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-07 01:40:58 +01:00
broke everything
This commit is contained in:
parent
c817301eca
commit
e59ad33295
1 changed files with 28 additions and 13 deletions
|
@ -30,10 +30,6 @@ def xontrib_context(name):
|
|||
"""Return a context dictionary for a xontrib of a given name."""
|
||||
spec = find_xontrib(name)
|
||||
if spec is None:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('default', ImportWarning)
|
||||
warnings.warn(prompt_xontrib_install(name),
|
||||
ImportWarning)
|
||||
return {}
|
||||
m = importlib.import_module(spec.name)
|
||||
pubnames = getattr(m, '__all__', None)
|
||||
|
@ -44,24 +40,39 @@ def xontrib_context(name):
|
|||
return ctx
|
||||
|
||||
|
||||
def prompt_xontrib_install(name):
|
||||
def prompt_xontrib_install(names):
|
||||
"""Returns a formatted string with name of xontrib package to prompt user"""
|
||||
md = xontrib_metadata()
|
||||
install_str = ('xontrib "{xontrib}" is not installed. \n'
|
||||
'To install it run \n'
|
||||
' pip install {package}')
|
||||
for xontrib in md['xontribs']:
|
||||
if xontrib['name'] == name:
|
||||
return install_str.format(xontrib=name, package=xontrib['package'])
|
||||
packages = []
|
||||
for name in names:
|
||||
for xontrib in md['xontribs']:
|
||||
if xontrib['name'] == name:
|
||||
packages.append(xontrib['package'])
|
||||
|
||||
warn_str = ('The following xontribs are enabled but not installed: \n'
|
||||
' {xontribs}\n'
|
||||
'To install them run \n'
|
||||
' pip install {packages}').format(xontribs=' '.join(names),
|
||||
packages=' '.join(packages))
|
||||
|
||||
def update_context(name, ctx=None):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('default', ImportWarning)
|
||||
warnings.warn(warn_str, ImportWarning)
|
||||
# return install_str.format(xontrib=name, package=xontrib['package'])
|
||||
|
||||
# install_str = ('xontrib "{xontrib}" is not installed. \n'
|
||||
# 'To install it run \n'
|
||||
# ' pip install {package}')
|
||||
|
||||
def update_context(name, ctx=None, missing_specs=[]):
|
||||
"""Updates a context in place from a xontrib. If ctx is not provided,
|
||||
then __xonsh_ctx__ is updated.
|
||||
"""
|
||||
if ctx is None:
|
||||
ctx = builtins.__xonsh_ctx__
|
||||
modctx = xontrib_context(name)
|
||||
if modctx == {}:
|
||||
missing_specs.append(name)
|
||||
return ctx.update(modctx)
|
||||
|
||||
|
||||
|
@ -76,10 +87,14 @@ def xontrib_metadata():
|
|||
def _load(ns):
|
||||
"""load xontribs"""
|
||||
ctx = builtins.__xonsh_ctx__
|
||||
missing_specs = []
|
||||
for name in ns.names:
|
||||
if ns.verbose:
|
||||
print('loading xontrib {0!r}'.format(name))
|
||||
update_context(name, ctx=ctx)
|
||||
update_context(name, ctx=ctx, missing_specs=missing_specs)
|
||||
print(missing_specs)
|
||||
if missing_specs:
|
||||
prompt_xontrib_install(missing_specs)
|
||||
|
||||
|
||||
def _list(ns):
|
||||
|
|
Loading…
Add table
Reference in a new issue