aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython/Build
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/cython/Cython/Build
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/cython/Cython/Build')
-rw-r--r--contrib/tools/cython/Cython/Build/Cythonize.py4
-rw-r--r--contrib/tools/cython/Cython/Build/Dependencies.py68
-rw-r--r--contrib/tools/cython/Cython/Build/Inline.py88
-rw-r--r--contrib/tools/cython/Cython/Build/IpythonMagic.py46
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestInline.py42
-rw-r--r--contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py20
6 files changed, 134 insertions, 134 deletions
diff --git a/contrib/tools/cython/Cython/Build/Cythonize.py b/contrib/tools/cython/Cython/Build/Cythonize.py
index 13a6637f41..c85b6eabab 100644
--- a/contrib/tools/cython/Cython/Build/Cythonize.py
+++ b/contrib/tools/cython/Cython/Build/Cythonize.py
@@ -103,7 +103,7 @@ def cython_compile(path_pattern, options):
compile_time_env=options.compile_time_env,
force=options.force,
quiet=options.quiet,
- depfile=options.depfile,
+ depfile=options.depfile,
**options.options)
if ext_modules and options.build:
@@ -195,7 +195,7 @@ def parse_args(args):
help='increase Python compatibility by ignoring some compile time errors')
parser.add_option('-k', '--keep-going', dest='keep_going', action='store_true',
help='compile as much as possible, ignore compilation failures')
- parser.add_option('-M', '--depfile', action='store_true', help='produce depfiles for the sources')
+ parser.add_option('-M', '--depfile', action='store_true', help='produce depfiles for the sources')
options, args = parser.parse_args(args)
if not args:
diff --git a/contrib/tools/cython/Cython/Build/Dependencies.py b/contrib/tools/cython/Cython/Build/Dependencies.py
index 0799ea0351..7eb55e2607 100644
--- a/contrib/tools/cython/Cython/Build/Dependencies.py
+++ b/contrib/tools/cython/Cython/Build/Dependencies.py
@@ -19,11 +19,11 @@ from distutils.util import strtobool
import zipfile
try:
- from collections.abc import Iterable
-except ImportError:
- from collections import Iterable
-
-try:
+ from collections.abc import Iterable
+except ImportError:
+ from collections import Iterable
+
+try:
import gzip
gzip_open = gzip.open
gzip_ext = '.gz'
@@ -322,8 +322,8 @@ def strip_string_literals(code, prefix='__Pyx_L'):
in_quote = False
hash_mark = single_q = double_q = -1
code_len = len(code)
- quote_type = None
- quote_len = -1
+ quote_type = None
+ quote_len = -1
while True:
if hash_mark < q:
@@ -755,7 +755,7 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
exclude = []
if patterns is None:
return [], {}
- elif isinstance(patterns, basestring) or not isinstance(patterns, Iterable):
+ elif isinstance(patterns, basestring) or not isinstance(patterns, Iterable):
patterns = [patterns]
explicit_modules = set([m.name for m in patterns if isinstance(m, Extension)])
seen = set()
@@ -911,8 +911,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
variable called ``foo`` as a string, and then call
``cythonize(..., aliases={'MY_HEADERS': foo})``.
- :param quiet: If True, Cython won't print error, warning, or status messages during the
- compilation.
+ :param quiet: If True, Cython won't print error, warning, or status messages during the
+ compilation.
:param force: Forces the recompilation of the Cython modules, even if the timestamps
don't indicate that a recompilation is necessary.
@@ -944,8 +944,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
:param compiler_directives: Allow to set compiler directives in the ``setup.py`` like this:
``compiler_directives={'embedsignature': True}``.
See :ref:`compiler-directives`.
-
- :param depfile: produce depfiles for the sources if True.
+
+ :param depfile: produce depfiles for the sources if True.
"""
if exclude is None:
exclude = []
@@ -954,8 +954,8 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
if 'common_utility_include_dir' in options:
safe_makedirs(options['common_utility_include_dir'])
- depfile = options.pop('depfile', None)
-
+ depfile = options.pop('depfile', None)
+
if pythran is None:
pythran_options = None
else:
@@ -1027,26 +1027,26 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
dir = os.path.dirname(c_file)
safe_makedirs_once(dir)
- # write out the depfile, if requested
- if depfile:
- dependencies = deps.all_dependencies(source)
- src_base_dir, _ = os.path.split(source)
- if not src_base_dir.endswith(os.sep):
- src_base_dir += os.sep
- # paths below the base_dir are relative, otherwise absolute
- paths = []
- for fname in dependencies:
- if (fname.startswith(src_base_dir) or
- fname.startswith('.' + os.path.sep)):
- paths.append(os.path.relpath(fname, src_base_dir))
- else:
- paths.append(os.path.abspath(fname))
-
- depline = os.path.split(c_file)[1] + ": \\\n "
- depline += " \\\n ".join(paths) + "\n"
- with open(c_file+'.dep', 'w') as outfile:
- outfile.write(depline)
-
+ # write out the depfile, if requested
+ if depfile:
+ dependencies = deps.all_dependencies(source)
+ src_base_dir, _ = os.path.split(source)
+ if not src_base_dir.endswith(os.sep):
+ src_base_dir += os.sep
+ # paths below the base_dir are relative, otherwise absolute
+ paths = []
+ for fname in dependencies:
+ if (fname.startswith(src_base_dir) or
+ fname.startswith('.' + os.path.sep)):
+ paths.append(os.path.relpath(fname, src_base_dir))
+ else:
+ paths.append(os.path.abspath(fname))
+
+ depline = os.path.split(c_file)[1] + ": \\\n "
+ depline += " \\\n ".join(paths) + "\n"
+ with open(c_file+'.dep', 'w') as outfile:
+ outfile.write(depline)
+
if os.path.exists(c_file):
c_timestamp = os.path.getmtime(c_file)
else:
diff --git a/contrib/tools/cython/Cython/Build/Inline.py b/contrib/tools/cython/Cython/Build/Inline.py
index 80a88c67a7..db6d2640a5 100644
--- a/contrib/tools/cython/Cython/Build/Inline.py
+++ b/contrib/tools/cython/Cython/Build/Inline.py
@@ -1,31 +1,31 @@
from __future__ import absolute_import
-import hashlib
-import inspect
-import os
-import re
-import sys
+import hashlib
+import inspect
+import os
+import re
+import sys
from distutils.core import Distribution, Extension
from distutils.command.build_ext import build_ext
import Cython
-from ..Compiler.Main import Context, default_options
+from ..Compiler.Main import Context, default_options
-from ..Compiler.Visitor import CythonTransform, EnvTransform
-from ..Compiler.ParseTreeTransforms import SkipDeclarations
+from ..Compiler.Visitor import CythonTransform, EnvTransform
+from ..Compiler.ParseTreeTransforms import SkipDeclarations
from ..Compiler.TreeFragment import parse_from_strings
from ..Compiler.StringEncoding import _unicode
from .Dependencies import strip_string_literals, cythonize, cached_function
-from ..Compiler import Pipeline
+from ..Compiler import Pipeline
from ..Utils import get_cython_cache_dir
import cython as cython_module
-IS_PY3 = sys.version_info >= (3,)
-
+IS_PY3 = sys.version_info >= (3,)
+
# A utility function to convert user-supplied ASCII strings to unicode.
-if not IS_PY3:
+if not IS_PY3:
def to_unicode(s):
if isinstance(s, bytes):
return s.decode('ascii')
@@ -34,18 +34,18 @@ if not IS_PY3:
else:
to_unicode = lambda x: x
-if sys.version_info < (3, 5):
- import imp
- def load_dynamic(name, module_path):
- return imp.load_dynamic(name, module_path)
-else:
- import importlib.util as _importlib_util
- def load_dynamic(name, module_path):
- spec = _importlib_util.spec_from_file_location(name, module_path)
- module = _importlib_util.module_from_spec(spec)
- # sys.modules[name] = module
- spec.loader.exec_module(module)
- return module
+if sys.version_info < (3, 5):
+ import imp
+ def load_dynamic(name, module_path):
+ return imp.load_dynamic(name, module_path)
+else:
+ import importlib.util as _importlib_util
+ def load_dynamic(name, module_path):
+ spec = _importlib_util.spec_from_file_location(name, module_path)
+ module = _importlib_util.module_from_spec(spec)
+ # sys.modules[name] = module
+ spec.loader.exec_module(module)
+ return module
class UnboundSymbols(EnvTransform, SkipDeclarations):
def __init__(self):
@@ -131,7 +131,7 @@ def _create_context(cython_include_dirs):
_cython_inline_cache = {}
_cython_inline_default_context = _create_context(('.',))
-
+
def _populate_unbound(kwds, unbound_symbols, locals=None, globals=None):
for symbol in unbound_symbols:
if symbol not in kwds:
@@ -148,12 +148,12 @@ def _populate_unbound(kwds, unbound_symbols, locals=None, globals=None):
else:
print("Couldn't find %r" % symbol)
-
-def _inline_key(orig_code, arg_sigs, language_level):
- key = orig_code, arg_sigs, sys.version_info, sys.executable, language_level, Cython.__version__
- return hashlib.sha1(_unicode(key).encode('utf-8')).hexdigest()
-
-
+
+def _inline_key(orig_code, arg_sigs, language_level):
+ key = orig_code, arg_sigs, sys.version_info, sys.executable, language_level, Cython.__version__
+ return hashlib.sha1(_unicode(key).encode('utf-8')).hexdigest()
+
+
def cython_inline(code, get_type=unsafe_type,
lib_dir=os.path.join(get_cython_cache_dir(), 'inline'),
cython_include_dirs=None, cython_compiler_directives=None,
@@ -163,20 +163,20 @@ def cython_inline(code, get_type=unsafe_type,
get_type = lambda x: 'object'
ctx = _create_context(tuple(cython_include_dirs)) if cython_include_dirs else _cython_inline_default_context
- cython_compiler_directives = dict(cython_compiler_directives) if cython_compiler_directives else {}
- if language_level is None and 'language_level' not in cython_compiler_directives:
- language_level = '3str'
- if language_level is not None:
- cython_compiler_directives['language_level'] = language_level
-
+ cython_compiler_directives = dict(cython_compiler_directives) if cython_compiler_directives else {}
+ if language_level is None and 'language_level' not in cython_compiler_directives:
+ language_level = '3str'
+ if language_level is not None:
+ cython_compiler_directives['language_level'] = language_level
+
# Fast path if this has been called in this session.
_unbound_symbols = _cython_inline_cache.get(code)
if _unbound_symbols is not None:
_populate_unbound(kwds, _unbound_symbols, locals, globals)
args = sorted(kwds.items())
arg_sigs = tuple([(get_type(value, ctx), arg) for arg, value in args])
- key_hash = _inline_key(code, arg_sigs, language_level)
- invoke = _cython_inline_cache.get((code, arg_sigs, key_hash))
+ key_hash = _inline_key(code, arg_sigs, language_level)
+ invoke = _cython_inline_cache.get((code, arg_sigs, key_hash))
if invoke is not None:
arg_list = [arg[1] for arg in args]
return invoke(*arg_list)
@@ -204,8 +204,8 @@ def cython_inline(code, get_type=unsafe_type,
del kwds[name]
arg_names = sorted(kwds)
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
- key_hash = _inline_key(orig_code, arg_sigs, language_level)
- module_name = "_cython_inline_" + key_hash
+ key_hash = _inline_key(orig_code, arg_sigs, language_level)
+ module_name = "_cython_inline_" + key_hash
if module_name in sys.modules:
module = sys.modules[module_name]
@@ -270,13 +270,13 @@ def __invoke(%(params)s):
build_extension.build_lib = lib_dir
build_extension.run()
- module = load_dynamic(module_name, module_path)
+ module = load_dynamic(module_name, module_path)
- _cython_inline_cache[orig_code, arg_sigs, key_hash] = module.__invoke
+ _cython_inline_cache[orig_code, arg_sigs, key_hash] = module.__invoke
arg_list = [kwds[arg] for arg in arg_names]
return module.__invoke(*arg_list)
-
+
# Cached suffix used by cython_inline above. None should get
# overridden with actual value upon the first cython_inline invocation
cython_inline.so_ext = None
diff --git a/contrib/tools/cython/Cython/Build/IpythonMagic.py b/contrib/tools/cython/Cython/Build/IpythonMagic.py
index a96889dc8a..7abb97ec70 100644
--- a/contrib/tools/cython/Cython/Build/IpythonMagic.py
+++ b/contrib/tools/cython/Cython/Build/IpythonMagic.py
@@ -56,8 +56,8 @@ import copy
import distutils.log
import textwrap
-IO_ENCODING = sys.getfilesystemencoding()
-IS_PY2 = sys.version_info[0] < 3
+IO_ENCODING = sys.getfilesystemencoding()
+IS_PY2 = sys.version_info[0] < 3
try:
reload
@@ -102,14 +102,14 @@ PGO_CONFIG = {
PGO_CONFIG['mingw32'] = PGO_CONFIG['gcc']
-if IS_PY2:
- def encode_fs(name):
- return name if isinstance(name, bytes) else name.encode(IO_ENCODING)
-else:
- def encode_fs(name):
- return name
-
-
+if IS_PY2:
+ def encode_fs(name):
+ return name if isinstance(name, bytes) else name.encode(IO_ENCODING)
+else:
+ def encode_fs(name):
+ return name
+
+
@magics_class
class CythonMagics(Magics):
@@ -315,7 +315,7 @@ class CythonMagics(Magics):
key += (time.time(),)
if args.name:
- module_name = str(args.name) # no-op in Py3
+ module_name = str(args.name) # no-op in Py3
else:
module_name = "_cython_magic_" + hashlib.md5(str(key).encode('utf-8')).hexdigest()
html_file = os.path.join(lib_dir, module_name + '.html')
@@ -331,9 +331,9 @@ class CythonMagics(Magics):
extension = None
if need_cythonize:
extensions = self._cythonize(module_name, code, lib_dir, args, quiet=args.quiet)
- if extensions is None:
- # Compilation failed and printed error message
- return None
+ if extensions is None:
+ # Compilation failed and printed error message
+ return None
assert len(extensions) == 1
extension = extensions[0]
self._code_cache[key] = module_name
@@ -341,12 +341,12 @@ class CythonMagics(Magics):
if args.pgo:
self._profile_pgo_wrapper(extension, lib_dir)
- try:
- self._build_extension(extension, lib_dir, pgo_step_name='use' if args.pgo else None,
- quiet=args.quiet)
- except distutils.errors.CompileError:
- # Build failed and printed error message
- return None
+ try:
+ self._build_extension(extension, lib_dir, pgo_step_name='use' if args.pgo else None,
+ quiet=args.quiet)
+ except distutils.errors.CompileError:
+ # Build failed and printed error message
+ return None
module = imp.load_dynamic(module_name, module_path)
self._import_all(module)
@@ -415,7 +415,7 @@ class CythonMagics(Magics):
def _cythonize(self, module_name, code, lib_dir, args, quiet=True):
pyx_file = os.path.join(lib_dir, module_name + '.pyx')
- pyx_file = encode_fs(pyx_file)
+ pyx_file = encode_fs(pyx_file)
c_include_dirs = args.include
c_src_files = list(map(str, args.src))
@@ -535,10 +535,10 @@ class CythonMagics(Magics):
build_extension = _build_ext(dist)
build_extension.finalize_options()
if temp_dir:
- temp_dir = encode_fs(temp_dir)
+ temp_dir = encode_fs(temp_dir)
build_extension.build_temp = temp_dir
if lib_dir:
- lib_dir = encode_fs(lib_dir)
+ lib_dir = encode_fs(lib_dir)
build_extension.build_lib = lib_dir
if extension is not None:
build_extension.extensions = [extension]
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestInline.py b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
index 9676e202ae..d209488083 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestInline.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestInline.py
@@ -24,10 +24,10 @@ class TestInline(CythonTest):
self.test_kwds['lib_dir'] = lib_dir
def test_simple(self):
- self.assertEqual(inline("return 1+2", **self.test_kwds), 3)
+ self.assertEqual(inline("return 1+2", **self.test_kwds), 3)
def test_types(self):
- self.assertEqual(inline("""
+ self.assertEqual(inline("""
cimport cython
return cython.typeof(a), cython.typeof(b)
""", a=1.0, b=[], **self.test_kwds), ('double', 'list object'))
@@ -35,13 +35,13 @@ class TestInline(CythonTest):
def test_locals(self):
a = 1
b = 2
- self.assertEqual(inline("return a+b", **self.test_kwds), 3)
+ self.assertEqual(inline("return a+b", **self.test_kwds), 3)
def test_globals(self):
- self.assertEqual(inline("return global_value + 1", **self.test_kwds), global_value + 1)
+ self.assertEqual(inline("return global_value + 1", **self.test_kwds), global_value + 1)
def test_no_return(self):
- self.assertEqual(inline("""
+ self.assertEqual(inline("""
a = 1
cdef double b = 2
cdef c = []
@@ -49,7 +49,7 @@ class TestInline(CythonTest):
def test_def_node(self):
foo = inline("def foo(x): return x * x", **self.test_kwds)['foo']
- self.assertEqual(foo(7), 49)
+ self.assertEqual(foo(7), 49)
def test_class_ref(self):
class Type(object):
@@ -64,7 +64,7 @@ class TestInline(CythonTest):
c = cy.declare(cy.pointer(cy.float), &b)
return b
""", a=3, **self.test_kwds)
- self.assertEqual(type(b), float)
+ self.assertEqual(type(b), float)
def test_compiler_directives(self):
self.assertEqual(
@@ -74,23 +74,23 @@ class TestInline(CythonTest):
6
)
- def test_lang_version(self):
- # GH-3419. Caching for inline code didn't always respect compiler directives.
- inline_divcode = "def f(int a, int b): return a/b"
- self.assertEqual(
- inline(inline_divcode, language_level=2)['f'](5,2),
- 2
- )
- self.assertEqual(
- inline(inline_divcode, language_level=3)['f'](5,2),
- 2.5
- )
-
+ def test_lang_version(self):
+ # GH-3419. Caching for inline code didn't always respect compiler directives.
+ inline_divcode = "def f(int a, int b): return a/b"
+ self.assertEqual(
+ inline(inline_divcode, language_level=2)['f'](5,2),
+ 2
+ )
+ self.assertEqual(
+ inline(inline_divcode, language_level=3)['f'](5,2),
+ 2.5
+ )
+
if has_numpy:
def test_numpy(self):
import numpy
a = numpy.ndarray((10, 20))
a[0,0] = 10
- self.assertEqual(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
- self.assertEqual(inline("return a[0,0]", a=a, **self.test_kwds), 10.0)
+ self.assertEqual(safe_type(a), 'numpy.ndarray[numpy.float64_t, ndim=2]')
+ self.assertEqual(inline("return a[0,0]", a=a, **self.test_kwds), 10.0)
diff --git a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
index d27c5717e6..24213091b2 100644
--- a/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
+++ b/contrib/tools/cython/Cython/Build/Tests/TestIpythonMagic.py
@@ -28,24 +28,24 @@ try:
except ImportError:
pass
-code = u"""\
+code = u"""\
def f(x):
return 2*x
-"""
+"""
-cython3_code = u"""\
+cython3_code = u"""\
def f(int x):
return 2 / x
def call(x):
return f(*(x,))
-"""
+"""
-pgo_cython3_code = cython3_code + u"""\
+pgo_cython3_code = cython3_code + u"""\
def main():
for _ in range(100): call(5)
main()
-"""
+"""
if sys.platform == 'win32':
@@ -154,10 +154,10 @@ class TestIPythonMagic(CythonTest):
@skip_win32('Skip on Windows')
def test_extlibs(self):
ip = self._ip
- code = u"""
+ code = u"""
from libc.math cimport sin
x = sin(0.0)
- """
+ """
ip.user_ns['x'] = 1
ip.run_cell_magic('cython', '-l m', code)
self.assertEqual(ip.user_ns['x'], 0)
@@ -195,11 +195,11 @@ x = sin(0.0)
ip.run_cell_magic('cython', '--verbose', code)
ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0)
- self.assertEqual([verbose_log.INFO, verbose_log.DEBUG, verbose_log.INFO],
+ self.assertEqual([verbose_log.INFO, verbose_log.DEBUG, verbose_log.INFO],
verbose_log.thresholds)
with mock_distutils() as normal_log:
ip.run_cell_magic('cython', '', code)
ip.ex('g = f(10)')
self.assertEqual(ip.user_ns['g'], 20.0)
- self.assertEqual([normal_log.INFO], normal_log.thresholds)
+ self.assertEqual([normal_log.INFO], normal_log.thresholds)