mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Add support for __all__
in xontribs.
This commit is contained in:
parent
1034612eca
commit
f24f60f946
3 changed files with 19 additions and 3 deletions
|
@ -69,8 +69,8 @@ default, they cannot be unloaded (easily).
|
|||
.. note::
|
||||
|
||||
When a xontrib is loaded from a config file or via the xontrib command,
|
||||
its public variables are placed in the current execution context, just
|
||||
like variables set in run control files.
|
||||
its public variables are placed in the current execution context unless
|
||||
`__all__` is defined, just like in regular Python modules.
|
||||
|
||||
Loading xontribs in the config file is as simple as adding a list of string
|
||||
xontrib names to the top-level ``"xontribs"`` key. For example, the following
|
||||
|
|
13
news/xontrib-all.rst
Normal file
13
news/xontrib-all.rst
Normal file
|
@ -0,0 +1,13 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:**
|
||||
|
||||
* Xontribs may now define ``__all__`` as a module top-level to limit what gets exported to the shell context
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
|
@ -36,7 +36,10 @@ def xontrib_context(name):
|
|||
ImportWarning)
|
||||
return {}
|
||||
m = importlib.import_module(spec.name)
|
||||
ctx = {k: getattr(m, k) for k in dir(m) if not k.startswith('_')}
|
||||
if hasattr(m, '__all__'):
|
||||
ctx = {k: getattr(m, k) for k in m.__all__}
|
||||
else:
|
||||
ctx = {k: getattr(m, k) for k in dir(m) if not k.startswith('_')}
|
||||
return ctx
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue