diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/python | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python')
31 files changed, 479 insertions, 479 deletions
diff --git a/library/python/pytest/main.py b/library/python/pytest/main.py index 6296bd6f0f..a3bb791f1c 100644 --- a/library/python/pytest/main.py +++ b/library/python/pytest/main.py @@ -45,12 +45,12 @@ def main(): m = MonkeyPatch() m.setattr(_pytest.assertion.rewrite, "AssertionRewritingHook", rewrite.AssertionRewritingHook) - prefix = '__tests__.' + prefix = '__tests__.' - test_modules = [ - name[len(prefix):] for name in sys.extra_modules - if name.startswith(prefix) and not name.endswith('.conftest') - ] + test_modules = [ + name[len(prefix):] for name in sys.extra_modules + if name.startswith(prefix) and not name.endswith('.conftest') + ] doctest_packages = __res.find("PY_DOCTEST_PACKAGES") or "" if isinstance(doctest_packages, bytes): @@ -68,27 +68,27 @@ def main(): if is_doctest_module(name) ] - def remove_user_site(paths): - site_paths = ('site-packages', 'site-python') + def remove_user_site(paths): + site_paths = ('site-packages', 'site-python') - def is_site_path(path): - for p in site_paths: - if path.find(p) != -1: - return True - return False + def is_site_path(path): + for p in site_paths: + if path.find(p) != -1: + return True + return False - new_paths = list(paths) - for p in paths: - if is_site_path(p): - new_paths.remove(p) + new_paths = list(paths) + for p in paths: + if is_site_path(p): + new_paths.remove(p) - return new_paths + return new_paths - sys.path = remove_user_site(sys.path) + sys.path = remove_user_site(sys.path) rc = pytest.main(plugins=[ collection.CollectionPlugin(test_modules, doctest_modules), - ya, - conftests, + ya, + conftests, ]) if rc == 5: diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py index 1bde03042d..843ab97414 100644 --- a/library/python/pytest/plugins/ya.py +++ b/library/python/pytest/plugins/ya.py @@ -246,7 +246,7 @@ def pytest_configure(config): os.environ.pop(envvar) if envvar + '_ORIGINAL' in os.environ: os.environ[envvar] = os.environ[envvar + '_ORIGINAL'] - + if config.option.root_dir: config.rootdir = py.path.local(config.option.root_dir) config.invocation_params = attr.evolve(config.invocation_params, dir=config.rootdir) diff --git a/library/python/pytest/pytest.yatest.ini b/library/python/pytest/pytest.yatest.ini index 70d6c98516..01b4e0e535 100644 --- a/library/python/pytest/pytest.yatest.ini +++ b/library/python/pytest/pytest.yatest.ini @@ -1,6 +1,6 @@ [pytest] -pep8maxlinelength = 200 -norecursedirs = * +pep8maxlinelength = 200 +norecursedirs = * pep8ignore = E127 E123 E226 E24 filterwarnings = ignore::pytest.RemovedInPytest4Warning diff --git a/library/python/resource/ut/lib/qw.txt b/library/python/resource/ut/lib/qw.txt index 50e37d5cac..ef4df624f3 100644 --- a/library/python/resource/ut/lib/qw.txt +++ b/library/python/resource/ut/lib/qw.txt @@ -1 +1 @@ -na gorshke sidel korol +na gorshke sidel korol diff --git a/library/python/resource/ut/lib/test_simple.py b/library/python/resource/ut/lib/test_simple.py index 52f006ff91..eaac8aa4c4 100644 --- a/library/python/resource/ut/lib/test_simple.py +++ b/library/python/resource/ut/lib/test_simple.py @@ -1,9 +1,9 @@ import six # noqa -import library.python.resource as rs - +import library.python.resource as rs + text = b'na gorshke sidel korol\n' - + def test_find(): assert rs.find('/qw.txt') == text diff --git a/library/python/resource/ut/lib/ya.make b/library/python/resource/ut/lib/ya.make index 693e388878..3f607afcdc 100644 --- a/library/python/resource/ut/lib/ya.make +++ b/library/python/resource/ut/lib/ya.make @@ -1,17 +1,17 @@ PY23_LIBRARY() - -OWNER(pg) - + +OWNER(pg) + TEST_SRCS(test_simple.py) - -PEERDIR( - library/python/resource -) - -RESOURCE( - qw.txt /qw.txt + +PEERDIR( + library/python/resource +) + +RESOURCE( + qw.txt /qw.txt qw.txt /prefix/1.txt qw.txt /prefix/2.txt -) - -END() +) + +END() diff --git a/library/python/resource/ut/py2/ya.make b/library/python/resource/ut/py2/ya.make index 5085610faf..555b9365e5 100644 --- a/library/python/resource/ut/py2/ya.make +++ b/library/python/resource/ut/py2/ya.make @@ -1,9 +1,9 @@ PY2TEST() - -OWNER(pg) - -PEERDIR( + +OWNER(pg) + +PEERDIR( library/python/resource/ut/lib -) - -END() +) + +END() diff --git a/library/python/resource/ut/ya.make b/library/python/resource/ut/ya.make index a5ec192d74..d44f1524e0 100644 --- a/library/python/resource/ut/ya.make +++ b/library/python/resource/ut/ya.make @@ -1,6 +1,6 @@ -OWNER(pg) - +OWNER(pg) + RECURSE( py2 py3 -) +) diff --git a/library/python/resource/ya.make b/library/python/resource/ya.make index 989329fa4b..60457ce584 100644 --- a/library/python/resource/ya.make +++ b/library/python/resource/ya.make @@ -1,13 +1,13 @@ PY23_LIBRARY() - -OWNER(pg) - + +OWNER(pg) + PEERDIR( contrib/python/six ) PY_SRCS(__init__.py) - -END() + +END() RECURSE_FOR_TESTS(ut) 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 diff --git a/library/python/svn_version/__svn_version.pyx b/library/python/svn_version/__svn_version.pyx index d66bc09d24..c008105148 100644 --- a/library/python/svn_version/__svn_version.pyx +++ b/library/python/svn_version/__svn_version.pyx @@ -1,7 +1,7 @@ -import future.utils as fu - +import future.utils as fu + cdef extern from "library/cpp/svnversion/svnversion.h": - cdef const char* GetProgramSvnVersion() except +; + cdef const char* GetProgramSvnVersion() except +; cdef int GetProgramSvnRevision() except +; cdef int GetArcadiaLastChangeNum() except +; cdef const char* GetProgramCommitId() except +; @@ -9,10 +9,10 @@ cdef extern from "library/cpp/svnversion/svnversion.h": cdef const char* GetBranch() except +; cdef const char* GetTag() except +; cdef int GetArcadiaPatchNumber() except +; - -def svn_version(): - return fu.bytes_to_native_str(GetProgramSvnVersion()) - + +def svn_version(): + return fu.bytes_to_native_str(GetProgramSvnVersion()) + def svn_revision(): return GetProgramSvnRevision() diff --git a/library/python/svn_version/ut/lib/test_simple.py b/library/python/svn_version/ut/lib/test_simple.py index 2c27af6c68..699bd2873f 100644 --- a/library/python/svn_version/ut/lib/test_simple.py +++ b/library/python/svn_version/ut/lib/test_simple.py @@ -1,9 +1,9 @@ import library.python.svn_version as sv - - -def test_simple(): + + +def test_simple(): assert sv.svn_version() - assert isinstance(sv.svn_version(), str) + assert isinstance(sv.svn_version(), str) assert sv.svn_revision() assert isinstance(sv.svn_revision(), int) assert sv.svn_last_revision() diff --git a/library/python/svn_version/ut/lib/ya.make b/library/python/svn_version/ut/lib/ya.make index fb50caf125..794114e131 100644 --- a/library/python/svn_version/ut/lib/ya.make +++ b/library/python/svn_version/ut/lib/ya.make @@ -1,13 +1,13 @@ -PY23_LIBRARY() - -OWNER(pg) - -PEERDIR( - library/python/svn_version -) - -TEST_SRCS( - test_simple.py -) - -END() +PY23_LIBRARY() + +OWNER(pg) + +PEERDIR( + library/python/svn_version +) + +TEST_SRCS( + test_simple.py +) + +END() diff --git a/library/python/svn_version/ut/py2/ya.make b/library/python/svn_version/ut/py2/ya.make index c860e16536..c8f6d66a51 100644 --- a/library/python/svn_version/ut/py2/ya.make +++ b/library/python/svn_version/ut/py2/ya.make @@ -1,9 +1,9 @@ PY2TEST() - -OWNER(pg) - -PEERDIR( - library/python/svn_version/ut/lib -) - -END() + +OWNER(pg) + +PEERDIR( + library/python/svn_version/ut/lib +) + +END() diff --git a/library/python/svn_version/ut/py3/ya.make b/library/python/svn_version/ut/py3/ya.make index 4231565142..e022f6d106 100644 --- a/library/python/svn_version/ut/py3/ya.make +++ b/library/python/svn_version/ut/py3/ya.make @@ -1,9 +1,9 @@ -PY3TEST() - -OWNER(pg) - -PEERDIR( - library/python/svn_version/ut/lib -) - -END() +PY3TEST() + +OWNER(pg) + +PEERDIR( + library/python/svn_version/ut/lib +) + +END() diff --git a/library/python/svn_version/ut/ya.make b/library/python/svn_version/ut/ya.make index 1363b76581..5aea8bb2f1 100644 --- a/library/python/svn_version/ut/ya.make +++ b/library/python/svn_version/ut/ya.make @@ -1,5 +1,5 @@ -RECURSE( - lib - py2 - py3 -) +RECURSE( + lib + py2 + py3 +) diff --git a/library/python/svn_version/ya.make b/library/python/svn_version/ya.make index 747a663f00..d805845845 100644 --- a/library/python/svn_version/ya.make +++ b/library/python/svn_version/ya.make @@ -1,15 +1,15 @@ -PY23_LIBRARY() - -OWNER(pg) - -PEERDIR( +PY23_LIBRARY() + +OWNER(pg) + +PEERDIR( library/cpp/svnversion - contrib/python/future -) - -PY_SRCS( + contrib/python/future +) + +PY_SRCS( __init__.py __svn_version.pyx -) - -END() +) + +END() diff --git a/library/python/symbols/libc/syms.cpp b/library/python/symbols/libc/syms.cpp index 6c04a7ef6e..3b305a5e07 100644 --- a/library/python/symbols/libc/syms.cpp +++ b/library/python/symbols/libc/syms.cpp @@ -1,8 +1,8 @@ -#include <util/system/platform.h> +#include <util/system/platform.h> -#include <library/python/symbols/registry/syms.h> - -#if !defined(_MSC_VER) +#include <library/python/symbols/registry/syms.h> + +#if !defined(_MSC_VER) #if __has_include(<aio.h>) #include <aio.h> #endif @@ -19,88 +19,88 @@ #include <stdlib.h> #include <string.h> #include <time.h> -#include <errno.h> -#include <sys/ipc.h> -#include <dlfcn.h> - -#if defined(_linux_) -#include <sys/prctl.h> +#include <errno.h> +#include <sys/ipc.h> +#include <dlfcn.h> + +#if defined(_linux_) +#include <sys/prctl.h> #include <sys/ptrace.h> -#include <sys/sendfile.h> -#else -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/uio.h> -#endif - -#if defined(_darwin_) -#include <sys/types.h> -#include <sys/sysctl.h> -#include <mach/mach_error.h> // Y_IGNORE -#include <mach/mach_time.h> // Y_IGNORE -#endif - -#if defined(_linux_) -#include <sys/inotify.h> +#include <sys/sendfile.h> +#else +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/uio.h> +#endif + +#if defined(_darwin_) +#include <sys/types.h> +#include <sys/sysctl.h> +#include <mach/mach_error.h> // Y_IGNORE +#include <mach/mach_time.h> // Y_IGNORE +#endif + +#if defined(_linux_) +#include <sys/inotify.h> #include <sys/mman.h> -#endif - -namespace { - static inline void* ErrnoLocation() { - return &errno; - } - - static int ClockGetres(clockid_t clk_id, struct timespec* res) { -#if defined(_darwin_) - static auto func = (decltype(&ClockGetres))dlsym(RTLD_SELF, "_clock_getres"); - - if (func) { - return func(clk_id, res); - } - - // https://opensource.apple.com/source/Libc/Libc-1158.1.2/gen/clock_gettime.c.auto.html - - switch (clk_id){ - case CLOCK_REALTIME: - case CLOCK_MONOTONIC: - case CLOCK_PROCESS_CPUTIME_ID: - res->tv_nsec = NSEC_PER_USEC; - res->tv_sec = 0; - - return 0; - - case CLOCK_MONOTONIC_RAW: - case CLOCK_MONOTONIC_RAW_APPROX: - case CLOCK_UPTIME_RAW: - case CLOCK_UPTIME_RAW_APPROX: - case CLOCK_THREAD_CPUTIME_ID: { - mach_timebase_info_data_t tb_info; - - if (mach_timebase_info(&tb_info)) { - return -1; - } - - res->tv_nsec = tb_info.numer / tb_info.denom + (tb_info.numer % tb_info.denom != 0); - res->tv_sec = 0; - - return 0; - } - - default: - errno = EINVAL; - return -1; - } -#else - return clock_getres(clk_id, res); -#endif - } -} - -BEGIN_SYMS("c") +#endif + +namespace { + static inline void* ErrnoLocation() { + return &errno; + } + + static int ClockGetres(clockid_t clk_id, struct timespec* res) { +#if defined(_darwin_) + static auto func = (decltype(&ClockGetres))dlsym(RTLD_SELF, "_clock_getres"); + + if (func) { + return func(clk_id, res); + } + + // https://opensource.apple.com/source/Libc/Libc-1158.1.2/gen/clock_gettime.c.auto.html + + switch (clk_id){ + case CLOCK_REALTIME: + case CLOCK_MONOTONIC: + case CLOCK_PROCESS_CPUTIME_ID: + res->tv_nsec = NSEC_PER_USEC; + res->tv_sec = 0; + + return 0; + + case CLOCK_MONOTONIC_RAW: + case CLOCK_MONOTONIC_RAW_APPROX: + case CLOCK_UPTIME_RAW: + case CLOCK_UPTIME_RAW_APPROX: + case CLOCK_THREAD_CPUTIME_ID: { + mach_timebase_info_data_t tb_info; + + if (mach_timebase_info(&tb_info)) { + return -1; + } + + res->tv_nsec = tb_info.numer / tb_info.denom + (tb_info.numer % tb_info.denom != 0); + res->tv_sec = 0; + + return 0; + } + + default: + errno = EINVAL; + return -1; + } +#else + return clock_getres(clk_id, res); +#endif + } +} + +BEGIN_SYMS("c") SYM(calloc) SYM(clock_gettime) -SYM_2("clock_getres", ClockGetres) +SYM_2("clock_getres", ClockGetres) SYM(closedir) SYM(fdopen) SYM(fflush) @@ -124,9 +124,9 @@ SYM(sem_unlink) SYM(sem_wait) SYM(siginterrupt) SYM(strdup) -SYM(sendfile) -SYM(strtod) -SYM_2("__errno_location", ErrnoLocation) +SYM(sendfile) +SYM(strtod) +SYM_2("__errno_location", ErrnoLocation) #if defined(_linux_) SYM(prctl) @@ -154,4 +154,4 @@ SYM(aio_suspend) #endif END_SYMS() -#endif +#endif diff --git a/library/python/symbols/libc/ya.make b/library/python/symbols/libc/ya.make index 7b84cbc961..ae0aecb676 100644 --- a/library/python/symbols/libc/ya.make +++ b/library/python/symbols/libc/ya.make @@ -1,9 +1,9 @@ -LIBRARY() +LIBRARY() -OWNER(pg orivej) +OWNER(pg orivej) PEERDIR( - library/python/symbols/registry + library/python/symbols/registry ) IF (GCC OR CLANG) @@ -13,7 +13,7 @@ IF (GCC OR CLANG) ENDIF() SRCS( - GLOBAL syms.cpp + GLOBAL syms.cpp ) END() diff --git a/library/python/symbols/module/__init__.py b/library/python/symbols/module/__init__.py index 0061b9e598..2472775377 100644 --- a/library/python/symbols/module/__init__.py +++ b/library/python/symbols/module/__init__.py @@ -1,48 +1,48 @@ -import subprocess - -from collections import defaultdict - -from .syms import syms - - -def gen_builtin(): - res = defaultdict(dict) - - for k, v in syms.items(): - mod, sym = k.split('|') - - res[mod][sym] = v - - return res - - -builtin_symbols = gen_builtin() -caps = builtin_symbols['_capability'] - - -def find_library(name, find_next): - subst = { - 'rt': 'c', - 'pthread': 'c', - 'm': 'c', - } - - builtin = builtin_symbols.get(subst.get(name, name)) - - if builtin: - return { - 'name': name, - 'symbols': builtin, - } - - if 'musl' in caps: - return None - - try: - subprocess.Popen.__patched__ - - return None - except Exception: - pass - - return find_next(name) +import subprocess + +from collections import defaultdict + +from .syms import syms + + +def gen_builtin(): + res = defaultdict(dict) + + for k, v in syms.items(): + mod, sym = k.split('|') + + res[mod][sym] = v + + return res + + +builtin_symbols = gen_builtin() +caps = builtin_symbols['_capability'] + + +def find_library(name, find_next): + subst = { + 'rt': 'c', + 'pthread': 'c', + 'm': 'c', + } + + builtin = builtin_symbols.get(subst.get(name, name)) + + if builtin: + return { + 'name': name, + 'symbols': builtin, + } + + if 'musl' in caps: + return None + + try: + subprocess.Popen.__patched__ + + return None + except Exception: + pass + + return find_next(name) diff --git a/library/python/symbols/module/module.cpp b/library/python/symbols/module/module.cpp index 92bc7f4d67..fc3fd8dc0f 100644 --- a/library/python/symbols/module/module.cpp +++ b/library/python/symbols/module/module.cpp @@ -1,62 +1,62 @@ #include <Python.h> -#include <library/python/symbols/registry/syms.h> - +#include <library/python/symbols/registry/syms.h> + #include <util/generic/string.h> -#define CAP(x) SYM_2(x, x) - -BEGIN_SYMS("_capability") -#if defined(_musl_) -CAP("musl") -#endif -#if defined(_linux_) -CAP("linux") -#endif -#if defined(_darwin_) -CAP("darwin") -#endif -CAP("_sentinel") -END_SYMS() - -#undef CAP - -using namespace NPrivate; - -namespace { - template <class T> - struct TCB: public ICB { - inline TCB(T& t) - : CB(&t) - { - } - - void Apply(const char* mod, const char* name, void* sym) override { - (*CB)(mod, name, sym); - } - - T* CB; - }; - - template <class T> - static inline TCB<T> MakeTCB(T& t) { - return t; - } -} - +#define CAP(x) SYM_2(x, x) + +BEGIN_SYMS("_capability") +#if defined(_musl_) +CAP("musl") +#endif +#if defined(_linux_) +CAP("linux") +#endif +#if defined(_darwin_) +CAP("darwin") +#endif +CAP("_sentinel") +END_SYMS() + +#undef CAP + +using namespace NPrivate; + +namespace { + template <class T> + struct TCB: public ICB { + inline TCB(T& t) + : CB(&t) + { + } + + void Apply(const char* mod, const char* name, void* sym) override { + (*CB)(mod, name, sym); + } + + T* CB; + }; + + template <class T> + static inline TCB<T> MakeTCB(T& t) { + return t; + } +} + static void DictSetStringPtr(PyObject* dict, const char* name, void* value) { PyObject* p = PyLong_FromVoidPtr(value); PyDict_SetItemString(dict, name, p); Py_DECREF(p); } - + static PyObject* InitSyms(PyObject* m) { if (!m) return NULL; PyObject* d = PyDict_New(); if (!d) return NULL; - + auto f = [&](const char* mod, const char* name, void* sym) { DictSetStringPtr(d, (TString(mod) + "|" + TString(name)).c_str(), sym); }; @@ -69,7 +69,7 @@ static PyObject* InitSyms(PyObject* m) { m = NULL; Py_DECREF(d); return m; -} +} #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef module = { diff --git a/library/python/symbols/module/ya.make b/library/python/symbols/module/ya.make index 78e30f2547..2385c35fe0 100644 --- a/library/python/symbols/module/ya.make +++ b/library/python/symbols/module/ya.make @@ -1,23 +1,23 @@ PY23_LIBRARY() - -OWNER(pg orivej) - + +OWNER(pg orivej) + NO_PYTHON_INCLUDES() -PEERDIR( +PEERDIR( contrib/libs/python/Include -) - -SRCS( - module.cpp -) - -PY_REGISTER( +) + +SRCS( + module.cpp +) + +PY_REGISTER( library.python.symbols.module.syms -) - -PY_SRCS( - __init__.py -) - -END() +) + +PY_SRCS( + __init__.py +) + +END() diff --git a/library/python/symbols/registry/syms.cpp b/library/python/symbols/registry/syms.cpp index ae8e98b32e..3529fb3ece 100644 --- a/library/python/symbols/registry/syms.cpp +++ b/library/python/symbols/registry/syms.cpp @@ -1,31 +1,31 @@ -#include "syms.h" - -#include <util/generic/vector.h> -#include <util/generic/string.h> -#include <util/generic/singleton.h> - -using namespace NPrivate; - -namespace { - struct TSym { - const char* Mod; - const char* Name; - void* Sym; - }; - - struct TSymbols: public TVector<TSym> { - static inline TSymbols* Instance() { - return Singleton<TSymbols>(); - } - }; -} - -void NPrivate::RegisterSymbol(const char* mod, const char* name, void* sym) { - TSymbols::Instance()->push_back(TSym{mod, name, sym}); -} - -void NPrivate::ForEachSymbol(ICB& cb) { - for (auto& x : *TSymbols::Instance()) { - cb.Apply(x.Mod, x.Name, x.Sym); - } -} +#include "syms.h" + +#include <util/generic/vector.h> +#include <util/generic/string.h> +#include <util/generic/singleton.h> + +using namespace NPrivate; + +namespace { + struct TSym { + const char* Mod; + const char* Name; + void* Sym; + }; + + struct TSymbols: public TVector<TSym> { + static inline TSymbols* Instance() { + return Singleton<TSymbols>(); + } + }; +} + +void NPrivate::RegisterSymbol(const char* mod, const char* name, void* sym) { + TSymbols::Instance()->push_back(TSym{mod, name, sym}); +} + +void NPrivate::ForEachSymbol(ICB& cb) { + for (auto& x : *TSymbols::Instance()) { + cb.Apply(x.Mod, x.Name, x.Sym); + } +} diff --git a/library/python/symbols/registry/syms.h b/library/python/symbols/registry/syms.h index 5e34d35298..4aca713216 100644 --- a/library/python/symbols/registry/syms.h +++ b/library/python/symbols/registry/syms.h @@ -1,24 +1,24 @@ -#pragma once - -namespace NPrivate { - struct ICB { - virtual void Apply(const char* mod, const char* name, void* sym) = 0; - }; - - void ForEachSymbol(ICB& cb); - void RegisterSymbol(const char* mod, const char* name, void* sym); -} - -#define BEGIN_SYMS(name) \ - namespace { \ - static struct TRegister { \ - const char* ModuleName = name; \ - inline TRegister() { -#define END_SYMS() \ - } \ - } \ - REGISTRY; \ - } - -#define SYM_2(n, s) ::NPrivate::RegisterSymbol(this->ModuleName, n, (void*)&s); -#define SYM(s) SYM_2(#s, s); +#pragma once + +namespace NPrivate { + struct ICB { + virtual void Apply(const char* mod, const char* name, void* sym) = 0; + }; + + void ForEachSymbol(ICB& cb); + void RegisterSymbol(const char* mod, const char* name, void* sym); +} + +#define BEGIN_SYMS(name) \ + namespace { \ + static struct TRegister { \ + const char* ModuleName = name; \ + inline TRegister() { +#define END_SYMS() \ + } \ + } \ + REGISTRY; \ + } + +#define SYM_2(n, s) ::NPrivate::RegisterSymbol(this->ModuleName, n, (void*)&s); +#define SYM(s) SYM_2(#s, s); diff --git a/library/python/symbols/registry/ya.make b/library/python/symbols/registry/ya.make index 2737b9fce9..e0ef822f98 100644 --- a/library/python/symbols/registry/ya.make +++ b/library/python/symbols/registry/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - -OWNER(pg orivej) - -SRCS( - syms.cpp -) - -END() +LIBRARY() + +OWNER(pg orivej) + +SRCS( + syms.cpp +) + +END() diff --git a/library/python/symbols/ya.make b/library/python/symbols/ya.make index 340a710c48..4e9031beb8 100644 --- a/library/python/symbols/ya.make +++ b/library/python/symbols/ya.make @@ -1,12 +1,12 @@ -RECURSE( - module - registry +RECURSE( + module + registry tests crypto - libc + libc libmagic python - uuid + uuid win_unicode_console -) +) diff --git a/library/python/testing/import_test/import_test.py b/library/python/testing/import_test/import_test.py index 3e3b7234ef..370815ed3a 100644 --- a/library/python/testing/import_test/import_test.py +++ b/library/python/testing/import_test/import_test.py @@ -8,7 +8,7 @@ import traceback import __res from __res import importer - + def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): """ @@ -44,8 +44,8 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): for module in modules: if module not in extra and (rx.search(module) or skip_func and skip_func(module)): print('SKIP', module) - continue - + continue + name = module.rsplit('.', 1)[-1] if name == '__main__' and 'if __name__ ==' not in importer.get_source(module): print('SKIP', module, '''without "if __name__ == '__main__'" check''') @@ -57,7 +57,7 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): for l in item.splitlines(): print('FAIL:', l, file=sys.stderr) - try: + try: print('TRY', module) # XXX waiting for py3 to use print(..., flush=True) sys.stdout.flush() @@ -74,7 +74,7 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): import_times[str(module)] = delay print('OK ', module, '{:.3f}s'.format(delay)) - except Exception as e: + except Exception as e: print('FAIL:', module, e, file=sys.stderr) print_backtrace_marked(sys.exc_info()) failed.append('{}: {}'.format(module, e)) @@ -92,8 +92,8 @@ def check_imports(no_check=(), extra=(), skip_func=None, py_main=None): if failed: raise ImportError('modules not imported:\n' + '\n'.join(failed)) - - + + test_imports = check_imports diff --git a/library/python/ya.make b/library/python/ya.make index 2e1eb6e0e1..11f141f786 100644 --- a/library/python/ya.make +++ b/library/python/ya.make @@ -1,6 +1,6 @@ OWNER(g:python-contrib) - -RECURSE( + +RECURSE( aho_corasick aho_corasick/ut archive @@ -12,7 +12,7 @@ RECURSE( auth_client_parser awssdk-extensions awssdk_async_extensions - base64 + base64 base64/test bclclient blackbox @@ -35,17 +35,17 @@ RECURSE( clickhouse_client cmain codecs - codecs/gen_corpus - codecs/test - compress - compress/tests + codecs/gen_corpus + codecs/test + compress + compress/tests cookiemy coredump_filter cores coverage - cpp_test + cpp_test cppdemangle - cqueue + cqueue crowd-kit cyson cyson/pymodule @@ -65,7 +65,7 @@ RECURSE( django_template_common django_tools_log_context dssclient - dump_dict + dump_dict edit_distance errorboosterclient filelock @@ -89,22 +89,22 @@ RECURSE( golovan_stats_aggregator granular_settings granular_settings/tests - guid - guid/test - guid/at_fork_test + guid + guid/test + guid/at_fork_test gunicorn hnsw ids import_test infected_masks infected_masks/ut - init_log + init_log init_log/example intrasearch_fetcher - json + json json/compare - json/perf - json/test + json/perf + json/test json/test/py2 json/test/py3 langdetect @@ -130,11 +130,11 @@ RECURSE( nstools nyt oauth - oauth/example + oauth/example ok_client openssl - par_apply - par_apply/test + par_apply + par_apply/test path path/tests protobuf @@ -153,7 +153,7 @@ RECURSE( redis_utils reservoir_sampling refsclient - resource + resource retry retry/tests runtime @@ -162,7 +162,7 @@ RECURSE( runtime_py3 runtime_py3/main runtime_py3/test - runtime_test + runtime_test sanitizers sdms_api sfx @@ -173,7 +173,7 @@ RECURSE( spack spyt ssh_client - ssh_sign + ssh_sign startrek_python_client startrek_python_client/tests_int statface_client @@ -181,8 +181,8 @@ RECURSE( strings strings/ut svn_ssh - svn_version - svn_version/ut + svn_version + svn_version/ut symbols testing tmp @@ -208,12 +208,12 @@ RECURSE( windows/ut yandex_tracker_client yenv - yt + yt yt/test ylock ylock/tests zipatch -) +) IF (NOT MUSL) RECURSE( |