mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
seems to work
This commit is contained in:
parent
115a095647
commit
502f1a6627
5 changed files with 54 additions and 1 deletions
|
@ -150,7 +150,7 @@ class _LazyModule(_ModuleType):
|
|||
pkg = dct['pkg']
|
||||
asname = dct['asname']
|
||||
if asname is None:
|
||||
glbs[pkg] = _modules[pkg]
|
||||
glbs[pkg] = m = _modules[pkg]
|
||||
else:
|
||||
glbs[asname] = m
|
||||
dct['loaded'] = True
|
||||
|
|
|
@ -9,6 +9,8 @@ else:
|
|||
import sys as _sys
|
||||
try:
|
||||
from xonsh import __amalgam__
|
||||
bg_pkg_resources = __amalgam__
|
||||
_sys.modules['xonsh.bg_pkg_resources'] = __amalgam__
|
||||
completer = __amalgam__
|
||||
_sys.modules['xonsh.completer'] = __amalgam__
|
||||
lazyasd = __amalgam__
|
||||
|
|
44
xonsh/bg_pkg_resources.py
Normal file
44
xonsh/bg_pkg_resources.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
"""Background thread loader for pkg_resources."""
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import builtins
|
||||
import threading
|
||||
import importlib
|
||||
|
||||
|
||||
class PkgResourcesLoader(threading.Thread):
|
||||
"""Thread to load the pkg_resources module."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.daemon = True
|
||||
self.start()
|
||||
|
||||
def run(self):
|
||||
# wait for other modules to stop being imported
|
||||
i = 0
|
||||
last = -6
|
||||
hist = [-5, -4, -3, -2, -1]
|
||||
while not all(last == x for x in hist):
|
||||
time.sleep(0.001)
|
||||
last = hist[i%5] = len(sys.modules)
|
||||
i += 1
|
||||
# now import pkg_resources properly
|
||||
if sys.modules['pkg_resources'] is None:
|
||||
del sys.modules['pkg_resources']
|
||||
pr = importlib.import_module('pkg_resources')
|
||||
if 'pygments.plugin' in sys.modules:
|
||||
sys.modules['pygments.plugin'].pkg_resources = pr
|
||||
|
||||
|
||||
def load_pkg_resources_in_background():
|
||||
"""Entry point for loading pkg_resources module in background."""
|
||||
if 'pkg_resources' in sys.modules:
|
||||
return
|
||||
env = getattr(builtins, '__xonsh_env__', os.environ)
|
||||
if env.get('XONSH_DEBUG', None):
|
||||
import pkg_resources
|
||||
return
|
||||
sys.modules['pkg_resources'] = None
|
||||
PkgResourcesLoader()
|
|
@ -0,0 +1,3 @@
|
|||
# must come before ptk / pygments imports
|
||||
from xonsh.bg_pkg_resources import load_pkg_resources_in_background
|
||||
load_pkg_resources_in_background()
|
|
@ -9,6 +9,10 @@ from warnings import warn
|
|||
from collections import ChainMap
|
||||
from collections.abc import MutableMapping
|
||||
|
||||
# must come before pygments imports
|
||||
from xonsh.bg_pkg_resources import load_pkg_resources_in_background
|
||||
load_pkg_resources_in_background()
|
||||
|
||||
from pygments.lexer import inherit, bygroups, using, this
|
||||
from pygments.lexers.shell import BashLexer
|
||||
from pygments.lexers.agile import PythonLexer
|
||||
|
|
Loading…
Add table
Reference in a new issue