From 1999f5e3b355db039e9b7c15ea3eaca760e0644b Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Sat, 16 Oct 2021 01:28:02 +0530 Subject: [PATCH] minimal changes to os.py python checks os-based assumptions at startup, some of which can be bypassed since this is Cosmopolitan Python. --- third_party/python/Lib/os.py | 19 +++++-------------- third_party/python/Modules/posixmodule.c | 2 ++ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/third_party/python/Lib/os.py b/third_party/python/Lib/os.py index e15133af6..48b7bda6e 100644 --- a/third_party/python/Lib/os.py +++ b/third_party/python/Lib/os.py @@ -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 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): diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index 6a67f4c3d..2bb79f0cd 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -78,6 +78,8 @@ PYTHON_PROVIDE("posix"); PYTHON_PROVIDE("posix._getfinalpathname"); +PYTHON_PROVIDE("posix._exit"); +PYTHON_PROVIDE("posix._have_functions"); /* POSIX module implementation */