Change stuff

This commit is contained in:
Justine Tunney 2021-08-17 10:20:55 -07:00
parent 0c6581f912
commit f66ef5d58e
7 changed files with 895 additions and 6766 deletions

View file

@ -4,7 +4,7 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
#if 1 #if 0
#define ZTRACE(FMT, ...) (dprintf)(2, FMT "\n", ##__VA_ARGS__) #define ZTRACE(FMT, ...) (dprintf)(2, FMT "\n", ##__VA_ARGS__)
#else #else
#define ZTRACE(FMT, ...) (void)0 #define ZTRACE(FMT, ...) (void)0

View file

@ -525,27 +525,25 @@ def execusercustomize():
def main(): def main():
"""Add standard site-specific directories to the module search path. """Add standard site-specific directories to the module search path.
This function is called automatically when this module is imported, This function is called automatically when this module is imported,
unless the python interpreter was started with the -S flag. unless the python interpreter was started with the -S flag.
""" """
# global ENABLE_USER_SITE global ENABLE_USER_SITE
abs_paths()
# abs_paths() known_paths = removeduppaths()
# known_paths = removeduppaths() known_paths = venv(known_paths)
# known_paths = venv(known_paths) if ENABLE_USER_SITE is None:
# if ENABLE_USER_SITE is None: ENABLE_USER_SITE = check_enableusersite()
# ENABLE_USER_SITE = check_enableusersite() known_paths = addusersitepackages(known_paths)
# known_paths = addusersitepackages(known_paths) known_paths = addsitepackages(known_paths)
# known_paths = addsitepackages(known_paths) setquit()
# setquit() setcopyright()
# setcopyright() sethelper()
# sethelper() if not sys.flags.isolated:
# if not sys.flags.isolated: enablerlcompleter()
# enablerlcompleter() execsitecustomize()
# execsitecustomize() if ENABLE_USER_SITE:
# if ENABLE_USER_SITE: execusercustomize()
# execusercustomize()
# Prevent extending of sys.path when python was started with -S and # Prevent extending of sys.path when python was started with -S and
# site is imported later. # site is imported later.

View file

@ -466,11 +466,154 @@ search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home,
static void static void
calculate_path(void) calculate_path(void)
{ {
#if 1
static wchar_t delimiter[2] = {DELIM, '\0'};
static wchar_t separator[2] = {SEP, '\0'};
/* ignore PYTHONPATH/PYTHONHOME for now */
// char *_rtpypath = Py_GETENV("PYTHONPATH");
/* XXX use wide version on Windows */
// wchar_t *rtpypath = NULL;
// wchar_t *home = Py_GetPythonHome();
char *_path = getenv("PATH");
wchar_t *path_buffer = NULL;
wchar_t *path = NULL;
wchar_t *prog = Py_GetProgramName();
wchar_t argv0_path[MAXPATHLEN+1];
/* wont need zip_path because embedded stdlib inside executable */
/* wchar_t zip_path[MAXPATHLEN+1]; */
wchar_t *buf;
size_t bufsz;
wchar_t ape_path[MAXPATHLEN+1];
size_t ape_length;
wchar_t ape_lib_path[MAXPATHLEN+1];
wchar_t ape_exec_path[MAXPATHLEN+1];
wchar_t package_path[MAXPATHLEN+1];
wchar_t ape_package_path[MAXPATHLEN+1];
if(IsWindows())
{
delimiter[0] = L';';
separator[0] = L'\\';
}
if (_path) {
path_buffer = Py_DecodeLocale(_path, NULL);
path = path_buffer;
}
/* If there is no slash in the argv0 path, then we have to
* assume python is on the user's $PATH, since there's no
* other way to find a directory to start the search from. If
* $PATH isn't exported, you lose.
*/
if (wcschr(prog, SEP))
wcsncpy(progpath, prog, MAXPATHLEN);
else if (path) {
while (1) {
wchar_t *delim = wcschr(path, DELIM);
if (delim) {
size_t len = delim - path;
if (len > MAXPATHLEN)
len = MAXPATHLEN;
wcsncpy(progpath, path, len);
*(progpath + len) = '\0';
}
else
wcsncpy(progpath, path, MAXPATHLEN);
joinpath(progpath, prog);
if (isxfile(progpath))
break;
if (!delim) {
progpath[0] = L'\0';
break;
}
path = delim + 1;
}
}
else
progpath[0] = '\0';
PyMem_RawFree(path_buffer);
if (progpath[0] != SEP && progpath[0] != '\0')
absolutize(progpath);
wcsncpy(argv0_path, progpath, MAXPATHLEN);
argv0_path[MAXPATHLEN] = '\0';
reduce(argv0_path);
/* At this point, argv0_path is guaranteed to be less than
MAXPATHLEN bytes long.
*/
/* not searching for pyvenv.cfg */
/* Avoid absolute path for prefix */
wcsncpy(prefix,
L"third_party/python/Lib",
MAXPATHLEN);
/* wcsncpy(prefix, */
/* L"zip!third_party/python/Lib/", */
/* MAXPATHLEN); */
/* Avoid absolute path for exec_prefix */
wcsncpy(exec_prefix, L"build/lib.linux-x86_64-3.6", MAXPATHLEN);
wcsncpy(package_path, L"Lib/site-packages", MAXPATHLEN);
// printf("progpath = %ls, prog = %ls\n", progpath, prog);
/* add paths for the internal store of the APE */
if(wcslen(progpath) > 0 && wcslen(progpath) + 1 < MAXPATHLEN)
wcsncpy(ape_path, progpath, MAXPATHLEN);
else
wcsncpy(ape_path, prog, MAXPATHLEN);
ape_length = wcslen(ape_path);
wcsncpy(ape_lib_path, ape_path, MAXPATHLEN);
// extra 1 at the start for the slash
if(ape_length + 1 + wcslen(prefix) + 1 < MAXPATHLEN)
{
ape_lib_path[ape_length] = L'/';
wcscat(ape_lib_path + ape_length + 1, prefix);
}
wcsncpy(ape_exec_path, ape_path, MAXPATHLEN);
if(ape_length + 1 + wcslen(exec_prefix) + 1 < MAXPATHLEN)
{
ape_exec_path[ape_length] = L'/';
wcscat(ape_exec_path + ape_length + 1, exec_prefix);
}
wcsncpy(ape_package_path, ape_path, MAXPATHLEN);
if(ape_length + 1 + wcslen(package_path) + 1 < MAXPATHLEN)
{
ape_package_path[ape_length] = L'/';
wcscat(ape_package_path + ape_length + 1, package_path);
}
/* Calculate size of return buffer */
bufsz = 0;
bufsz += wcslen(ape_lib_path) + 1;
bufsz += wcslen(ape_exec_path) + 1;
bufsz += wcslen(ape_package_path) + 1;
bufsz += wcslen(ape_path) + 1;
bufsz += wcslen(prefix) + 1;
bufsz += wcslen(exec_prefix) + 1;
bufsz += wcslen(package_path) + 1;
/* This is the only malloc call in this file */
buf = PyMem_RawMalloc(bufsz * sizeof(wchar_t));
if (buf == NULL) {
Py_FatalError(
"Not enough memory for dynamic PYTHONPATH");
}
buf[0] = L'\0';
wcscat(buf, prefix);
wcscat(buf, delimiter);
wcscat(buf, package_path);
wcscat(buf, delimiter);
wcscat(buf, ape_lib_path);
wcscat(buf, delimiter);
wcscat(buf, ape_package_path);
wcscat(buf, delimiter);
wcscat(buf, ape_exec_path);
wcscat(buf, delimiter);
wcscat(buf, ape_path);
wcscat(buf, delimiter);
/* Finally, on goes the directory for dynamic-load modules */
wcscat(buf, exec_prefix);
/* And publish the results */
module_search_path = buf;
// printf("%ls\n", buf);
#else
module_search_path = L"zip!.python/"; module_search_path = L"zip!.python/";
/* module_search_path = L"third_party/python/Lib/"; */ module_search_path = L"third_party/python/Lib/";
#endif
} }
/* External interface */ /* External interface */
void void
Py_SetPath(const wchar_t *path) Py_SetPath(const wchar_t *path)

View file

@ -4,6 +4,7 @@
Python 3 Python 3
https://docs.python.org/3/license.html │ https://docs.python.org/3/license.html │
*/ */
#include "libc/stdio/stdio.h"
#include "libc/unicode/locale.h" #include "libc/unicode/locale.h"
#include "third_party/python/Include/Python-ast.h" #include "third_party/python/Include/Python-ast.h"
#include "third_party/python/Include/abstract.h" #include "third_party/python/Include/abstract.h"

File diff suppressed because it is too large Load diff

View file

@ -437,6 +437,7 @@ o/$(MODE)/third_party/python/python.com.dbg: \
$(THIRD_PARTY_PYTHON_A_DEPS) \ $(THIRD_PARTY_PYTHON_A_DEPS) \
$(THIRD_PARTY_PYTHON_A) \ $(THIRD_PARTY_PYTHON_A) \
$(THIRD_PARTY_PYTHON_STDLIB_PY_OBJS) \ $(THIRD_PARTY_PYTHON_STDLIB_PY_OBJS) \
$(THIRD_PARTY_PYTHON_STDLIB_PYC_OBJS) \
o/$(MODE)/third_party/python/Programs/python.o \ o/$(MODE)/third_party/python/Programs/python.o \
$(CRT) \ $(CRT) \
$(APE) $(APE)
@ -455,11 +456,11 @@ o/$(MODE)/third_party/python/pycomp.com.dbg: \
$(APE) $(APE)
-@$(APELINK) -@$(APELINK)
o/$(MODE)/third_party/python/freeze.com.dbg: \ o/$(MODE)/third_party/python/freeze.com.dbg: \
$(THIRD_PARTY_PYTHON_A_DEPS) \ $(THIRD_PARTY_PYTHON_A_DEPS) \
$(THIRD_PARTY_PYTHON_A) \ $(THIRD_PARTY_PYTHON_A) \
o/$(MODE)/third_party/python/Programs/_freeze_importlib.o \ o/$(MODE)/third_party/python/Programs/freeze.o \
$(CRT) \ $(CRT) \
$(APE) $(APE)
-@$(APELINK) -@$(APELINK)