aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/python/runtime_py3
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/runtime_py3')
-rw-r--r--library/python/runtime_py3/__res.pyx48
-rw-r--r--library/python/runtime_py3/importer.pxi54
-rw-r--r--library/python/runtime_py3/main/main.c8
-rw-r--r--library/python/runtime_py3/ya.make14
4 files changed, 62 insertions, 62 deletions
diff --git a/library/python/runtime_py3/__res.pyx b/library/python/runtime_py3/__res.pyx
index 97190d9f29..306e780b2b 100644
--- a/library/python/runtime_py3/__res.pyx
+++ b/library/python/runtime_py3/__res.pyx
@@ -1,36 +1,36 @@
from _codecs import utf_8_decode, utf_8_encode
-from libcpp cimport bool
-
+from libcpp cimport bool
+
from util.generic.string cimport TString, TStringBuf
-
-
+
+
cdef extern from "library/cpp/resource/resource.h" namespace "NResource":
- cdef size_t Count() except +
- cdef TStringBuf KeyByIndex(size_t idx) except +
+ cdef size_t Count() except +
+ cdef TStringBuf KeyByIndex(size_t idx) except +
cdef bool FindExact(const TStringBuf key, TString* result) nogil except +
-
-
-def count():
- return Count()
-
-
-def key_by_index(idx):
- cdef TStringBuf ret = KeyByIndex(idx)
-
- return ret.Data()[:ret.Size()]
-
-
-def find(s):
+
+
+def count():
+ return Count()
+
+
+def key_by_index(idx):
+ cdef TStringBuf ret = KeyByIndex(idx)
+
+ return ret.Data()[:ret.Size()]
+
+
+def find(s):
cdef TString res
-
+
if isinstance(s, str):
s = utf_8_encode(s)[0]
- if FindExact(TStringBuf(s, len(s)), &res):
- return res.c_str()[:res.length()]
-
- return None
+ if FindExact(TStringBuf(s, len(s)), &res):
+ return res.c_str()[:res.length()]
+
+ return None
include "importer.pxi"
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 904f94dea2..050f943424 100644
--- a/library/python/runtime_py3/importer.pxi
+++ b/library/python/runtime_py3/importer.pxi
@@ -1,12 +1,12 @@
import marshal
-import sys
+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_external import _os, _path_isfile, _path_isdir, _path_isabs, path_sep, _path_join, _path_split
from _io import FileIO
-import __res as __resource
-
+import __res as __resource
+
_b = lambda x: x if isinstance(x, bytes) else utf_8_encode(x)[0]
_s = lambda x: x if isinstance(x, str) else utf_8_decode(x)[0]
env_entry_point = b'Y_PYTHON_ENTRY_POINT'
@@ -16,7 +16,7 @@ env_extended_source_search = b'Y_PYTHON_EXTENDED_SOURCE_SEARCH'
res_ya_ide_venv = b'YA_IDE_VENV'
executable = sys.executable or 'Y_PYTHON'
sys.modules['run_import_hook'] = __resource
-
+
# This is the prefix in contrib/tools/python3/src/Lib/ya.make.
py_prefix = b'py/'
py_prefix_len = len(py_prefix)
@@ -97,10 +97,10 @@ def file_bytes(path):
def iter_keys(prefix):
l = len(prefix)
for idx in range(__resource.count()):
- key = __resource.key_by_index(idx)
+ key = __resource.key_by_index(idx)
if key.startswith(prefix):
yield key, key[l:]
-
+
def iter_py_modules(with_keys=False):
for key, path in iter_keys(b'resfs/file/' + py_prefix):
@@ -117,8 +117,8 @@ def iter_prefixes(s):
while i >= 0:
yield s[:i]
i = s.find('.', i + 1)
-
-
+
+
def resfs_resolve(path):
"""
Return the absolute path of a root-relative path if it exists.
@@ -171,12 +171,12 @@ def mod_path(mod):
return py_prefix + _b(mod).replace(b'.', b'/') + b'.py'
-class ResourceImporter(object):
-
+class ResourceImporter(object):
+
""" A meta_path importer that loads code from built-in resources.
- """
-
- def __init__(self):
+ """
+
+ def __init__(self):
self.memory = set(iter_py_modules()) # Set of importable module names.
self.source_map = {} # Map from file names to module names.
self._source_name = {} # Map from original to altered module names.
@@ -185,13 +185,13 @@ class ResourceImporter(object):
self.arcadia_source_finder = ArcadiaSourceFinder(_s(Y_PYTHON_SOURCE_ROOT))
else:
self.arcadia_source_finder = None
-
+
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:
- self.memory.add(k)
-
+ for pp in iter_prefixes(p):
+ k = pp + '.__init__'
+ if k not in self.memory:
+ self.memory.add(k)
+
def for_package(self, name):
import copy
importer = copy.copy(self)
@@ -211,7 +211,7 @@ class ResourceImporter(object):
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)
@@ -239,7 +239,7 @@ class ResourceImporter(object):
if data is None:
raise IOError(path) # Y_PYTHON_ENTRY_POINT=:resource_files
return data
-
+
# PEP-302 extension 2 of 3: get __file__ without importing.
def get_filename(self, fullname):
modname = fullname
@@ -291,13 +291,13 @@ class ResourceImporter(object):
# This covers packages with no __init__.py in resources.
return compile('', modname, 'exec', dont_inherit=True)
- def is_package(self, fullname):
- if fullname in self.memory:
- return False
+ def is_package(self, fullname):
+ if fullname in self.memory:
+ return False
if fullname + '.__init__' in self.memory:
- return True
-
+ return True
+
if self.arcadia_source_finder:
return self.arcadia_source_finder.is_package(fullname)
@@ -564,7 +564,7 @@ sys.is_standalone_binary = True
sys.frozen = True
# Set of names of importable modules.
-sys.extra_modules = importer.memory
+sys.extra_modules = importer.memory
# Use custom implementation of traceback printer.
# Built-in printer (PyTraceBack_Print) does not support custom module loaders
diff --git a/library/python/runtime_py3/main/main.c b/library/python/runtime_py3/main/main.c
index 3159800615..48a6f3b116 100644
--- a/library/python/runtime_py3/main/main.c
+++ b/library/python/runtime_py3/main/main.c
@@ -80,10 +80,10 @@ static int pymain(int argc, char** argv) {
}
int i, sts = 1;
- char* oldloc = NULL;
- wchar_t** argv_copy = NULL;
+ char* oldloc = NULL;
+ wchar_t** argv_copy = NULL;
/* We need a second copies, as Python might modify the first one. */
- wchar_t** argv_copy2 = NULL;
+ wchar_t** argv_copy2 = NULL;
char* entry_point_copy = NULL;
if (argc > 0) {
@@ -195,7 +195,7 @@ static int pymain(int argc, char** argv) {
if (module == NULL) {
PyErr_Print();
} else {
- PyObject* value = PyObject_CallMethod(module, func_name, NULL);
+ PyObject* value = PyObject_CallMethod(module, func_name, NULL);
if (value == NULL) {
PyErr_Print();
diff --git a/library/python/runtime_py3/ya.make b/library/python/runtime_py3/ya.make
index fa5c11341a..fdb79661f0 100644
--- a/library/python/runtime_py3/ya.make
+++ b/library/python/runtime_py3/ya.make
@@ -1,19 +1,19 @@
PY3_LIBRARY()
-
+
OWNER(
borman
orivej
pg
)
-
+
NO_WSHADOW()
-PEERDIR(
+PEERDIR(
contrib/tools/python3/src
contrib/tools/python3/lib/py
library/cpp/resource
-)
-
+)
+
CFLAGS(-DCYTHON_REGISTER_ABCS=0)
NO_PYTHON_INCLUDES()
@@ -30,7 +30,7 @@ PY_SRCS(
__res.pyx
sitecustomize.pyx
)
-
+
IF (CYTHON_COVERAGE)
# Let covarage support add all needed files to resources
ELSE()
@@ -42,7 +42,7 @@ ELSE()
)
ENDIF()
-END()
+END()
RECURSE_FOR_TESTS(
test