imports where I need

This commit is contained in:
Anthony Scopatz 2016-06-15 22:11:17 -04:00
parent 8a5d41f920
commit d2784efc0a
5 changed files with 128 additions and 100 deletions

View file

@ -323,14 +323,19 @@ def read_exclude(pkg):
FAKE_LOAD = """
import sys as _sys
try:
from {pkg} import __amalgam__
{load}
del __amalgam__
except ImportError:
import os as _os
if _os.getenv('DEBUG', ''):
pass
del _sys
else:
import sys as _sys
try:
from {pkg} import __amalgam__
{load}
del __amalgam__
except ImportError:
pass
del _sys
del _os
""".strip()
@ -342,9 +347,9 @@ def rewrite_init(pkg, order):
stop = i
elif line.startswith('# amalgamate'):
start = i
t = ("{1} = __amalgam__\n "
t = ("{1} = __amalgam__\n "
"_sys.modules['{0}.{1}'] = __amalgam__")
load = '\n '.join(t.format(pkg, m) for m in order)
load = '\n '.join(t.format(pkg, m) for m in order)
s = FAKE_LOAD.format(pkg=pkg, load=load)
if start + 1 == stop:
lines.insert(stop, s)

View file

@ -54,8 +54,11 @@ def build_tables():
from xonsh.parser import Parser
Parser(lexer_table='lexer_table', yacc_table='parser_table',
outputdir='xonsh')
import amalgamate
os.environ['DEBUG'] = '1'
amalgamate.main(['amalgamate', 'xonsh'])
del os.environ['DEBUG']
sys.path.pop(0)

View file

@ -1,87 +1,92 @@
__version__ = '0.3.4'
# amalgamate exclude jupyter_kernel parser_table parser_test_table pyghooks winutils
import sys as _sys
try:
from xonsh import __amalgam__
completer = __amalgam__
_sys.modules['xonsh.completer'] = __amalgam__
lazyasd = __amalgam__
_sys.modules['xonsh.lazyasd'] = __amalgam__
lazyjson = __amalgam__
_sys.modules['xonsh.lazyjson'] = __amalgam__
pretty = __amalgam__
_sys.modules['xonsh.pretty'] = __amalgam__
teepty = __amalgam__
_sys.modules['xonsh.teepty'] = __amalgam__
timings = __amalgam__
_sys.modules['xonsh.timings'] = __amalgam__
ansi_colors = __amalgam__
_sys.modules['xonsh.ansi_colors'] = __amalgam__
codecache = __amalgam__
_sys.modules['xonsh.codecache'] = __amalgam__
openpy = __amalgam__
_sys.modules['xonsh.openpy'] = __amalgam__
platform = __amalgam__
_sys.modules['xonsh.platform'] = __amalgam__
jobs = __amalgam__
_sys.modules['xonsh.jobs'] = __amalgam__
parser = __amalgam__
_sys.modules['xonsh.parser'] = __amalgam__
tokenize = __amalgam__
_sys.modules['xonsh.tokenize'] = __amalgam__
tools = __amalgam__
_sys.modules['xonsh.tools'] = __amalgam__
vox = __amalgam__
_sys.modules['xonsh.vox'] = __amalgam__
ast = __amalgam__
_sys.modules['xonsh.ast'] = __amalgam__
contexts = __amalgam__
_sys.modules['xonsh.contexts'] = __amalgam__
diff_history = __amalgam__
_sys.modules['xonsh.diff_history'] = __amalgam__
dirstack = __amalgam__
_sys.modules['xonsh.dirstack'] = __amalgam__
foreign_shells = __amalgam__
_sys.modules['xonsh.foreign_shells'] = __amalgam__
inspectors = __amalgam__
_sys.modules['xonsh.inspectors'] = __amalgam__
lexer = __amalgam__
_sys.modules['xonsh.lexer'] = __amalgam__
proc = __amalgam__
_sys.modules['xonsh.proc'] = __amalgam__
wizard = __amalgam__
_sys.modules['xonsh.wizard'] = __amalgam__
xontribs = __amalgam__
_sys.modules['xonsh.xontribs'] = __amalgam__
environ = __amalgam__
_sys.modules['xonsh.environ'] = __amalgam__
history = __amalgam__
_sys.modules['xonsh.history'] = __amalgam__
base_shell = __amalgam__
_sys.modules['xonsh.base_shell'] = __amalgam__
replay = __amalgam__
_sys.modules['xonsh.replay'] = __amalgam__
tracer = __amalgam__
_sys.modules['xonsh.tracer'] = __amalgam__
xonfig = __amalgam__
_sys.modules['xonsh.xonfig'] = __amalgam__
aliases = __amalgam__
_sys.modules['xonsh.aliases'] = __amalgam__
readline_shell = __amalgam__
_sys.modules['xonsh.readline_shell'] = __amalgam__
built_ins = __amalgam__
_sys.modules['xonsh.built_ins'] = __amalgam__
execer = __amalgam__
_sys.modules['xonsh.execer'] = __amalgam__
imphooks = __amalgam__
_sys.modules['xonsh.imphooks'] = __amalgam__
shell = __amalgam__
_sys.modules['xonsh.shell'] = __amalgam__
main = __amalgam__
_sys.modules['xonsh.main'] = __amalgam__
del __amalgam__
except ImportError:
import os as _os
if _os.getenv('DEBUG', ''):
pass
del _sys
else:
import sys as _sys
try:
from xonsh import __amalgam__
completer = __amalgam__
_sys.modules['xonsh.completer'] = __amalgam__
lazyasd = __amalgam__
_sys.modules['xonsh.lazyasd'] = __amalgam__
lazyjson = __amalgam__
_sys.modules['xonsh.lazyjson'] = __amalgam__
pretty = __amalgam__
_sys.modules['xonsh.pretty'] = __amalgam__
teepty = __amalgam__
_sys.modules['xonsh.teepty'] = __amalgam__
timings = __amalgam__
_sys.modules['xonsh.timings'] = __amalgam__
ansi_colors = __amalgam__
_sys.modules['xonsh.ansi_colors'] = __amalgam__
codecache = __amalgam__
_sys.modules['xonsh.codecache'] = __amalgam__
openpy = __amalgam__
_sys.modules['xonsh.openpy'] = __amalgam__
platform = __amalgam__
_sys.modules['xonsh.platform'] = __amalgam__
jobs = __amalgam__
_sys.modules['xonsh.jobs'] = __amalgam__
parser = __amalgam__
_sys.modules['xonsh.parser'] = __amalgam__
tokenize = __amalgam__
_sys.modules['xonsh.tokenize'] = __amalgam__
tools = __amalgam__
_sys.modules['xonsh.tools'] = __amalgam__
vox = __amalgam__
_sys.modules['xonsh.vox'] = __amalgam__
ast = __amalgam__
_sys.modules['xonsh.ast'] = __amalgam__
contexts = __amalgam__
_sys.modules['xonsh.contexts'] = __amalgam__
diff_history = __amalgam__
_sys.modules['xonsh.diff_history'] = __amalgam__
dirstack = __amalgam__
_sys.modules['xonsh.dirstack'] = __amalgam__
foreign_shells = __amalgam__
_sys.modules['xonsh.foreign_shells'] = __amalgam__
inspectors = __amalgam__
_sys.modules['xonsh.inspectors'] = __amalgam__
lexer = __amalgam__
_sys.modules['xonsh.lexer'] = __amalgam__
proc = __amalgam__
_sys.modules['xonsh.proc'] = __amalgam__
wizard = __amalgam__
_sys.modules['xonsh.wizard'] = __amalgam__
xontribs = __amalgam__
_sys.modules['xonsh.xontribs'] = __amalgam__
environ = __amalgam__
_sys.modules['xonsh.environ'] = __amalgam__
history = __amalgam__
_sys.modules['xonsh.history'] = __amalgam__
base_shell = __amalgam__
_sys.modules['xonsh.base_shell'] = __amalgam__
replay = __amalgam__
_sys.modules['xonsh.replay'] = __amalgam__
tracer = __amalgam__
_sys.modules['xonsh.tracer'] = __amalgam__
xonfig = __amalgam__
_sys.modules['xonsh.xonfig'] = __amalgam__
aliases = __amalgam__
_sys.modules['xonsh.aliases'] = __amalgam__
readline_shell = __amalgam__
_sys.modules['xonsh.readline_shell'] = __amalgam__
built_ins = __amalgam__
_sys.modules['xonsh.built_ins'] = __amalgam__
execer = __amalgam__
_sys.modules['xonsh.execer'] = __amalgam__
imphooks = __amalgam__
_sys.modules['xonsh.imphooks'] = __amalgam__
shell = __amalgam__
_sys.modules['xonsh.shell'] = __amalgam__
main = __amalgam__
_sys.modules['xonsh.main'] = __amalgam__
del __amalgam__
except ImportError:
pass
del _sys
del _os
# amalgamate end

View file

@ -6,15 +6,14 @@ import sys
import time
import builtins
from xonsh.tools import XonshError, escape_windows_cmd_string, print_exception
from xonsh.tools import (XonshError, escape_windows_cmd_string, print_exception,
DefaultNotSet)
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
from xonsh.codecache import (should_use_cache, code_cache_name,
code_cache_check, get_cache_filename,
update_cache, run_compiled_code)
from xonsh.completer import Completer
from xonsh.environ import multiline_prompt, format_prompt, partial_format_prompt
if HAS_PYGMENTS:
from xonsh.pyghooks import XonshStyle
class _TeeOut(object):
@ -118,11 +117,26 @@ class BaseShell(object):
self.buffer = []
self.need_more_lines = False
self.mlprompt = None
if HAS_PYGMENTS:
env = builtins.__xonsh_env__
self.styler = XonshStyle(env.get('XONSH_COLOR_STYLE'))
else:
self.styler = None
self._styler = DefaultNotGiven
@property
def styler(self):
if self._styler is DefaultNotGiven:
if HAS_PYGMENTS:
from xonsh.pyghooks import XonshStyle
env = builtins.__xonsh_env__
self._styler = XonshStyle(env.get('XONSH_COLOR_STYLE'))
else:
self._styler = None
return self._styler
@styler.setter
def styler(self, value):
self._styler = value
@styler.deleter
def styler(self):
self._styler = DefaultNotGiven
def emptyline(self):
"""Called when an empty line has been entered."""

View file

@ -19,7 +19,8 @@ import types
import importlib
from xonsh.lazyasd import LazyObject
from xonsh.openpy import detect_encoding, read_py_file
from xonsh.tokenize import detect_encoding
from xonsh.openpy import read_py_file
from xonsh.tools import (cast_unicode, safe_hasattr, indent,
print_color, format_color)
from xonsh.platform import HAS_PYGMENTS, PYTHON_VERSION_INFO