mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
more laziness
This commit is contained in:
parent
80339f5dc4
commit
6f9c442dbc
5 changed files with 721 additions and 2093 deletions
|
@ -126,8 +126,8 @@ class _LazyModule(_ModuleType):
|
|||
self.__dct__ = {
|
||||
'loaded': False,
|
||||
'pkg': pkg, # pkg
|
||||
'mod': mod # pkg.mod
|
||||
'asname': asname # alias
|
||||
'mod': mod, # pkg.mod
|
||||
'asname': asname, # alias
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -372,4 +372,4 @@ def main(args=None):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
3
setup.py
3
setup.py
|
@ -33,7 +33,6 @@ try:
|
|||
except ImportError:
|
||||
HAVE_JUPYTER = False
|
||||
|
||||
from xonsh import __version__ as XONSH_VERSION
|
||||
|
||||
TABLES = ['xonsh/lexer_table.py', 'xonsh/parser_table.py', 'xonsh/__amalgam__.py']
|
||||
|
||||
|
@ -46,6 +45,8 @@ def clean_tables():
|
|||
print('Removed ' + f)
|
||||
|
||||
|
||||
from xonsh import __version__ as XONSH_VERSION
|
||||
|
||||
def build_tables():
|
||||
"""Build the lexer/parser modules."""
|
||||
print('Building lexer and parser tables.')
|
||||
|
|
|
@ -4,12 +4,12 @@ __version__ = '0.3.4'
|
|||
import sys as _sys
|
||||
try:
|
||||
from xonsh import __amalgam__
|
||||
ansi_colors = __amalgam__
|
||||
_sys.modules['xonsh.ansi_colors'] = __amalgam__
|
||||
codecache = __amalgam__
|
||||
_sys.modules['xonsh.codecache'] = __amalgam__
|
||||
completer = __amalgam__
|
||||
_sys.modules['xonsh.completer'] = __amalgam__
|
||||
lazyasd = __amalgam__
|
||||
_sys.modules['xonsh.lazyasd'] = __amalgam__
|
||||
lazyjson = __amalgam__
|
||||
_sys.modules['xonsh.lazyjson'] = __amalgam__
|
||||
openpy = __amalgam__
|
||||
|
@ -22,6 +22,8 @@ try:
|
|||
_sys.modules['xonsh.teepty'] = __amalgam__
|
||||
timings = __amalgam__
|
||||
_sys.modules['xonsh.timings'] = __amalgam__
|
||||
ansi_colors = __amalgam__
|
||||
_sys.modules['xonsh.ansi_colors'] = __amalgam__
|
||||
jobs = __amalgam__
|
||||
_sys.modules['xonsh.jobs'] = __amalgam__
|
||||
parser = __amalgam__
|
||||
|
|
2788
xonsh/ansi_colors.py
2788
xonsh/ansi_colors.py
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
"""Lazy and self destrctive containers for speeding up module import."""
|
||||
import collections.abc as abc
|
||||
|
||||
class LazyAndSelfDestructiveObject(object):
|
||||
class LazyObject(object):
|
||||
|
||||
def __init__(self, load, ctx, name):
|
||||
"""Lazily loads an object via the load function the first time an
|
||||
|
@ -12,8 +12,7 @@ class LazyAndSelfDestructiveObject(object):
|
|||
For example, you can prevent the compilation of a regular expreession
|
||||
until it is actually used::
|
||||
|
||||
DOT = LazyAndSelfDestructiveObject((lambda: re.compile('.')),
|
||||
globals(), 'DOT')
|
||||
DOT = LazyObject((lambda: re.compile('.')), globals(), 'DOT')
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
@ -34,7 +33,7 @@ class LazyAndSelfDestructiveObject(object):
|
|||
}
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name == '_lasdo:
|
||||
if name == '_lasdo':
|
||||
return super().__getattribute__(name)
|
||||
d = self._lasdo
|
||||
if d['loaded']:
|
||||
|
@ -46,7 +45,7 @@ class LazyAndSelfDestructiveObject(object):
|
|||
return getattr(obj, name)
|
||||
|
||||
|
||||
class LazyAndSelfDestructiveDict(abc.MutableMapping):
|
||||
class LazyDict(abc.MutableMapping):
|
||||
|
||||
def __init__(self, loaders, ctx, name):
|
||||
"""Dictionary like object that lazily loads its values from an initial
|
||||
|
@ -58,7 +57,7 @@ class LazyAndSelfDestructiveDict(abc.MutableMapping):
|
|||
For example, you can prevent the compilation of a bunch of regular
|
||||
expressions until they are actually used::
|
||||
|
||||
RES = LazyAndSelfDestructiveDict({
|
||||
RES = LazyDict({
|
||||
'dot': lambda: re.compile('.'),
|
||||
'all': lambda: re.compile('.*'),
|
||||
'two': lambda: re.compile('..'),
|
||||
|
|
Loading…
Add table
Reference in a new issue