Merge branch 'master' into hist_ref

This commit is contained in:
laerus 2016-07-25 02:05:35 +03:00
commit 0560d7674e
7 changed files with 86 additions and 8 deletions

View file

@ -8,7 +8,9 @@ from collections import namedtuple
from collections.abc import Mapping from collections.abc import Mapping
from ast import parse, walk, Import, ImportFrom from ast import parse, walk, Import, ImportFrom
ModNode = namedtuple('ModNode', ['name', 'pkgdeps', 'extdeps']) __version__ = '0.1.2'
ModNode = namedtuple('ModNode', ['name', 'pkgdeps', 'extdeps', 'futures'])
ModNode.__doc__ = """Module node for dependency graph. ModNode.__doc__ = """Module node for dependency graph.
Attributes Attributes
@ -19,6 +21,8 @@ pkgdeps : frozenset of str
Module dependencies in the same package. Module dependencies in the same package.
extdeps : frozenset of str extdeps : frozenset of str
External module dependencies from outside of the package. External module dependencies from outside of the package.
futures : frozenset of str
Import directive names antecedent to 'from __future__ import'
""" """
@ -172,6 +176,7 @@ def make_node(name, pkg, allowed, glbnames):
pkgdot = pkg + '.' pkgdot = pkg + '.'
pkgdeps = set() pkgdeps = set()
extdeps = set() extdeps = set()
futures = set()
glbnames.module = name glbnames.module = name
for a in tree.body: for a in tree.body:
glbnames.add(a, istopnode=True) glbnames.add(a, istopnode=True)
@ -194,7 +199,10 @@ def make_node(name, pkg, allowed, glbnames):
pkgdeps.add(m) pkgdeps.add(m)
else: else:
extdeps.add(a.module) extdeps.add(a.module)
return ModNode(name, frozenset(pkgdeps), frozenset(extdeps)) elif a.module == '__future__':
futures.update(n.name for n in a.names)
return ModNode(name, frozenset(pkgdeps), frozenset(extdeps),
frozenset(futures))
def make_graph(pkg, exclude=None): def make_graph(pkg, exclude=None):
@ -377,6 +385,9 @@ def rewrite_imports(name, pkg, order, imps):
elif a.module.startswith(pkgdot) and p == pkg and m in order: elif a.module.startswith(pkgdot) and p == pkg and m in order:
replacements.append((start, stop, replacements.append((start, stop,
'# amalgamated ' + a.module + '\n')) '# amalgamated ' + a.module + '\n'))
elif a.module == '__future__':
replacements.append((start, stop,
'# amalgamated __future__ directive\n'))
else: else:
keep = [] keep = []
for n in a.names: for n in a.names:
@ -401,12 +412,23 @@ def rewrite_imports(name, pkg, order, imps):
return ''.join(lines) return ''.join(lines)
def sorted_futures(graph):
"""Returns a sorted, unique list of future imports."""
f = set()
for value in graph.values():
f |= value.futures
return sorted(f)
def amalgamate(order, graph, pkg): def amalgamate(order, graph, pkg):
"""Create amalgamated source.""" """Create amalgamated source."""
src = ('\"\"\"Amalgamation of {0} package, made up of the following ' src = ('\"\"\"Amalgamation of {0} package, made up of the following '
'modules, in order:\n\n* ').format(pkg) 'modules, in order:\n\n* ').format(pkg)
src += '\n* '.join(order) src += '\n* '.join(order)
src += '\n\n\"\"\"\n' src += '\n\n\"\"\"\n'
futures = sorted_futures(graph)
if len(futures) > 0:
src += 'from __future__ import ' + ', '.join(futures) + '\n'
src += LAZY_IMPORTS src += LAZY_IMPORTS
imps = set() imps = set()
for name in order: for name in order:

15
news/amalgamation.rst Normal file
View file

@ -0,0 +1,15 @@
**Added:** None
**Changed:**
* Moved ``amalgamate_source`` outside ``build_tables``
* Disable amalgamation on setup develop
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

13
news/futamal.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:**
* amalgamate.py now properly handles ``from __future__`` imports.
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

13
news/jupyter.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* Completions in ``jupyter_kernel.py`` now use updated completion framework
**Security:** None

View file

@ -51,8 +51,9 @@ os.environ['XONSH_DEBUG'] = '1'
from xonsh import __version__ as XONSH_VERSION from xonsh import __version__ as XONSH_VERSION
def amalagamate_source(): def amalgamate_source():
"""Amalgamtes source files.""" """Amalgamates source files."""
sys.path.insert(0, os.path.dirname(__file__))
try: try:
import amalgamate import amalgamate
except ImportError: except ImportError:
@ -60,6 +61,7 @@ def amalagamate_source():
return return
amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh', amalgamate.main(['amalgamate', '--debug=XONSH_DEBUG', 'xonsh',
'xonsh.completers']) 'xonsh.completers'])
sys.path.pop(0)
def build_tables(): def build_tables():
@ -69,7 +71,6 @@ def build_tables():
from xonsh.parser import Parser from xonsh.parser import Parser
Parser(lexer_table='lexer_table', yacc_table='parser_table', Parser(lexer_table='lexer_table', yacc_table='parser_table',
outputdir='xonsh') outputdir='xonsh')
amalagamate_source()
sys.path.pop(0) sys.path.pop(0)
@ -164,6 +165,7 @@ class xinstall(install):
def run(self): def run(self):
clean_tables() clean_tables()
build_tables() build_tables()
amalgamate_source()
# add dirty version number # add dirty version number
dirty = dirty_version() dirty = dirty_version()
# install Jupyter hook # install Jupyter hook
@ -185,6 +187,7 @@ class xsdist(sdist):
def make_release_tree(self, basedir, files): def make_release_tree(self, basedir, files):
clean_tables() clean_tables()
build_tables() build_tables()
amalgamate_source()
dirty = dirty_version() dirty = dirty_version()
sdist.make_release_tree(self, basedir, files) sdist.make_release_tree(self, basedir, files)
if dirty: if dirty:

View file

@ -9,6 +9,7 @@ from ipykernel.kernelbase import Kernel
from xonsh import __version__ as version from xonsh import __version__ as version
from xonsh.main import main_context from xonsh.main import main_context
from xonsh.tools import redirect_stdout, redirect_stderr, swap from xonsh.tools import redirect_stdout, redirect_stderr, swap
from xonsh.completer import Completer
MAX_SIZE = 8388608 # 8 Mb MAX_SIZE = 8388608 # 8 Mb
@ -28,6 +29,10 @@ class XonshKernel(Kernel):
'file_extension': '.xsh', 'file_extension': '.xsh',
} }
def __init__(self, **kwargs):
self.completer = Completer()
super().__init__(**kwargs)
def do_execute(self, code, silent, store_history=True, user_expressions=None, def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False): allow_stdin=False):
"""Execute user code.""" """Execute user code."""
@ -96,8 +101,13 @@ class XonshKernel(Kernel):
def do_complete(self, code, pos): def do_complete(self, code, pos):
"""Get completions.""" """Get completions."""
shell = builtins.__xonsh_shell__ shell = builtins.__xonsh_shell__
comps, beg, end = shell.completer.find_and_complete(code, pos, shell.ctx) line = code.split('\n')[-1]
message = {'matches': comps, 'cursor_start': beg, 'cursor_end': end+1, prefix = line.split(' ')[-1]
endidx = pos
begidx = pos - len(prefix)
rtn, _ = self.completer.complete(prefix, line, begidx,
endidx, shell.ctx)
message = {'matches': rtn, 'cursor_start': begidx, 'cursor_end': endidx,
'metadata': {}, 'status': 'ok'} 'metadata': {}, 'status': 'ok'}
return message return message

View file

@ -10,6 +10,8 @@ import importlib
import importlib.util import importlib.util
import collections.abc as abc import collections.abc as abc
__version__ = '0.1.1'
class LazyObject(object): class LazyObject(object):
@ -285,7 +287,7 @@ class BackgroundModuleLoader(threading.Thread):
time.sleep(0.001) time.sleep(0.001)
last = hist[i % 5] = len(sys.modules) last = hist[i % 5] = len(sys.modules)
i += 1 i += 1
# now import pkg_resources properly # now import module properly
modname = importlib.util.resolve_name(self.name, self.package) modname = importlib.util.resolve_name(self.name, self.package)
if isinstance(sys.modules[modname], BackgroundModuleProxy): if isinstance(sys.modules[modname], BackgroundModuleProxy):
del sys.modules[modname] del sys.modules[modname]