aboutsummaryrefslogtreecommitdiffstats
path: root/library/python
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /library/python
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python')
-rw-r--r--library/python/pytest/main.py38
-rw-r--r--library/python/pytest/plugins/collection.py20
-rw-r--r--library/python/pytest/plugins/conftests.py22
-rw-r--r--library/python/pytest/plugins/ya.py38
-rw-r--r--library/python/pytest/pytest.yatest.ini6
-rw-r--r--library/python/pytest/rewrite.py128
-rw-r--r--library/python/pytest/ya.make2
-rw-r--r--library/python/pytest/yatest_tools.py8
-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
-rw-r--r--library/python/testing/yatest_common/yatest/common/process.py16
-rw-r--r--library/python/testing/yatest_lib/external.py16
13 files changed, 306 insertions, 306 deletions
diff --git a/library/python/pytest/main.py b/library/python/pytest/main.py
index 6296bd6f0f..355623ff0e 100644
--- a/library/python/pytest/main.py
+++ b/library/python/pytest/main.py
@@ -2,10 +2,10 @@ import os
import sys
import time
-import __res
+import __res
FORCE_EXIT_TESTSFAILED_ENV = 'FORCE_EXIT_TESTSFAILED'
-
+
def main():
import library.python.pytest.context as context
@@ -39,12 +39,12 @@ def main():
import library.python.pytest.plugins.ya as ya
import library.python.pytest.plugins.conftests as conftests
- import _pytest.assertion
- from _pytest.monkeypatch import MonkeyPatch
+ import _pytest.assertion
+ from _pytest.monkeypatch import MonkeyPatch
from . import rewrite
- m = MonkeyPatch()
- m.setattr(_pytest.assertion.rewrite, "AssertionRewritingHook", rewrite.AssertionRewritingHook)
-
+ m = MonkeyPatch()
+ m.setattr(_pytest.assertion.rewrite, "AssertionRewritingHook", rewrite.AssertionRewritingHook)
+
prefix = '__tests__.'
test_modules = [
@@ -56,18 +56,18 @@ def main():
if isinstance(doctest_packages, bytes):
doctest_packages = doctest_packages.decode('utf-8')
doctest_packages = doctest_packages.split()
-
- def is_doctest_module(name):
- for package in doctest_packages:
+
+ def is_doctest_module(name):
+ for package in doctest_packages:
if name == package or name.startswith(str(package) + "."):
- return True
- return False
-
- doctest_modules = [
- name for name in sys.extra_modules
- if is_doctest_module(name)
- ]
-
+ return True
+ return False
+
+ doctest_modules = [
+ name for name in sys.extra_modules
+ if is_doctest_module(name)
+ ]
+
def remove_user_site(paths):
site_paths = ('site-packages', 'site-python')
@@ -86,7 +86,7 @@ def main():
sys.path = remove_user_site(sys.path)
rc = pytest.main(plugins=[
- collection.CollectionPlugin(test_modules, doctest_modules),
+ collection.CollectionPlugin(test_modules, doctest_modules),
ya,
conftests,
])
diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py
index e36f47a78f..dad830e473 100644
--- a/library/python/pytest/plugins/collection.py
+++ b/library/python/pytest/plugins/collection.py
@@ -18,14 +18,14 @@ class LoadedModule(_pytest.python.Module):
self.parent = parent
self.config = parent.config
self.keywords = {}
- self.own_markers = []
+ self.own_markers = []
self.fspath = py.path.local()
@classmethod
def from_parent(cls, **kwargs):
namespace = kwargs.pop('namespace', True)
kwargs.setdefault('fspath', py.path.local())
-
+
loaded_module = getattr(super(LoadedModule, cls), 'from_parent', cls)(**kwargs)
loaded_module.namespace = namespace
@@ -44,7 +44,7 @@ class LoadedModule(_pytest.python.Module):
def _getobj(self):
module_name = self.name[:-len('.py')]
- if self.namespace:
+ if self.namespace:
module_name = '__tests__.' + module_name
__import__(module_name)
return sys.modules[module_name]
@@ -54,13 +54,13 @@ class DoctestModule(LoadedModule):
def collect(self):
import doctest
-
- module = self._getobj()
- # uses internal doctest module parsing mechanism
+
+ module = self._getobj()
+ # uses internal doctest module parsing mechanism
finder = doctest.DocTestFinder()
optionflags = _pytest.doctest.get_optionflags(self)
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags)
-
+
try:
for test in finder.find(module, self.name[:-len('.py')]):
if test.examples: # skip empty doctests
@@ -94,9 +94,9 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f
class CollectionPlugin(object):
- def __init__(self, test_modules, doctest_modules):
+ def __init__(self, test_modules, doctest_modules):
self._test_modules = test_modules
- self._doctest_modules = doctest_modules
+ self._doctest_modules = doctest_modules
def pytest_sessionstart(self, session):
@@ -124,5 +124,5 @@ class CollectionPlugin(object):
if os.environ.get('YA_PYTEST_DISABLE_DOCTEST', 'no') == 'no':
for doctest_module in self._doctest_modules:
yield DoctestModule.from_parent(name=doctest_module, parent=session, namespace=False)
-
+
session.collect = collect
diff --git a/library/python/pytest/plugins/conftests.py b/library/python/pytest/plugins/conftests.py
index 522041f5a7..96456da28c 100644
--- a/library/python/pytest/plugins/conftests.py
+++ b/library/python/pytest/plugins/conftests.py
@@ -23,23 +23,23 @@ conftest_modules = []
@hookimpl(trylast=True)
def pytest_load_initial_conftests(early_config, parser, args):
- conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)
+ conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)
- def conftest_key(name):
- if not name.startswith("__tests__."):
- # Make __tests__ come last
- return "_." + name
- return name
+ def conftest_key(name):
+ if not name.startswith("__tests__."):
+ # Make __tests__ come last
+ return "_." + name
+ return name
- for name in sorted(conftests, key=conftest_key):
- mod = importlib.import_module(name)
+ for name in sorted(conftests, key=conftest_key):
+ mod = importlib.import_module(name)
if os.getenv("CONFTEST_LOAD_POLICY") != "LOCAL":
mod.__orig_file__ = mod.__file__
mod.__file__ = ""
- conftest_modules.append(mod)
+ conftest_modules.append(mod)
early_config.pluginmanager.consider_conftest(mod)
-
-
+
+
def getconftestmodules(*args, **kwargs):
return conftest_modules
diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py
index 1bde03042d..0dfbb7c274 100644
--- a/library/python/pytest/plugins/ya.py
+++ b/library/python/pytest/plugins/ya.py
@@ -185,7 +185,7 @@ def pytest_configure(config):
global pytest_config
pytest_config = config
- config.option.continue_on_collection_errors = True
+ config.option.continue_on_collection_errors = True
config.addinivalue_line("markers", "ya:external")
@@ -523,9 +523,9 @@ def pytest_collectreport(report):
sys.stderr.write(yatest_lib.tools.to_utf8(report.longrepr))
-@pytest.mark.tryfirst
-def pytest_pyfunc_call(pyfuncitem):
- testfunction = pyfuncitem.obj
+@pytest.mark.tryfirst
+def pytest_pyfunc_call(pyfuncitem):
+ testfunction = pyfuncitem.obj
iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None)
if iscoroutinefunction is not None and iscoroutinefunction(testfunction):
msg = "Coroutine functions are not natively supported and have been skipped.\n"
@@ -538,9 +538,9 @@ def pytest_pyfunc_call(pyfuncitem):
funcargs = pyfuncitem.funcargs
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
pyfuncitem.retval = testfunction(**testargs)
- return True
-
-
+ return True
+
+
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
def logreport(report, result, call):
@@ -575,8 +575,8 @@ def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
result = None
- if hasattr(item, 'retval') and item.retval is not None:
- result = item.retval
+ if hasattr(item, 'retval') and item.retval is not None:
+ result = item.retval
if not pytest_config.from_ya_test:
ti = TestItem(rep, result, pytest_config.option.test_suffix)
tr = pytest_config.pluginmanager.getplugin('terminalreporter')
@@ -584,13 +584,13 @@ def pytest_runtest_makereport(item, call):
logreport(rep, result, call)
-def pytest_make_parametrize_id(config, val, argname):
- # Avoid <, > symbols in canondata file names
- if inspect.isfunction(val) and val.__name__ == "<lambda>":
- return str(argname)
- return None
-
-
+def pytest_make_parametrize_id(config, val, argname):
+ # Avoid <, > symbols in canondata file names
+ if inspect.isfunction(val) and val.__name__ == "<lambda>":
+ return str(argname)
+ return None
+
+
def get_formatted_error(report):
if isinstance(report.longrepr, tuple):
text = ""
@@ -692,7 +692,7 @@ class TestItem(object):
return self._error
def set_error(self, entry, marker='bad'):
- if isinstance(entry, _pytest.reports.BaseReport):
+ if isinstance(entry, _pytest.reports.BaseReport):
self._error = get_formatted_error(entry)
else:
self._error = "[[{}]]{}".format(yatest_lib.tools.to_str(marker), yatest_lib.tools.to_str(entry))
@@ -827,9 +827,9 @@ class TraceReportGenerator(object):
self.trace('subtest-started', message)
def on_finish_test_case(self, test_item, duration_only=False):
- if test_item.result is not None:
+ if test_item.result is not None:
try:
- result = canon.serialize(test_item.result)
+ result = canon.serialize(test_item.result)
except Exception as e:
yatest_logger.exception("Error while serializing test results")
test_item.set_error("Invalid test result: {}".format(e))
diff --git a/library/python/pytest/pytest.yatest.ini b/library/python/pytest/pytest.yatest.ini
index 70d6c98516..b755a300f9 100644
--- a/library/python/pytest/pytest.yatest.ini
+++ b/library/python/pytest/pytest.yatest.ini
@@ -2,6 +2,6 @@
pep8maxlinelength = 200
norecursedirs = *
pep8ignore = E127 E123 E226 E24
-filterwarnings =
- ignore::pytest.RemovedInPytest4Warning
-addopts = -p no:warnings
+filterwarnings =
+ ignore::pytest.RemovedInPytest4Warning
+addopts = -p no:warnings
diff --git a/library/python/pytest/rewrite.py b/library/python/pytest/rewrite.py
index 4cebcb1edd..e14bd3279b 100644
--- a/library/python/pytest/rewrite.py
+++ b/library/python/pytest/rewrite.py
@@ -1,11 +1,11 @@
-from __future__ import absolute_import
-from __future__ import print_function
-
-import ast
-
+from __future__ import absolute_import
+from __future__ import print_function
+
+import ast
+
import py
-from _pytest.assertion import rewrite
+from _pytest.assertion import rewrite
try:
import importlib.util
except ImportError:
@@ -16,23 +16,23 @@ try:
except ImportError:
pass
-from __res import importer
+from __res import importer
import sys
import six
-
-
+
+
def _get_state(config):
if hasattr(config, '_assertstate'):
return config._assertstate
return config._store[rewrite.assertstate_key]
-class AssertionRewritingHook(rewrite.AssertionRewritingHook):
+class AssertionRewritingHook(rewrite.AssertionRewritingHook):
def __init__(self, *args, **kwargs):
self.modules = {}
super(AssertionRewritingHook, self).__init__(*args, **kwargs)
-
- def find_module(self, name, path=None):
+
+ def find_module(self, name, path=None):
co = self._find_module(name, path)
if co is not None:
return self
@@ -40,28 +40,28 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):
def _find_module(self, name, path=None):
state = _get_state(self.config)
if not self._should_rewrite(name, None, state):
- return None
- state.trace("find_module called for: %s" % name)
-
- try:
- if self.is_package(name):
- return None
- except ImportError:
- return None
-
+ return None
+ state.trace("find_module called for: %s" % name)
+
+ try:
+ if self.is_package(name):
+ return None
+ except ImportError:
+ return None
+
if hasattr(self._rewritten_names, 'add'):
self._rewritten_names.add(name)
else:
self._rewritten_names[name] = Path(path[0])
-
- state.trace("rewriting %s" % name)
- co = _rewrite_test(self.config, name)
- if co is None:
- # Probably a SyntaxError in the test.
- return None
- self.modules[name] = co, None
+
+ state.trace("rewriting %s" % name)
+ co = _rewrite_test(self.config, name)
+ if co is None:
+ # Probably a SyntaxError in the test.
+ return None
+ self.modules[name] = co, None
return co
-
+
def find_spec(self, name, path=None, target=None):
co = self._find_module(name, path)
if co is not None:
@@ -72,17 +72,17 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):
)
def _should_rewrite(self, name, fn, state):
- if name.startswith("__tests__.") or name.endswith(".conftest"):
- return True
-
- return self._is_marked_for_rewrite(name, state)
-
- def is_package(self, name):
- return importer.is_package(name)
-
- def get_source(self, name):
- return importer.get_source(name)
-
+ if name.startswith("__tests__.") or name.endswith(".conftest"):
+ return True
+
+ return self._is_marked_for_rewrite(name, state)
+
+ def is_package(self, name):
+ return importer.is_package(name)
+
+ def get_source(self, name):
+ return importer.get_source(name)
+
if six.PY3:
def load_module(self, module):
co, _ = self.modules.pop(module.__name__)
@@ -97,7 +97,7 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):
del sys.modules[module.__name__]
raise
return sys.modules[module.__name__]
-
+
def exec_module(self, module):
if module.__name__ in self.modules:
self.load_module(module)
@@ -105,28 +105,28 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):
super(AssertionRewritingHook, self).exec_module(module)
-def _rewrite_test(config, name):
- """Try to read and rewrite *fn* and return the code object."""
+def _rewrite_test(config, name):
+ """Try to read and rewrite *fn* and return the code object."""
state = _get_state(config)
-
- source = importer.get_source(name)
- if source is None:
- return None
-
- path = importer.get_filename(name)
-
- try:
- tree = ast.parse(source, filename=path)
- except SyntaxError:
- # Let this pop up again in the real import.
- state.trace("failed to parse: %r" % (path,))
- return None
+
+ source = importer.get_source(name)
+ if source is None:
+ return None
+
+ path = importer.get_filename(name)
+
+ try:
+ tree = ast.parse(source, filename=path)
+ except SyntaxError:
+ # Let this pop up again in the real import.
+ state.trace("failed to parse: %r" % (path,))
+ return None
rewrite.rewrite_asserts(tree, py.path.local(path), config)
- try:
- co = compile(tree, path, "exec", dont_inherit=True)
- except SyntaxError:
- # It's possible that this error is from some bug in the
- # assertion rewriting, but I don't know of a fast way to tell.
- state.trace("failed to compile: %r" % (path,))
- return None
- return co
+ try:
+ co = compile(tree, path, "exec", dont_inherit=True)
+ except SyntaxError:
+ # It's possible that this error is from some bug in the
+ # assertion rewriting, but I don't know of a fast way to tell.
+ state.trace("failed to compile: %r" % (path,))
+ return None
+ return co
diff --git a/library/python/pytest/ya.make b/library/python/pytest/ya.make
index 060c92c313..84c0954311 100644
--- a/library/python/pytest/ya.make
+++ b/library/python/pytest/ya.make
@@ -8,7 +8,7 @@ OWNER(
PY_SRCS(
__init__.py
main.py
- rewrite.py
+ rewrite.py
yatest_tools.py
context.py
)
diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py
index 6b8b896394..473bfeaadd 100644
--- a/library/python/pytest/yatest_tools.py
+++ b/library/python/pytest/yatest_tools.py
@@ -284,10 +284,10 @@ def get_test_log_file_path(output_dir, class_name, test_name, extension="log"):
def split_node_id(nodeid, test_suffix=None):
- path, possible_open_bracket, params = nodeid.partition('[')
+ path, possible_open_bracket, params = nodeid.partition('[')
separator = "::"
- if separator in path:
- path, test_name = path.split(separator, 1)
+ if separator in path:
+ path, test_name = path.split(separator, 1)
else:
test_name = os.path.basename(path)
if test_suffix:
@@ -300,5 +300,5 @@ def split_node_id(nodeid, test_suffix=None):
class_name += separator + klass_name
if separator in test_name:
test_name = test_name.split(separator)[-1]
- test_name += possible_open_bracket + params
+ test_name += possible_open_bracket + params
return yatest_lib.tools.to_utf8(class_name), yatest_lib.tools.to_utf8(test_name)
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 904f94dea2..720153abf6 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 3159800615..75af2f8cde 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 fa5c11341a..0990770ab3 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
)
diff --git a/library/python/testing/yatest_common/yatest/common/process.py b/library/python/testing/yatest_common/yatest/common/process.py
index a8bcc21f51..d4618d59fb 100644
--- a/library/python/testing/yatest_common/yatest/common/process.py
+++ b/library/python/testing/yatest_common/yatest/common/process.py
@@ -9,7 +9,7 @@ import logging
import tempfile
import subprocess
import errno
-import distutils.version
+import distutils.version
import six
@@ -27,7 +27,7 @@ from . import environment
MAX_OUT_LEN = 1000 * 1000 # 1 mb
MAX_MESSAGE_LEN = 1500
SANITIZER_ERROR_PATTERN = br": ([A-Z][\w]+Sanitizer)"
-GLIBC_PATTERN = re.compile(r"\S+@GLIBC_([0-9.]+)")
+GLIBC_PATTERN = re.compile(r"\S+@GLIBC_([0-9.]+)")
yatest_logger = logging.getLogger("ya.test")
@@ -696,13 +696,13 @@ def _run_readelf(binary_path):
def check_glibc_version(binary_path):
- lucid_glibc_version = distutils.version.LooseVersion("2.11")
-
+ lucid_glibc_version = distutils.version.LooseVersion("2.11")
+
for l in _run_readelf(binary_path).split('\n'):
- match = GLIBC_PATTERN.search(l)
- if not match:
- continue
- assert distutils.version.LooseVersion(match.group(1)) <= lucid_glibc_version, match.group(0)
+ match = GLIBC_PATTERN.search(l)
+ if not match:
+ continue
+ assert distutils.version.LooseVersion(match.group(1)) <= lucid_glibc_version, match.group(0)
def backtrace_to_html(bt_filename, output):
diff --git a/library/python/testing/yatest_lib/external.py b/library/python/testing/yatest_lib/external.py
index 39113230d9..699ba4449c 100644
--- a/library/python/testing/yatest_lib/external.py
+++ b/library/python/testing/yatest_lib/external.py
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
MDS_URI_PREFIX = 'https://storage.yandex-team.ru/get-devtools/'
-def apply(func, value, apply_to_keys=False):
+def apply(func, value, apply_to_keys=False):
"""
Applies func to every possible member of value
:param value: could be either a primitive object or a complex one (list, dicts)
@@ -41,7 +41,7 @@ def apply(func, value, apply_to_keys=False):
for key, val in sorted(value.items(), key=lambda dict_item: dict_item[0]):
path = copy.copy(value_path)
path.append(key)
- res[_apply(func, key, path) if apply_to_keys else key] = _apply(func, val, path)
+ res[_apply(func, key, path) if apply_to_keys else key] = _apply(func, val, path)
else:
res = func(value, value_path)
return res
@@ -78,7 +78,7 @@ def serialize(value):
if is_coroutine(val):
return None
raise ValueError("Cannot serialize value '{}' of type {}".format(val, type(val)))
- return apply(_serialize, value, apply_to_keys=True)
+ return apply(_serialize, value, apply_to_keys=True)
def is_external(value):
@@ -89,7 +89,7 @@ class ExternalSchema(object):
File = "file"
SandboxResource = "sbr"
Delayed = "delayed"
- HTTP = "http"
+ HTTP = "http"
class CanonicalObject(dict):
@@ -131,10 +131,10 @@ class ExternalDataInfo(object):
return self.uri.startswith(ExternalSchema.Delayed)
@property
- def is_http(self):
- return self.uri.startswith(ExternalSchema.HTTP)
-
- @property
+ def is_http(self):
+ return self.uri.startswith(ExternalSchema.HTTP)
+
+ @property
def path(self):
if self.uri.count("://") != 1:
logger.error("Invalid external data uri: '%s'", self.uri)