Minimize Python startup imports (#292)

* get_exports_list should return list
* remove unintentional `CC=clang` in makefile
* avoid importing sysconfig during startup

site.py requires only a couple of functions from sysconfig, but needs to
load the entirety of sysconfig to get those functions. This commit
makes it such that sysconfig is imported only when sys.platform is darwin.

* remove redundant constants from stat module

The constants are only there in case the C implementation (ie the _stat
module) is not available. With Cosmopolitan the _stat module is always
available. The entire Lib/stat.py file can be removed if the Windows-based
constants can be moved into the Modules/_stat.c.

* minimal changes to os.py

python checks os-based assumptions at startup, some of  which can be
bypassed since this is Cosmopolitan Python.
This commit is contained in:
Gautham 2021-10-26 02:34:04 +05:30 committed by GitHub
parent 253ac31a64
commit 49db877fbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 185 deletions

View file

@ -38,24 +38,15 @@ def _exists(name):
return name in globals()
def _get_exports_list(module):
try:
return list(module.__all__)
except AttributeError:
return [n for n in dir(module) if n[0] != '_']
return list(getattr(module, "__all__", (n for n in dir(module) if n[0] != '_')))
name = 'posix'
linesep = '\n'
from posix import *
try:
from posix import _exit
__all__.append('_exit')
except ImportError:
pass
from posix import _exit
__all__.append('_exit')
import posixpath as path
try:
from posix import _have_functions
except ImportError:
pass
from posix import _have_functions
import posix
__all__.extend(_get_exports_list(posix))
del posix
@ -67,7 +58,7 @@ from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
del _names
if _exists("_have_functions"):
if True or _exists("_have_functions"):
_globals = globals()
def _add(str, fn):
if (fn in _globals) and (str in _have_functions):