aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:57 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:57 +0300
commit28148f76dbfcc644d96427d41c92f36cbf2fdc6e (patch)
treeb83306b6e37edeea782e9eed673d89286c4fef35 /library/python/runtime_py3
parente988f30484abe5fdeedcc7a5d3c226c01a21800c (diff)
downloadydb-28148f76dbfcc644d96427d41c92f36cbf2fdc6e.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/python/runtime_py3')
-rw-r--r--library/python/runtime_py3/importer.pxi56
-rw-r--r--library/python/runtime_py3/main/main.c258
-rw-r--r--library/python/runtime_py3/ya.make4
3 files changed, 159 insertions, 159 deletions
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 720153abf6..904f94dea2 100644
--- a/library/python/runtime_py3/importer.pxi
+++ b/library/python/runtime_py3/importer.pxi
@@ -1,7 +1,7 @@
import marshal
import sys
from _codecs import utf_8_decode, utf_8_encode
-from _frozen_importlib import _call_with_frames_removed, spec_from_loader, BuiltinImporter
+from _frozen_importlib import _call_with_frames_removed, spec_from_loader, BuiltinImporter
from _frozen_importlib_external import _os, _path_isfile, _path_isdir, _path_isabs, path_sep, _path_join, _path_split
from _io import FileIO
@@ -186,7 +186,7 @@ class ResourceImporter(object):
else:
self.arcadia_source_finder = None
- for p in list(self.memory) + list(sys.builtin_module_names):
+ for p in list(self.memory) + list(sys.builtin_module_names):
for pp in iter_prefixes(p):
k = pp + '.__init__'
if k not in self.memory:
@@ -207,27 +207,27 @@ class ResourceImporter(object):
def find_spec(self, fullname, path=None, target=None):
try:
- is_package = self.is_package(fullname)
+ is_package = self.is_package(fullname)
except ImportError:
return None
- return spec_from_loader(fullname, self, is_package=is_package)
-
- def find_module(self, fullname, path=None):
- """For backward compatibility."""
- spec = self.find_spec(fullname, path)
- return spec.loader if spec is not None else None
-
- def create_module(self, spec):
- """Use default semantics for module creation."""
-
- def exec_module(self, module):
- code = self.get_code(module.__name__)
+ return spec_from_loader(fullname, self, is_package=is_package)
+
+ def find_module(self, fullname, path=None):
+ """For backward compatibility."""
+ spec = self.find_spec(fullname, path)
+ return spec.loader if spec is not None else None
+
+ def create_module(self, spec):
+ """Use default semantics for module creation."""
+
+ def exec_module(self, module):
+ code = self.get_code(module.__name__)
module.__file__ = code.co_filename
if self.is_package(module.__name__):
module.__path__= [executable + path_sep + module.__name__.replace('.', path_sep)]
# exec(code, module.__dict__)
- _call_with_frames_removed(exec, code, module.__dict__)
-
+ _call_with_frames_removed(exec, code, module.__dict__)
+
# PEP-302 extension 1 of 3: data loader.
def get_data(self, path):
path = _b(path)
@@ -263,7 +263,7 @@ class ResourceImporter(object):
abspath = resfs_resolve(relpath)
if abspath:
return _s(file_bytes(abspath))
- data = resfs_read(mod_path(fullname))
+ data = resfs_read(mod_path(fullname))
return _s(data) if data else ''
def get_code(self, fullname):
@@ -281,8 +281,8 @@ class ResourceImporter(object):
yapyc_path = path + b'.yapyc3'
yapyc_data = resfs_read(yapyc_path, builtin=True)
- if yapyc_data:
- return marshal.loads(yapyc_data)
+ if yapyc_data:
+ return marshal.loads(yapyc_data)
else:
py_data = resfs_read(path, builtin=True)
if py_data:
@@ -385,14 +385,14 @@ class _ResfsResourceReader:
yield _s(res_or_subdir)
-class BuiltinSubmoduleImporter(BuiltinImporter):
- @classmethod
- def find_spec(cls, fullname, path=None, target=None):
- if path is not None:
- return super().find_spec(fullname, None, target)
- else:
- return None
-
+class BuiltinSubmoduleImporter(BuiltinImporter):
+ @classmethod
+ def find_spec(cls, fullname, path=None, target=None):
+ if path is not None:
+ return super().find_spec(fullname, None, target)
+ else:
+ return None
+
class ArcadiaSourceFinder:
"""
diff --git a/library/python/runtime_py3/main/main.c b/library/python/runtime_py3/main/main.c
index 75af2f8cde..3159800615 100644
--- a/library/python/runtime_py3/main/main.c
+++ b/library/python/runtime_py3/main/main.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-#include <locale.h>
+#include <locale.h>
void Py_InitArgcArgv(int argc, wchar_t **argv);
char* GetPyMain();
@@ -24,77 +24,77 @@ void unsetenv(const char* name) {
}
#endif
-static int RunModule(const char *modname)
-{
- PyObject *module, *runpy, *runmodule, *runargs, *result;
- runpy = PyImport_ImportModule("runpy");
- if (runpy == NULL) {
- fprintf(stderr, "Could not import runpy module\n");
- PyErr_Print();
- return -1;
- }
- runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main");
- if (runmodule == NULL) {
- fprintf(stderr, "Could not access runpy._run_module_as_main\n");
- PyErr_Print();
- Py_DECREF(runpy);
- return -1;
- }
- module = PyUnicode_FromString(modname);
- if (module == NULL) {
- fprintf(stderr, "Could not convert module name to unicode\n");
- PyErr_Print();
- Py_DECREF(runpy);
- Py_DECREF(runmodule);
- return -1;
- }
- runargs = Py_BuildValue("(Oi)", module, 0);
- if (runargs == NULL) {
- fprintf(stderr,
- "Could not create arguments for runpy._run_module_as_main\n");
- PyErr_Print();
- Py_DECREF(runpy);
- Py_DECREF(runmodule);
- Py_DECREF(module);
- return -1;
- }
- result = PyObject_Call(runmodule, runargs, NULL);
- if (result == NULL) {
- PyErr_Print();
- }
- Py_DECREF(runpy);
- Py_DECREF(runmodule);
- Py_DECREF(module);
- Py_DECREF(runargs);
- if (result == NULL) {
- return -1;
- }
- Py_DECREF(result);
- return 0;
-}
-
+static int RunModule(const char *modname)
+{
+ PyObject *module, *runpy, *runmodule, *runargs, *result;
+ runpy = PyImport_ImportModule("runpy");
+ if (runpy == NULL) {
+ fprintf(stderr, "Could not import runpy module\n");
+ PyErr_Print();
+ return -1;
+ }
+ runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main");
+ if (runmodule == NULL) {
+ fprintf(stderr, "Could not access runpy._run_module_as_main\n");
+ PyErr_Print();
+ Py_DECREF(runpy);
+ return -1;
+ }
+ module = PyUnicode_FromString(modname);
+ if (module == NULL) {
+ fprintf(stderr, "Could not convert module name to unicode\n");
+ PyErr_Print();
+ Py_DECREF(runpy);
+ Py_DECREF(runmodule);
+ return -1;
+ }
+ runargs = Py_BuildValue("(Oi)", module, 0);
+ if (runargs == NULL) {
+ fprintf(stderr,
+ "Could not create arguments for runpy._run_module_as_main\n");
+ PyErr_Print();
+ Py_DECREF(runpy);
+ Py_DECREF(runmodule);
+ Py_DECREF(module);
+ return -1;
+ }
+ result = PyObject_Call(runmodule, runargs, NULL);
+ if (result == NULL) {
+ PyErr_Print();
+ }
+ Py_DECREF(runpy);
+ Py_DECREF(runmodule);
+ Py_DECREF(module);
+ Py_DECREF(runargs);
+ if (result == NULL) {
+ return -1;
+ }
+ Py_DECREF(result);
+ return 0;
+}
+
static int pymain(int argc, char** argv) {
PyStatus status = _PyRuntime_Initialize();
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
}
- int i, sts = 1;
+ int i, sts = 1;
char* oldloc = NULL;
wchar_t** argv_copy = NULL;
- /* We need a second copies, as Python might modify the first one. */
+ /* We need a second copies, as Python might modify the first one. */
wchar_t** argv_copy2 = NULL;
- char* entry_point_copy = NULL;
-
- if (argc > 0) {
- argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
- argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
- if (!argv_copy || !argv_copy2) {
- fprintf(stderr, "out of memory\n");
- goto error;
- }
- }
-
+ char* entry_point_copy = NULL;
+
+ if (argc > 0) {
+ argv_copy = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
+ argv_copy2 = PyMem_RawMalloc(sizeof(wchar_t*) * argc);
+ if (!argv_copy || !argv_copy2) {
+ fprintf(stderr, "out of memory\n");
+ goto error;
+ }
+ }
+
PyConfig config;
PyConfig_InitPythonConfig(&config);
config.pathconfig_warnings = 0; /* Suppress errors from getpath.c */
@@ -104,27 +104,27 @@ static int pymain(int argc, char** argv) {
config.bytes_warning = atoi(bytes_warning);
}
- oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
- if (!oldloc) {
- fprintf(stderr, "out of memory\n");
- goto error;
- }
-
- setlocale(LC_ALL, "");
- for (i = 0; i < argc; i++) {
- argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
- argv_copy2[i] = argv_copy[i];
- if (!argv_copy[i]) {
- fprintf(stderr, "Unable to decode the command line argument #%i\n",
+ oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
+ if (!oldloc) {
+ fprintf(stderr, "out of memory\n");
+ goto error;
+ }
+
+ setlocale(LC_ALL, "");
+ for (i = 0; i < argc; i++) {
+ argv_copy[i] = Py_DecodeLocale(argv[i], NULL);
+ argv_copy2[i] = argv_copy[i];
+ if (!argv_copy[i]) {
+ fprintf(stderr, "Unable to decode the command line argument #%i\n",
i + 1);
- argc = i;
- goto error;
- }
- }
- setlocale(LC_ALL, oldloc);
- PyMem_RawFree(oldloc);
- oldloc = NULL;
-
+ argc = i;
+ goto error;
+ }
+ }
+ setlocale(LC_ALL, oldloc);
+ PyMem_RawFree(oldloc);
+ oldloc = NULL;
+
if (argc >= 1)
Py_SetProgramName(argv_copy[0]);
@@ -156,10 +156,10 @@ static int pymain(int argc, char** argv) {
free(entry_point_copy);
return sts;
}
-
+
Py_InitArgcArgv(argc, argv_copy);
- PySys_SetArgv(argc, argv_copy);
-
+ PySys_SetArgv(argc, argv_copy);
+
{
PyObject* module = PyImport_ImportModule("library.python.runtime_py3.entry_points");
if (module == NULL) {
@@ -175,53 +175,53 @@ static int pymain(int argc, char** argv) {
}
}
- const char* module_name = entry_point_copy;
- const char* func_name = NULL;
-
- char *colon = strchr(entry_point_copy, ':');
- if (colon != NULL) {
- colon[0] = '\0';
- func_name = colon + 1;
- }
+ const char* module_name = entry_point_copy;
+ const char* func_name = NULL;
+
+ char *colon = strchr(entry_point_copy, ':');
+ if (colon != NULL) {
+ colon[0] = '\0';
+ func_name = colon + 1;
+ }
if (module_name[0] == '\0') {
module_name = "library.python.runtime_py3.entry_points";
}
-
- if (!func_name) {
- sts = RunModule(module_name);
- } else {
- PyObject* module = PyImport_ImportModule(module_name);
-
- if (module == NULL) {
- PyErr_Print();
- } else {
+
+ if (!func_name) {
+ sts = RunModule(module_name);
+ } else {
+ PyObject* module = PyImport_ImportModule(module_name);
+
+ if (module == NULL) {
+ PyErr_Print();
+ } else {
PyObject* value = PyObject_CallMethod(module, func_name, NULL);
-
- if (value == NULL) {
- PyErr_Print();
- } else {
- Py_DECREF(value);
- sts = 0;
- }
-
- Py_DECREF(module);
- }
- }
-
- if (Py_FinalizeEx() < 0) {
- sts = 120;
- }
-
-error:
- free(entry_point_copy);
- PyMem_RawFree(argv_copy);
- if (argv_copy2) {
- for (i = 0; i < argc; i++)
- PyMem_RawFree(argv_copy2[i]);
- PyMem_RawFree(argv_copy2);
- }
- PyMem_RawFree(oldloc);
- return sts;
+
+ if (value == NULL) {
+ PyErr_Print();
+ } else {
+ Py_DECREF(value);
+ sts = 0;
+ }
+
+ Py_DECREF(module);
+ }
+ }
+
+ if (Py_FinalizeEx() < 0) {
+ sts = 120;
+ }
+
+error:
+ free(entry_point_copy);
+ PyMem_RawFree(argv_copy);
+ if (argv_copy2) {
+ for (i = 0; i < argc; i++)
+ PyMem_RawFree(argv_copy2[i]);
+ PyMem_RawFree(argv_copy2);
+ }
+ PyMem_RawFree(oldloc);
+ return sts;
}
int (*mainptr)(int argc, char** argv) = pymain;
diff --git a/library/python/runtime_py3/ya.make b/library/python/runtime_py3/ya.make
index 0990770ab3..fa5c11341a 100644
--- a/library/python/runtime_py3/ya.make
+++ b/library/python/runtime_py3/ya.make
@@ -22,12 +22,12 @@ ENABLE(PYBUILD_NO_PYC)
PY_SRCS(
entry_points.py
- TOP_LEVEL
+ TOP_LEVEL
CYTHON_DIRECTIVE
language_level=3
- __res.pyx
+ __res.pyx
sitecustomize.pyx
)