mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 19:30:29 +00:00
simplify some functions in _bootstrap_external
This commit is contained in:
parent
17c7dafb1c
commit
66ab4d84d3
1 changed files with 17 additions and 64 deletions
|
@ -98,8 +98,7 @@ def _path_isfile(path):
|
||||||
|
|
||||||
def _path_isdir(path):
|
def _path_isdir(path):
|
||||||
"""Replacement for os.path.isdir."""
|
"""Replacement for os.path.isdir."""
|
||||||
if not path:
|
path = path or _os.getcwd()
|
||||||
path = _os.getcwd()
|
|
||||||
return _path_is_mode_type(path, 0o040000)
|
return _path_is_mode_type(path, 0o040000)
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,15 +396,11 @@ def _check_name(method):
|
||||||
raise ImportError('loader for %s cannot handle %s' %
|
raise ImportError('loader for %s cannot handle %s' %
|
||||||
(self.name, name), name=name)
|
(self.name, name), name=name)
|
||||||
return method(self, name, *args, **kwargs)
|
return method(self, name, *args, **kwargs)
|
||||||
try:
|
def _wrap(new, old):
|
||||||
_wrap = _bootstrap._wrap
|
for replace in ['__module__', '__name__', '__qualname__', '__doc__']:
|
||||||
except NameError:
|
if hasattr(old, replace):
|
||||||
# XXX yuck
|
setattr(new, replace, getattr(old, replace))
|
||||||
def _wrap(new, old):
|
new.__dict__.update(old.__dict__)
|
||||||
for replace in ['__module__', '__name__', '__qualname__', '__doc__']:
|
|
||||||
if hasattr(old, replace):
|
|
||||||
setattr(new, replace, getattr(old, replace))
|
|
||||||
new.__dict__.update(old.__dict__)
|
|
||||||
_wrap(_check_name_wrapper, method)
|
_wrap(_check_name_wrapper, method)
|
||||||
return _check_name_wrapper
|
return _check_name_wrapper
|
||||||
|
|
||||||
|
@ -1345,14 +1340,10 @@ def _fix_up_module(ns, name, pathname, cpathname=None):
|
||||||
loader = SourceFileLoader(name, pathname)
|
loader = SourceFileLoader(name, pathname)
|
||||||
if not spec:
|
if not spec:
|
||||||
spec = spec_from_file_location(name, pathname, loader=loader)
|
spec = spec_from_file_location(name, pathname, loader=loader)
|
||||||
try:
|
ns['__spec__'] = spec
|
||||||
ns['__spec__'] = spec
|
ns['__loader__'] = loader
|
||||||
ns['__loader__'] = loader
|
ns['__file__'] = pathname
|
||||||
ns['__file__'] = pathname
|
ns['__cached__'] = cpathname
|
||||||
ns['__cached__'] = cpathname
|
|
||||||
except Exception:
|
|
||||||
# Not important enough to report.
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _get_supported_file_loaders():
|
def _get_supported_file_loaders():
|
||||||
|
@ -1378,61 +1369,23 @@ def _setup(_bootstrap_module):
|
||||||
sys = _bootstrap.sys
|
sys = _bootstrap.sys
|
||||||
_imp = _bootstrap._imp
|
_imp = _bootstrap._imp
|
||||||
|
|
||||||
|
builtin_from_name = _bootstrap._builtin_from_name
|
||||||
# Directly load built-in modules needed during bootstrap.
|
# Directly load built-in modules needed during bootstrap.
|
||||||
self_module = sys.modules[__name__]
|
self_module = sys.modules[__name__]
|
||||||
for builtin_name in ('_io', '_warnings', 'builtins', 'marshal'):
|
for builtin_name in ('_io', '_warnings', 'builtins', 'marshal', 'posix', '_weakref'):
|
||||||
if builtin_name not in sys.modules:
|
setattr(self_module, builtin_name, sys.modules.get(builtin_name, builtin_from_name(builtin_name)))
|
||||||
builtin_module = _bootstrap._builtin_from_name(builtin_name)
|
|
||||||
else:
|
|
||||||
builtin_module = sys.modules[builtin_name]
|
|
||||||
setattr(self_module, builtin_name, builtin_module)
|
|
||||||
|
|
||||||
# Directly load the os module (needed during bootstrap).
|
# Directly load the os module (needed during bootstrap).
|
||||||
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
|
os_details = ('posix', ['/']), ('nt', ['\\', '/'])
|
||||||
for builtin_os, path_separators in os_details:
|
builtin_os, path_separators = os_details[0]
|
||||||
# Assumption made in _path_join()
|
setattr(self_module, '_os', sys.modules.get(builtin_os, builtin_from_name(builtin_os)))
|
||||||
assert all(len(sep) == 1 for sep in path_separators)
|
setattr(self_module, 'path_sep', path_separators[0])
|
||||||
path_sep = path_separators[0]
|
|
||||||
if builtin_os in sys.modules:
|
|
||||||
os_module = sys.modules[builtin_os]
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
os_module = _bootstrap._builtin_from_name(builtin_os)
|
|
||||||
break
|
|
||||||
except ImportError:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise ImportError('importlib requires posix or nt')
|
|
||||||
setattr(self_module, '_os', os_module)
|
|
||||||
setattr(self_module, 'path_sep', path_sep)
|
|
||||||
setattr(self_module, 'path_separators', ''.join(path_separators))
|
setattr(self_module, 'path_separators', ''.join(path_separators))
|
||||||
|
setattr(self_module, '_thread', None)
|
||||||
# Directly load the _thread module (needed during bootstrap).
|
|
||||||
try:
|
|
||||||
thread_module = _bootstrap._builtin_from_name('_thread')
|
|
||||||
except ImportError:
|
|
||||||
# Python was built without threads
|
|
||||||
thread_module = None
|
|
||||||
setattr(self_module, '_thread', thread_module)
|
|
||||||
|
|
||||||
# Directly load the _weakref module (needed during bootstrap).
|
|
||||||
weakref_module = _bootstrap._builtin_from_name('_weakref')
|
|
||||||
setattr(self_module, '_weakref', weakref_module)
|
|
||||||
|
|
||||||
# Directly load the winreg module (needed during bootstrap).
|
|
||||||
if builtin_os == 'nt':
|
|
||||||
winreg_module = _bootstrap._builtin_from_name('winreg')
|
|
||||||
setattr(self_module, '_winreg', winreg_module)
|
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
setattr(self_module, '_relax_case', _make_relax_case())
|
setattr(self_module, '_relax_case', _make_relax_case())
|
||||||
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
|
EXTENSION_SUFFIXES.extend(_imp.extension_suffixes())
|
||||||
if builtin_os == 'nt':
|
|
||||||
SOURCE_SUFFIXES.append('.pyw')
|
|
||||||
if '_d.pyd' in EXTENSION_SUFFIXES:
|
|
||||||
WindowsRegistryFinder.DEBUG_BUILD = True
|
|
||||||
|
|
||||||
|
|
||||||
def _install(_bootstrap_module):
|
def _install(_bootstrap_module):
|
||||||
"""Install the path-based import components."""
|
"""Install the path-based import components."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue