Cython 3.2.0__cp39-abi3-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Cython/Build/BuildExecutable.py +169 -0
- Cython/Build/Cache.py +199 -0
- Cython/Build/Cythonize.py +350 -0
- Cython/Build/Dependencies.py +1314 -0
- Cython/Build/Distutils.py +1 -0
- Cython/Build/Inline.py +463 -0
- Cython/Build/IpythonMagic.py +560 -0
- Cython/Build/SharedModule.py +94 -0
- Cython/Build/Tests/TestCyCache.py +194 -0
- Cython/Build/Tests/TestCythonizeArgsParser.py +481 -0
- Cython/Build/Tests/TestDependencies.py +133 -0
- Cython/Build/Tests/TestInline.py +177 -0
- Cython/Build/Tests/TestIpythonMagic.py +287 -0
- Cython/Build/Tests/TestRecythonize.py +212 -0
- Cython/Build/Tests/TestStripLiterals.py +155 -0
- Cython/Build/Tests/__init__.py +1 -0
- Cython/Build/__init__.py +11 -0
- Cython/CodeWriter.py +815 -0
- Cython/Compiler/AnalysedTreeTransforms.py +97 -0
- Cython/Compiler/Annotate.py +328 -0
- Cython/Compiler/AutoDocTransforms.py +320 -0
- Cython/Compiler/Buffer.py +680 -0
- Cython/Compiler/Builtin.py +984 -0
- Cython/Compiler/CmdLine.py +263 -0
- Cython/Compiler/Code.pxd +149 -0
- Cython/Compiler/Code.py +3746 -0
- Cython/Compiler/Code.pyd +0 -0
- Cython/Compiler/CodeGeneration.py +33 -0
- Cython/Compiler/CythonScope.py +191 -0
- Cython/Compiler/Dataclass.py +864 -0
- Cython/Compiler/DebugFlags.py +24 -0
- Cython/Compiler/Errors.py +297 -0
- Cython/Compiler/ExprNodes.py +15562 -0
- Cython/Compiler/FlowControl.pxd +97 -0
- Cython/Compiler/FlowControl.py +1451 -0
- Cython/Compiler/FlowControl.pyd +0 -0
- Cython/Compiler/FusedNode.py +971 -0
- Cython/Compiler/FusedNode.pyd +0 -0
- Cython/Compiler/Future.py +16 -0
- Cython/Compiler/Interpreter.py +57 -0
- Cython/Compiler/Lexicon.py +421 -0
- Cython/Compiler/LineTable.py +114 -0
- Cython/Compiler/LineTable.pyd +0 -0
- Cython/Compiler/Main.py +857 -0
- Cython/Compiler/MatchCaseNodes.py +259 -0
- Cython/Compiler/MemoryView.py +905 -0
- Cython/Compiler/ModuleNode.py +4235 -0
- Cython/Compiler/Naming.py +363 -0
- Cython/Compiler/Nodes.py +10831 -0
- Cython/Compiler/Optimize.py +5288 -0
- Cython/Compiler/Options.py +843 -0
- Cython/Compiler/ParseTreeTransforms.pxd +78 -0
- Cython/Compiler/ParseTreeTransforms.py +4638 -0
- Cython/Compiler/Parsing.pxd +9 -0
- Cython/Compiler/Parsing.py +4775 -0
- Cython/Compiler/Parsing.pyd +0 -0
- Cython/Compiler/Pipeline.py +439 -0
- Cython/Compiler/PyrexTypes.py +5870 -0
- Cython/Compiler/Pythran.py +232 -0
- Cython/Compiler/Scanning.pxd +48 -0
- Cython/Compiler/Scanning.py +701 -0
- Cython/Compiler/Scanning.pyd +0 -0
- Cython/Compiler/StringEncoding.py +298 -0
- Cython/Compiler/Symtab.py +3073 -0
- Cython/Compiler/Tests/TestBuffer.py +105 -0
- Cython/Compiler/Tests/TestBuiltin.py +72 -0
- Cython/Compiler/Tests/TestCmdLine.py +586 -0
- Cython/Compiler/Tests/TestCode.py +144 -0
- Cython/Compiler/Tests/TestFlowControl.py +65 -0
- Cython/Compiler/Tests/TestGrammar.py +202 -0
- Cython/Compiler/Tests/TestMemView.py +71 -0
- Cython/Compiler/Tests/TestParseTreeTransforms.py +285 -0
- Cython/Compiler/Tests/TestScanning.py +134 -0
- Cython/Compiler/Tests/TestSignatureMatching.py +73 -0
- Cython/Compiler/Tests/TestStringEncoding.py +21 -0
- Cython/Compiler/Tests/TestTreeFragment.py +63 -0
- Cython/Compiler/Tests/TestTreePath.py +103 -0
- Cython/Compiler/Tests/TestTypes.py +75 -0
- Cython/Compiler/Tests/TestUtilityLoad.py +112 -0
- Cython/Compiler/Tests/TestVisitor.py +61 -0
- Cython/Compiler/Tests/Utils.py +36 -0
- Cython/Compiler/Tests/__init__.py +1 -0
- Cython/Compiler/TreeFragment.py +278 -0
- Cython/Compiler/TreePath.py +303 -0
- Cython/Compiler/TypeInference.py +591 -0
- Cython/Compiler/TypeSlots.py +1174 -0
- Cython/Compiler/UFuncs.py +311 -0
- Cython/Compiler/UtilNodes.py +389 -0
- Cython/Compiler/UtilityCode.py +344 -0
- Cython/Compiler/Version.py +8 -0
- Cython/Compiler/Visitor.pxd +53 -0
- Cython/Compiler/Visitor.py +861 -0
- Cython/Compiler/Visitor.pyd +0 -0
- Cython/Compiler/__init__.py +1 -0
- Cython/Coverage.py +448 -0
- Cython/Debugger/Cygdb.py +177 -0
- Cython/Debugger/DebugWriter.py +82 -0
- Cython/Debugger/Tests/TestLibCython.py +275 -0
- Cython/Debugger/Tests/__init__.py +1 -0
- Cython/Debugger/Tests/cfuncs.c +8 -0
- Cython/Debugger/Tests/codefile +49 -0
- Cython/Debugger/Tests/test_libcython_in_gdb.py +578 -0
- Cython/Debugger/Tests/test_libpython_in_gdb.py +90 -0
- Cython/Debugger/__init__.py +1 -0
- Cython/Debugger/libcython.py +1548 -0
- Cython/Debugger/libpython.py +2821 -0
- Cython/Debugging.py +20 -0
- Cython/Distutils/__init__.py +2 -0
- Cython/Distutils/build_ext.py +139 -0
- Cython/Distutils/extension.py +96 -0
- Cython/Distutils/old_build_ext.py +351 -0
- Cython/Includes/cpython/__init__.pxd +173 -0
- Cython/Includes/cpython/array.pxd +178 -0
- Cython/Includes/cpython/bool.pxd +37 -0
- Cython/Includes/cpython/buffer.pxd +112 -0
- Cython/Includes/cpython/bytearray.pxd +33 -0
- Cython/Includes/cpython/bytes.pxd +200 -0
- Cython/Includes/cpython/cellobject.pxd +35 -0
- Cython/Includes/cpython/ceval.pxd +8 -0
- Cython/Includes/cpython/codecs.pxd +121 -0
- Cython/Includes/cpython/complex.pxd +60 -0
- Cython/Includes/cpython/contextvars.pxd +145 -0
- Cython/Includes/cpython/conversion.pxd +36 -0
- Cython/Includes/cpython/datetime.pxd +395 -0
- Cython/Includes/cpython/descr.pxd +26 -0
- Cython/Includes/cpython/dict.pxd +187 -0
- Cython/Includes/cpython/exc.pxd +263 -0
- Cython/Includes/cpython/fileobject.pxd +57 -0
- Cython/Includes/cpython/float.pxd +47 -0
- Cython/Includes/cpython/function.pxd +65 -0
- Cython/Includes/cpython/genobject.pxd +25 -0
- Cython/Includes/cpython/getargs.pxd +12 -0
- Cython/Includes/cpython/instance.pxd +25 -0
- Cython/Includes/cpython/iterator.pxd +36 -0
- Cython/Includes/cpython/iterobject.pxd +24 -0
- Cython/Includes/cpython/list.pxd +92 -0
- Cython/Includes/cpython/long.pxd +149 -0
- Cython/Includes/cpython/longintrepr.pxd +14 -0
- Cython/Includes/cpython/mapping.pxd +63 -0
- Cython/Includes/cpython/marshal.pxd +66 -0
- Cython/Includes/cpython/mem.pxd +120 -0
- Cython/Includes/cpython/memoryview.pxd +50 -0
- Cython/Includes/cpython/method.pxd +49 -0
- Cython/Includes/cpython/module.pxd +208 -0
- Cython/Includes/cpython/number.pxd +258 -0
- Cython/Includes/cpython/object.pxd +433 -0
- Cython/Includes/cpython/pycapsule.pxd +143 -0
- Cython/Includes/cpython/pylifecycle.pxd +68 -0
- Cython/Includes/cpython/pyport.pxd +8 -0
- Cython/Includes/cpython/pystate.pxd +95 -0
- Cython/Includes/cpython/pythread.pxd +53 -0
- Cython/Includes/cpython/ref.pxd +141 -0
- Cython/Includes/cpython/sequence.pxd +134 -0
- Cython/Includes/cpython/set.pxd +119 -0
- Cython/Includes/cpython/slice.pxd +70 -0
- Cython/Includes/cpython/time.pxd +129 -0
- Cython/Includes/cpython/tuple.pxd +72 -0
- Cython/Includes/cpython/type.pxd +53 -0
- Cython/Includes/cpython/unicode.pxd +639 -0
- Cython/Includes/cpython/version.pxd +32 -0
- Cython/Includes/cpython/weakref.pxd +78 -0
- Cython/Includes/libc/__init__.pxd +1 -0
- Cython/Includes/libc/complex.pxd +35 -0
- Cython/Includes/libc/errno.pxd +127 -0
- Cython/Includes/libc/float.pxd +43 -0
- Cython/Includes/libc/limits.pxd +28 -0
- Cython/Includes/libc/locale.pxd +46 -0
- Cython/Includes/libc/math.pxd +209 -0
- Cython/Includes/libc/setjmp.pxd +10 -0
- Cython/Includes/libc/signal.pxd +64 -0
- Cython/Includes/libc/stddef.pxd +9 -0
- Cython/Includes/libc/stdint.pxd +105 -0
- Cython/Includes/libc/stdio.pxd +80 -0
- Cython/Includes/libc/stdlib.pxd +72 -0
- Cython/Includes/libc/string.pxd +50 -0
- Cython/Includes/libc/threads.pxd +234 -0
- Cython/Includes/libc/time.pxd +52 -0
- Cython/Includes/libcpp/__init__.pxd +4 -0
- Cython/Includes/libcpp/algorithm.pxd +320 -0
- Cython/Includes/libcpp/any.pxd +16 -0
- Cython/Includes/libcpp/atomic.pxd +59 -0
- Cython/Includes/libcpp/barrier.pxd +22 -0
- Cython/Includes/libcpp/bit.pxd +29 -0
- Cython/Includes/libcpp/cast.pxd +12 -0
- Cython/Includes/libcpp/cmath.pxd +518 -0
- Cython/Includes/libcpp/complex.pxd +106 -0
- Cython/Includes/libcpp/condition_variable.pxd +322 -0
- Cython/Includes/libcpp/deque.pxd +165 -0
- Cython/Includes/libcpp/exception.pxd +86 -0
- Cython/Includes/libcpp/execution.pxd +15 -0
- Cython/Includes/libcpp/forward_list.pxd +63 -0
- Cython/Includes/libcpp/functional.pxd +26 -0
- Cython/Includes/libcpp/future.pxd +103 -0
- Cython/Includes/libcpp/iterator.pxd +34 -0
- Cython/Includes/libcpp/latch.pxd +17 -0
- Cython/Includes/libcpp/limits.pxd +61 -0
- Cython/Includes/libcpp/list.pxd +117 -0
- Cython/Includes/libcpp/map.pxd +252 -0
- Cython/Includes/libcpp/memory.pxd +115 -0
- Cython/Includes/libcpp/mutex.pxd +387 -0
- Cython/Includes/libcpp/numbers.pxd +15 -0
- Cython/Includes/libcpp/numeric.pxd +131 -0
- Cython/Includes/libcpp/optional.pxd +34 -0
- Cython/Includes/libcpp/pair.pxd +1 -0
- Cython/Includes/libcpp/queue.pxd +25 -0
- Cython/Includes/libcpp/random.pxd +166 -0
- Cython/Includes/libcpp/semaphore.pxd +43 -0
- Cython/Includes/libcpp/set.pxd +228 -0
- Cython/Includes/libcpp/shared_mutex.pxd +96 -0
- Cython/Includes/libcpp/span.pxd +87 -0
- Cython/Includes/libcpp/stack.pxd +11 -0
- Cython/Includes/libcpp/stop_token.pxd +117 -0
- Cython/Includes/libcpp/string.pxd +355 -0
- Cython/Includes/libcpp/string_view.pxd +183 -0
- Cython/Includes/libcpp/typeindex.pxd +15 -0
- Cython/Includes/libcpp/typeinfo.pxd +10 -0
- Cython/Includes/libcpp/unordered_map.pxd +193 -0
- Cython/Includes/libcpp/unordered_set.pxd +152 -0
- Cython/Includes/libcpp/utility.pxd +30 -0
- Cython/Includes/libcpp/vector.pxd +186 -0
- Cython/Includes/numpy/math.pxd +150 -0
- Cython/Includes/openmp.pxd +50 -0
- Cython/Includes/posix/__init__.pxd +1 -0
- Cython/Includes/posix/dlfcn.pxd +14 -0
- Cython/Includes/posix/fcntl.pxd +86 -0
- Cython/Includes/posix/ioctl.pxd +4 -0
- Cython/Includes/posix/mman.pxd +101 -0
- Cython/Includes/posix/resource.pxd +57 -0
- Cython/Includes/posix/select.pxd +21 -0
- Cython/Includes/posix/signal.pxd +73 -0
- Cython/Includes/posix/stat.pxd +98 -0
- Cython/Includes/posix/stdio.pxd +37 -0
- Cython/Includes/posix/stdlib.pxd +29 -0
- Cython/Includes/posix/strings.pxd +9 -0
- Cython/Includes/posix/time.pxd +71 -0
- Cython/Includes/posix/types.pxd +30 -0
- Cython/Includes/posix/uio.pxd +26 -0
- Cython/Includes/posix/unistd.pxd +271 -0
- Cython/Includes/posix/wait.pxd +38 -0
- Cython/Plex/Actions.pxd +24 -0
- Cython/Plex/Actions.py +119 -0
- Cython/Plex/Actions.pyd +0 -0
- Cython/Plex/DFA.pxd +14 -0
- Cython/Plex/DFA.py +164 -0
- Cython/Plex/DFA.pyd +0 -0
- Cython/Plex/Errors.py +48 -0
- Cython/Plex/Lexicons.py +178 -0
- Cython/Plex/Machines.pxd +36 -0
- Cython/Plex/Machines.py +238 -0
- Cython/Plex/Machines.pyd +0 -0
- Cython/Plex/Regexps.py +535 -0
- Cython/Plex/Scanners.pxd +45 -0
- Cython/Plex/Scanners.py +328 -0
- Cython/Plex/Scanners.pyd +0 -0
- Cython/Plex/Transitions.pxd +14 -0
- Cython/Plex/Transitions.py +239 -0
- Cython/Plex/Transitions.pyd +0 -0
- Cython/Plex/__init__.py +34 -0
- Cython/Runtime/__init__.py +1 -0
- Cython/Runtime/refnanny.pyd +0 -0
- Cython/Runtime/refnanny.pyx +237 -0
- Cython/Shadow.py +690 -0
- Cython/Shadow.pyi +521 -0
- Cython/StringIOTree.py +170 -0
- Cython/StringIOTree.pyd +0 -0
- Cython/Tempita/__init__.py +4 -0
- Cython/Tempita/_looper.py +154 -0
- Cython/Tempita/_tempita.py +1091 -0
- Cython/Tempita/_tempita.pyd +0 -0
- Cython/TestUtils.py +422 -0
- Cython/Tests/TestCodeWriter.py +128 -0
- Cython/Tests/TestCythonUtils.py +202 -0
- Cython/Tests/TestJediTyper.py +223 -0
- Cython/Tests/TestShadow.py +114 -0
- Cython/Tests/TestStringIOTree.py +67 -0
- Cython/Tests/TestTestUtils.py +90 -0
- Cython/Tests/__init__.py +1 -0
- Cython/Tests/xmlrunner.py +390 -0
- Cython/Utility/AsyncGen.c +1031 -0
- Cython/Utility/Buffer.c +865 -0
- Cython/Utility/BufferFormatFromTypeInfo.pxd +2 -0
- Cython/Utility/Builtins.c +810 -0
- Cython/Utility/CConvert.pyx +134 -0
- Cython/Utility/CMath.c +104 -0
- Cython/Utility/CommonStructures.c +226 -0
- Cython/Utility/Complex.c +378 -0
- Cython/Utility/Coroutine.c +2300 -0
- Cython/Utility/CpdefEnums.pyx +103 -0
- Cython/Utility/CppConvert.pyx +282 -0
- Cython/Utility/CppSupport.cpp +151 -0
- Cython/Utility/CythonFunction.c +1832 -0
- Cython/Utility/Dataclasses.c +101 -0
- Cython/Utility/Embed.c +121 -0
- Cython/Utility/Exceptions.c +1016 -0
- Cython/Utility/ExtensionTypes.c +996 -0
- Cython/Utility/FunctionArguments.c +1043 -0
- Cython/Utility/FusedFunction.pyx +44 -0
- Cython/Utility/ImportExport.c +907 -0
- Cython/Utility/MemoryView.pxd +188 -0
- Cython/Utility/MemoryView.pyx +1482 -0
- Cython/Utility/MemoryView_C.c +927 -0
- Cython/Utility/ModuleSetupCode.c +3203 -0
- Cython/Utility/NumpyImportArray.c +46 -0
- Cython/Utility/ObjectHandling.c +3273 -0
- Cython/Utility/Optimize.c +1603 -0
- Cython/Utility/Overflow.c +384 -0
- Cython/Utility/Printing.c +86 -0
- Cython/Utility/Profile.c +732 -0
- Cython/Utility/StringTools.c +1379 -0
- Cython/Utility/Synchronization.c +399 -0
- Cython/Utility/TString.c +356 -0
- Cython/Utility/TestCyUtilityLoader.pyx +8 -0
- Cython/Utility/TestCythonScope.pyx +75 -0
- Cython/Utility/TestUtilityLoader.c +12 -0
- Cython/Utility/TypeConversion.c +1385 -0
- Cython/Utility/UFuncs.pyx +50 -0
- Cython/Utility/UFuncs_C.c +89 -0
- Cython/Utility/__init__.py +28 -0
- Cython/Utility/arrayarray.h +167 -0
- Cython/Utils.py +687 -0
- Cython/Utils.pyd +0 -0
- Cython/__init__.py +10 -0
- Cython/__init__.pyi +7 -0
- Cython/py.typed +0 -0
- cython-3.2.0.dist-info/METADATA +85 -0
- cython-3.2.0.dist-info/RECORD +333 -0
- cython-3.2.0.dist-info/WHEEL +5 -0
- cython-3.2.0.dist-info/entry_points.txt +4 -0
- cython-3.2.0.dist-info/top_level.txt +3 -0
- cython.py +29 -0
- pyximport/__init__.py +4 -0
- pyximport/pyxbuild.py +160 -0
- pyximport/pyximport.py +482 -0
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Cython - Compilation-wide options and pragma declarations
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
from .. import Utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ShouldBeFromDirective:
|
|
12
|
+
|
|
13
|
+
known_directives = []
|
|
14
|
+
|
|
15
|
+
def __init__(self, options_name, directive_name=None, disallow=False):
|
|
16
|
+
self.options_name = options_name
|
|
17
|
+
self.directive_name = directive_name or options_name
|
|
18
|
+
self.disallow = disallow
|
|
19
|
+
self.known_directives.append(self)
|
|
20
|
+
|
|
21
|
+
def __nonzero__(self):
|
|
22
|
+
self._bad_access()
|
|
23
|
+
|
|
24
|
+
def __int__(self):
|
|
25
|
+
self._bad_access()
|
|
26
|
+
|
|
27
|
+
def _bad_access(self):
|
|
28
|
+
raise RuntimeError(repr(self))
|
|
29
|
+
|
|
30
|
+
def __repr__(self):
|
|
31
|
+
return "Illegal access of '%s' from Options module rather than directive '%s'" % (
|
|
32
|
+
self.options_name, self.directive_name)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
The members of this module are documented using autodata in
|
|
37
|
+
Cython/docs/src/reference/compilation.rst.
|
|
38
|
+
See https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
|
|
39
|
+
for how autodata works.
|
|
40
|
+
Descriptions of those members should start with a #:
|
|
41
|
+
Donc forget to keep the docs in sync by removing and adding
|
|
42
|
+
the members in both this file and the .rst file.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
#: Whether or not to include docstring in the Python extension. If False, the binary size
|
|
46
|
+
#: will be smaller, but the ``__doc__`` attribute of any class or function will be an
|
|
47
|
+
#: empty string.
|
|
48
|
+
docstrings = True
|
|
49
|
+
|
|
50
|
+
#: Embed the source code position in the docstrings of functions and classes.
|
|
51
|
+
embed_pos_in_docstring = False
|
|
52
|
+
|
|
53
|
+
# undocumented
|
|
54
|
+
pre_import = None
|
|
55
|
+
|
|
56
|
+
#: Decref global variables in each module on exit for garbage collection.
|
|
57
|
+
#: 0: None, 1+: interned objects, 2+: cdef globals, 3+: types objects
|
|
58
|
+
#: Mostly for reducing noise in Valgrind as it typically executes at process exit
|
|
59
|
+
#: (when all memory will be reclaimed anyways).
|
|
60
|
+
#: Note that directly or indirectly executed cleanup code that makes use of global
|
|
61
|
+
#: variables or types may no longer be safe when enabling the respective level since
|
|
62
|
+
#: there is no guaranteed order in which the (reference counted) objects will
|
|
63
|
+
#: be cleaned up. The order can change due to live references and reference cycles.
|
|
64
|
+
generate_cleanup_code = False
|
|
65
|
+
|
|
66
|
+
#: Should tp_clear() set object fields to None instead of clearing them to NULL?
|
|
67
|
+
clear_to_none = True
|
|
68
|
+
|
|
69
|
+
#: Generate an annotated HTML version of the input source files for debugging and optimisation purposes.
|
|
70
|
+
#: This has the same effect as the ``annotate`` argument in :func:`cythonize`.
|
|
71
|
+
annotate = False
|
|
72
|
+
|
|
73
|
+
# When annotating source files in HTML, include coverage information from
|
|
74
|
+
# this file.
|
|
75
|
+
annotate_coverage_xml = None
|
|
76
|
+
|
|
77
|
+
#: This will abort the compilation on the first error occurred rather than trying
|
|
78
|
+
#: to keep going and printing further error messages.
|
|
79
|
+
fast_fail = False
|
|
80
|
+
|
|
81
|
+
#: Turn all warnings into errors.
|
|
82
|
+
warning_errors = False
|
|
83
|
+
|
|
84
|
+
#: Make unknown names an error. Python raises a NameError when
|
|
85
|
+
#: encountering unknown names at runtime, whereas this option makes
|
|
86
|
+
#: them a compile time error. If you want full Python compatibility,
|
|
87
|
+
#: you should disable this option and also 'cache_builtins'.
|
|
88
|
+
error_on_unknown_names = True
|
|
89
|
+
|
|
90
|
+
#: Make uninitialized local variable reference a compile time error.
|
|
91
|
+
#: Python raises UnboundLocalError at runtime, whereas this option makes
|
|
92
|
+
#: them a compile time error. Note that this option affects only variables
|
|
93
|
+
#: of "python object" type.
|
|
94
|
+
error_on_uninitialized = True
|
|
95
|
+
|
|
96
|
+
#: This will convert statements of the form ``for i in range(...)``
|
|
97
|
+
#: to ``for i from ...`` when ``i`` is a C integer type, and the direction
|
|
98
|
+
#: (i.e. sign of step) can be determined.
|
|
99
|
+
#: WARNING: This may change the semantics if the range causes assignment to
|
|
100
|
+
#: i to overflow. Specifically, if this option is set, an error will be
|
|
101
|
+
#: raised before the loop is entered, whereas without this option the loop
|
|
102
|
+
#: will execute until an overflowing value is encountered.
|
|
103
|
+
convert_range = True
|
|
104
|
+
|
|
105
|
+
#: Perform lookups on builtin names only once, at module initialisation
|
|
106
|
+
#: time. This will prevent the module from getting imported if a
|
|
107
|
+
#: builtin name that it uses cannot be found during initialisation.
|
|
108
|
+
#: Default is True.
|
|
109
|
+
#: Note that some legacy builtins are automatically remapped
|
|
110
|
+
#: from their Python 2 names to their Python 3 names by Cython
|
|
111
|
+
#: when building in Python 3.x,
|
|
112
|
+
#: so that they do not get in the way even if this option is enabled.
|
|
113
|
+
cache_builtins = True
|
|
114
|
+
|
|
115
|
+
#: Generate branch prediction hints to speed up error handling etc.
|
|
116
|
+
gcc_branch_hints = True
|
|
117
|
+
|
|
118
|
+
#: Enable this to allow one to write ``your_module.foo = ...`` to overwrite the
|
|
119
|
+
#: definition of the cpdef function foo, at the cost of an extra dictionary
|
|
120
|
+
#: lookup on every call.
|
|
121
|
+
#: If this is false it generates only the Python wrapper and no override check.
|
|
122
|
+
lookup_module_cpdef = False
|
|
123
|
+
|
|
124
|
+
#: Whether or not to embed the Python interpreter, for use in making a
|
|
125
|
+
#: standalone executable or calling from external libraries.
|
|
126
|
+
#: This will provide a C function which initialises the interpreter and
|
|
127
|
+
#: executes the body of this module.
|
|
128
|
+
#: See `this demo <https://github.com/cython/cython/tree/master/Demos/embed>`_
|
|
129
|
+
#: for a concrete example.
|
|
130
|
+
#: If true, the initialisation function is the C main() function, but
|
|
131
|
+
#: this option can also be set to a non-empty string to provide a function name explicitly.
|
|
132
|
+
#: Default is False.
|
|
133
|
+
embed = None
|
|
134
|
+
|
|
135
|
+
#: When embedding, this allows listing the names of statically linked extension modules
|
|
136
|
+
#: to register with Python's inittab mechanism on startup, so that they can be imported.
|
|
137
|
+
embed_modules = []
|
|
138
|
+
|
|
139
|
+
# In previous iterations of Cython, globals() gave the first non-Cython module
|
|
140
|
+
# globals in the call stack. Sage relies on this behavior for variable injection.
|
|
141
|
+
old_style_globals = ShouldBeFromDirective('old_style_globals')
|
|
142
|
+
|
|
143
|
+
#: Allows cimporting from a pyx file without a pxd file.
|
|
144
|
+
cimport_from_pyx = False
|
|
145
|
+
|
|
146
|
+
#: Maximum number of dimensions for buffers -- set lower than number of
|
|
147
|
+
#: dimensions in numpy, as
|
|
148
|
+
#: slices are passed by value and involve a lot of copying.
|
|
149
|
+
buffer_max_dims = 8
|
|
150
|
+
|
|
151
|
+
#: Number of function closure instances to keep in a freelist (0: no freelists)
|
|
152
|
+
closure_freelist_size = 8
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def get_directive_defaults():
|
|
156
|
+
# To add an item to this list, all accesses should be changed to use the new
|
|
157
|
+
# directive, and the global option itself should be set to an instance of
|
|
158
|
+
# ShouldBeFromDirective.
|
|
159
|
+
for old_option in ShouldBeFromDirective.known_directives:
|
|
160
|
+
value = globals().get(old_option.options_name)
|
|
161
|
+
assert old_option.directive_name in _directive_defaults
|
|
162
|
+
if not isinstance(value, ShouldBeFromDirective):
|
|
163
|
+
if old_option.disallow:
|
|
164
|
+
raise RuntimeError(
|
|
165
|
+
"Option '%s' must be set from directive '%s'" % (
|
|
166
|
+
old_option.option_name, old_option.directive_name))
|
|
167
|
+
else:
|
|
168
|
+
# Warn?
|
|
169
|
+
_directive_defaults[old_option.directive_name] = value
|
|
170
|
+
return _directive_defaults
|
|
171
|
+
|
|
172
|
+
def copy_inherited_directives(outer_directives, **new_directives):
|
|
173
|
+
# A few directives are not copied downwards and this function removes them.
|
|
174
|
+
# For example, test_assert_path_exists and test_fail_if_path_exists should not be inherited
|
|
175
|
+
# otherwise they can produce very misleading test failures
|
|
176
|
+
new_directives_out = dict(outer_directives)
|
|
177
|
+
for name in ('test_assert_path_exists', 'test_fail_if_path_exists', 'test_assert_c_code_has', 'test_fail_if_c_code_has',
|
|
178
|
+
'test_body_needs_exception_handling', 'critical_section'):
|
|
179
|
+
new_directives_out.pop(name, None)
|
|
180
|
+
new_directives_out.update(new_directives)
|
|
181
|
+
return new_directives_out
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def copy_for_internal(outer_directives):
|
|
185
|
+
# Reset some directives that users should not control for internal code.
|
|
186
|
+
return copy_inherited_directives(
|
|
187
|
+
outer_directives,
|
|
188
|
+
binding=False,
|
|
189
|
+
profile=False,
|
|
190
|
+
linetrace=False,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# Declare compiler directives
|
|
195
|
+
_directive_defaults = {
|
|
196
|
+
'binding': True, # was False before 3.0
|
|
197
|
+
'boundscheck' : True,
|
|
198
|
+
'nonecheck' : False,
|
|
199
|
+
'initializedcheck' : True,
|
|
200
|
+
'freethreading_compatible': False,
|
|
201
|
+
'subinterpreters_compatible': 'no',
|
|
202
|
+
'embedsignature': False,
|
|
203
|
+
'embedsignature.format': 'c',
|
|
204
|
+
'auto_cpdef': False,
|
|
205
|
+
'auto_pickle': None,
|
|
206
|
+
'cdivision': False, # was True before 0.12
|
|
207
|
+
'cdivision_warnings': False,
|
|
208
|
+
'cpow': None, # was True before 3.0
|
|
209
|
+
# None (not set by user) is treated as slightly different from False
|
|
210
|
+
'c_api_binop_methods': False, # was True before 3.0
|
|
211
|
+
'overflowcheck': False,
|
|
212
|
+
'overflowcheck.fold': True,
|
|
213
|
+
'always_allow_keywords': True,
|
|
214
|
+
'allow_none_for_extension_args': True,
|
|
215
|
+
'wraparound' : True,
|
|
216
|
+
'ccomplex' : False, # use C99/C++ for complex types and arith
|
|
217
|
+
'callspec' : "",
|
|
218
|
+
'nogil' : False,
|
|
219
|
+
'gil' : False,
|
|
220
|
+
'with_gil' : False,
|
|
221
|
+
'profile': False,
|
|
222
|
+
'linetrace': False,
|
|
223
|
+
'emit_code_comments': True, # copy original source code into C code comments
|
|
224
|
+
'annotation_typing': True, # read type declarations from Python function annotations
|
|
225
|
+
'infer_types': None,
|
|
226
|
+
'infer_types.verbose': False,
|
|
227
|
+
'autotestdict': True,
|
|
228
|
+
'autotestdict.cdef': False,
|
|
229
|
+
'autotestdict.all': False,
|
|
230
|
+
'language_level': None,
|
|
231
|
+
'fast_getattr': False, # Undocumented until we come up with a better way to handle this everywhere.
|
|
232
|
+
'py2_import': False, # For backward compatibility of Cython's source code in Py3 source mode
|
|
233
|
+
'preliminary_late_includes_cy28': False, # Temporary directive in 0.28, to be removed in a later version (see GH#2079).
|
|
234
|
+
'iterable_coroutine': False, # Make async coroutines backwards compatible with the old asyncio yield-from syntax.
|
|
235
|
+
'c_string_type': 'bytes',
|
|
236
|
+
'c_string_encoding': '',
|
|
237
|
+
'type_version_tag': True, # enables Py_TPFLAGS_HAVE_VERSION_TAG on extension types
|
|
238
|
+
'unraisable_tracebacks': True,
|
|
239
|
+
'old_style_globals': False,
|
|
240
|
+
'np_pythran': False,
|
|
241
|
+
'fast_gil': False,
|
|
242
|
+
'cpp_locals': False, # uses std::optional for C++ locals, so that they work more like Python locals
|
|
243
|
+
'legacy_implicit_noexcept': False,
|
|
244
|
+
'c_compile_guard': '',
|
|
245
|
+
|
|
246
|
+
# set __file__ and/or __path__ to known source/target path at import time (instead of not having them available)
|
|
247
|
+
'set_initial_path' : None, # SOURCEFILE or "/full/path/to/module"
|
|
248
|
+
|
|
249
|
+
'warn': None,
|
|
250
|
+
'warn.undeclared': False,
|
|
251
|
+
'warn.unreachable': True,
|
|
252
|
+
'warn.maybe_uninitialized': False,
|
|
253
|
+
'warn.unused': False,
|
|
254
|
+
'warn.unused_arg': False,
|
|
255
|
+
'warn.unused_result': False,
|
|
256
|
+
'warn.multiple_declarators': True,
|
|
257
|
+
'warn.deprecated.DEF': False,
|
|
258
|
+
'warn.deprecated.IF': True,
|
|
259
|
+
'show_performance_hints': True,
|
|
260
|
+
|
|
261
|
+
# optimizations
|
|
262
|
+
'optimize.inline_defnode_calls': True,
|
|
263
|
+
'optimize.unpack_method_calls': True, # increases code size when True
|
|
264
|
+
'optimize.unpack_method_calls_in_pyinit': False, # uselessly increases code size when True
|
|
265
|
+
'optimize.use_switch': True,
|
|
266
|
+
|
|
267
|
+
# remove unreachable code
|
|
268
|
+
'remove_unreachable': True,
|
|
269
|
+
|
|
270
|
+
# control flow debug directives
|
|
271
|
+
'control_flow.dot_output': "", # Graphviz output filename
|
|
272
|
+
'control_flow.dot_annotate_defs': False, # Annotate definitions
|
|
273
|
+
|
|
274
|
+
# test support
|
|
275
|
+
'test_assert_path_exists' : [],
|
|
276
|
+
'test_fail_if_path_exists' : [],
|
|
277
|
+
'test_body_needs_exception_handling' : None,
|
|
278
|
+
'test_assert_c_code_has' : [],
|
|
279
|
+
'test_fail_if_c_code_has' : [],
|
|
280
|
+
|
|
281
|
+
# experimental, subject to change
|
|
282
|
+
'formal_grammar': False,
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
# Extra warning directives
|
|
286
|
+
extra_warnings = {
|
|
287
|
+
'warn.maybe_uninitialized': True,
|
|
288
|
+
'warn.unreachable': True,
|
|
289
|
+
'warn.unused': True,
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
def one_of(*args, map=None):
|
|
293
|
+
def validate(name, value):
|
|
294
|
+
if map is not None:
|
|
295
|
+
value = map.get(value, value)
|
|
296
|
+
if value not in args:
|
|
297
|
+
raise ValueError("%s directive must be one of %s, got '%s'" % (
|
|
298
|
+
name, args, value))
|
|
299
|
+
return value
|
|
300
|
+
return validate
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
_normalise_common_encoding_name = {
|
|
304
|
+
'utf8': 'utf8',
|
|
305
|
+
'utf-8': 'utf8',
|
|
306
|
+
'default': 'utf8',
|
|
307
|
+
'ascii': 'ascii',
|
|
308
|
+
'us-ascii': 'ascii',
|
|
309
|
+
}.get
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def normalise_encoding_name(option_name, encoding):
|
|
313
|
+
"""
|
|
314
|
+
>>> normalise_encoding_name('c_string_encoding', 'ascii')
|
|
315
|
+
'ascii'
|
|
316
|
+
>>> normalise_encoding_name('c_string_encoding', 'AsCIi')
|
|
317
|
+
'ascii'
|
|
318
|
+
>>> normalise_encoding_name('c_string_encoding', 'us-ascii')
|
|
319
|
+
'ascii'
|
|
320
|
+
>>> normalise_encoding_name('c_string_encoding', 'utF8')
|
|
321
|
+
'utf8'
|
|
322
|
+
>>> normalise_encoding_name('c_string_encoding', 'utF-8')
|
|
323
|
+
'utf8'
|
|
324
|
+
>>> normalise_encoding_name('c_string_encoding', 'deFAuLT')
|
|
325
|
+
'utf8'
|
|
326
|
+
>>> normalise_encoding_name('c_string_encoding', 'default')
|
|
327
|
+
'utf8'
|
|
328
|
+
>>> normalise_encoding_name('c_string_encoding', 'SeriousLyNoSuch--Encoding')
|
|
329
|
+
'SeriousLyNoSuch--Encoding'
|
|
330
|
+
"""
|
|
331
|
+
if not encoding:
|
|
332
|
+
return ''
|
|
333
|
+
encoding_name = _normalise_common_encoding_name(encoding.lower())
|
|
334
|
+
if encoding_name is not None:
|
|
335
|
+
return encoding_name
|
|
336
|
+
|
|
337
|
+
import codecs
|
|
338
|
+
try:
|
|
339
|
+
decoder = codecs.getdecoder(encoding)
|
|
340
|
+
except LookupError:
|
|
341
|
+
return encoding # may exists at runtime ...
|
|
342
|
+
for name in ('ascii', 'utf8'):
|
|
343
|
+
if codecs.getdecoder(name) == decoder:
|
|
344
|
+
return name
|
|
345
|
+
return encoding
|
|
346
|
+
|
|
347
|
+
# use as a sential value to defer analysis of the arguments
|
|
348
|
+
# instead of analysing them in InterpretCompilerDirectives. The dataclass directives are quite
|
|
349
|
+
# complicated and it's easier to deal with them at the point the dataclass is created
|
|
350
|
+
class DEFER_ANALYSIS_OF_ARGUMENTS:
|
|
351
|
+
pass
|
|
352
|
+
DEFER_ANALYSIS_OF_ARGUMENTS = DEFER_ANALYSIS_OF_ARGUMENTS()
|
|
353
|
+
|
|
354
|
+
# Override types possibilities above, if needed
|
|
355
|
+
directive_types = {
|
|
356
|
+
'language_level': str, # values can be None/2/3/'3str', where None == 2+warning
|
|
357
|
+
'auto_pickle': bool,
|
|
358
|
+
'locals': dict,
|
|
359
|
+
'final' : bool, # final cdef classes and methods
|
|
360
|
+
'collection_type': one_of('sequence'),
|
|
361
|
+
'nogil' : DEFER_ANALYSIS_OF_ARGUMENTS,
|
|
362
|
+
'gil' : DEFER_ANALYSIS_OF_ARGUMENTS,
|
|
363
|
+
'critical_section' : DEFER_ANALYSIS_OF_ARGUMENTS,
|
|
364
|
+
'with_gil' : None,
|
|
365
|
+
'internal' : bool, # cdef class visibility in the module dict
|
|
366
|
+
'infer_types' : bool, # values can be True/None/False
|
|
367
|
+
'binding' : bool,
|
|
368
|
+
'cfunc' : None, # decorators do not take directive value
|
|
369
|
+
'ccall' : None,
|
|
370
|
+
'ufunc': None,
|
|
371
|
+
'cpow' : bool,
|
|
372
|
+
'inline' : None,
|
|
373
|
+
'staticmethod' : None,
|
|
374
|
+
'cclass' : None,
|
|
375
|
+
'no_gc_clear' : bool,
|
|
376
|
+
'no_gc' : bool,
|
|
377
|
+
'returns' : type,
|
|
378
|
+
'exceptval': type, # actually (type, check=True/False), but has its own parser
|
|
379
|
+
'set_initial_path': str,
|
|
380
|
+
'freelist': int,
|
|
381
|
+
'c_string_type': one_of('bytes', 'bytearray', 'str', 'unicode', map={'unicode': 'str'}),
|
|
382
|
+
'c_string_encoding': normalise_encoding_name,
|
|
383
|
+
'trashcan': bool,
|
|
384
|
+
'total_ordering': None,
|
|
385
|
+
'dataclasses.dataclass': DEFER_ANALYSIS_OF_ARGUMENTS,
|
|
386
|
+
'dataclasses.field': DEFER_ANALYSIS_OF_ARGUMENTS,
|
|
387
|
+
'embedsignature.format': one_of('c', 'clinic', 'python'),
|
|
388
|
+
'subinterpreters_compatible': one_of('no', 'shared_gil', 'own_gil'),
|
|
389
|
+
'test_body_needs_exception_handling': bool,
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
for key, val in _directive_defaults.items():
|
|
393
|
+
if key not in directive_types:
|
|
394
|
+
directive_types[key] = type(val)
|
|
395
|
+
|
|
396
|
+
directive_scopes = { # defaults to available everywhere
|
|
397
|
+
# 'module', 'function', 'class', 'with statement'
|
|
398
|
+
'auto_pickle': ('module', 'cclass'),
|
|
399
|
+
'final' : ('cclass', 'function'),
|
|
400
|
+
'ccomplex' : ('module',),
|
|
401
|
+
'collection_type': ('cclass',),
|
|
402
|
+
'nogil' : ('function', 'with statement'),
|
|
403
|
+
'gil' : ('with statement'),
|
|
404
|
+
'with_gil' : ('function',),
|
|
405
|
+
'critical_section': ('function', 'with statement'),
|
|
406
|
+
'inline' : ('function',),
|
|
407
|
+
'cfunc' : ('function', 'with statement'),
|
|
408
|
+
'ccall' : ('function', 'with statement'),
|
|
409
|
+
'returns' : ('function',),
|
|
410
|
+
'exceptval' : ('function',),
|
|
411
|
+
'locals' : ('function',),
|
|
412
|
+
'staticmethod' : ('function',), # FIXME: analysis currently lacks more specific function scope
|
|
413
|
+
'no_gc_clear' : ('cclass',),
|
|
414
|
+
'no_gc' : ('cclass',),
|
|
415
|
+
'internal' : ('cclass',),
|
|
416
|
+
'cclass' : ('class', 'cclass', 'with statement'),
|
|
417
|
+
'autotestdict' : ('module',),
|
|
418
|
+
'autotestdict.all' : ('module',),
|
|
419
|
+
'autotestdict.cdef' : ('module',),
|
|
420
|
+
'set_initial_path' : ('module',),
|
|
421
|
+
'test_assert_path_exists' : ('function', 'class', 'cclass'),
|
|
422
|
+
'test_fail_if_path_exists' : ('function', 'class', 'cclass'),
|
|
423
|
+
'test_assert_c_code_has' : ('module',),
|
|
424
|
+
'test_fail_if_c_code_has' : ('module',),
|
|
425
|
+
'test_body_needs_exception_handling' : ('with statement',),
|
|
426
|
+
'freelist': ('cclass',),
|
|
427
|
+
'formal_grammar': ('module',),
|
|
428
|
+
'emit_code_comments': ('module',),
|
|
429
|
+
# Avoid scope-specific to/from_py_functions for c_string.
|
|
430
|
+
'c_string_type': ('module',),
|
|
431
|
+
'c_string_encoding': ('module',),
|
|
432
|
+
'type_version_tag': ('module', 'cclass'),
|
|
433
|
+
'language_level': ('module',),
|
|
434
|
+
# globals() could conceivably be controlled at a finer granularity,
|
|
435
|
+
# but that would complicate the implementation
|
|
436
|
+
'old_style_globals': ('module',),
|
|
437
|
+
'np_pythran': ('module',),
|
|
438
|
+
'preliminary_late_includes_cy28': ('module',),
|
|
439
|
+
'fast_gil': ('module',),
|
|
440
|
+
'iterable_coroutine': ('module', 'function'),
|
|
441
|
+
'trashcan' : ('cclass',),
|
|
442
|
+
'total_ordering': ('class', 'cclass'),
|
|
443
|
+
'dataclasses.dataclass' : ('class', 'cclass'),
|
|
444
|
+
'cpp_locals': ('module', 'function', 'cclass'), # I don't think they make sense in a with_statement
|
|
445
|
+
'ufunc': ('function',),
|
|
446
|
+
'legacy_implicit_noexcept': ('module', ),
|
|
447
|
+
'c_compile_guard': ('function',), # actually C function but this is enforced later
|
|
448
|
+
'control_flow.dot_output': ('module',),
|
|
449
|
+
'control_flow.dot_annotate_defs': ('module',),
|
|
450
|
+
'freethreading_compatible': ('module',),
|
|
451
|
+
'subinterpreters_compatible': ('module',),
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
# A list of directives that (when used as a decorator) are only applied to
|
|
456
|
+
# the object they decorate and not to its children.
|
|
457
|
+
immediate_decorator_directives = {
|
|
458
|
+
'cfunc', 'ccall', 'cclass', 'dataclasses.dataclass', 'ufunc',
|
|
459
|
+
# function signature directives
|
|
460
|
+
'inline', 'exceptval', 'returns', 'with_gil', # 'nogil',
|
|
461
|
+
# class directives
|
|
462
|
+
'freelist', 'no_gc', 'no_gc_clear', 'type_version_tag', 'final',
|
|
463
|
+
'auto_pickle', 'internal', 'collection_type', 'total_ordering',
|
|
464
|
+
# testing directives
|
|
465
|
+
'test_fail_if_path_exists', 'test_assert_path_exists',
|
|
466
|
+
'test_body_needs_exception_handling',
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def parse_directive_value(name, value, relaxed_bool=False):
|
|
471
|
+
"""
|
|
472
|
+
Parses value as an option value for the given name and returns
|
|
473
|
+
the interpreted value. None is returned if the option does not exist.
|
|
474
|
+
|
|
475
|
+
>>> print(parse_directive_value('nonexisting', 'asdf asdfd'))
|
|
476
|
+
None
|
|
477
|
+
>>> parse_directive_value('boundscheck', 'True')
|
|
478
|
+
True
|
|
479
|
+
>>> parse_directive_value('boundscheck', 'true')
|
|
480
|
+
Traceback (most recent call last):
|
|
481
|
+
...
|
|
482
|
+
ValueError: boundscheck directive must be set to True or False, got 'true'
|
|
483
|
+
|
|
484
|
+
>>> parse_directive_value('c_string_encoding', 'us-ascii')
|
|
485
|
+
'ascii'
|
|
486
|
+
>>> parse_directive_value('c_string_type', 'str')
|
|
487
|
+
'str'
|
|
488
|
+
>>> parse_directive_value('c_string_type', 'bytes')
|
|
489
|
+
'bytes'
|
|
490
|
+
>>> parse_directive_value('c_string_type', 'bytearray')
|
|
491
|
+
'bytearray'
|
|
492
|
+
>>> parse_directive_value('c_string_type', 'unicode')
|
|
493
|
+
'str'
|
|
494
|
+
>>> parse_directive_value('c_string_type', 'unnicode')
|
|
495
|
+
Traceback (most recent call last):
|
|
496
|
+
ValueError: c_string_type directive must be one of ('bytes', 'bytearray', 'str', 'unicode'), got 'unnicode'
|
|
497
|
+
"""
|
|
498
|
+
type = directive_types.get(name)
|
|
499
|
+
if not type:
|
|
500
|
+
return None
|
|
501
|
+
orig_value = value
|
|
502
|
+
if type is bool:
|
|
503
|
+
value = str(value)
|
|
504
|
+
if value == 'True':
|
|
505
|
+
return True
|
|
506
|
+
if value == 'False':
|
|
507
|
+
return False
|
|
508
|
+
if relaxed_bool:
|
|
509
|
+
value = value.lower()
|
|
510
|
+
if value in ("true", "yes"):
|
|
511
|
+
return True
|
|
512
|
+
elif value in ("false", "no"):
|
|
513
|
+
return False
|
|
514
|
+
raise ValueError("%s directive must be set to True or False, got '%s'" % (
|
|
515
|
+
name, orig_value))
|
|
516
|
+
elif type is int:
|
|
517
|
+
try:
|
|
518
|
+
return int(value)
|
|
519
|
+
except ValueError:
|
|
520
|
+
raise ValueError("%s directive must be set to an integer, got '%s'" % (
|
|
521
|
+
name, orig_value))
|
|
522
|
+
elif type is str:
|
|
523
|
+
return str(value)
|
|
524
|
+
elif callable(type):
|
|
525
|
+
return type(name, value)
|
|
526
|
+
else:
|
|
527
|
+
assert False
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
|
|
531
|
+
current_settings=None):
|
|
532
|
+
"""
|
|
533
|
+
Parses a comma-separated list of pragma options. Whitespace
|
|
534
|
+
is not considered.
|
|
535
|
+
|
|
536
|
+
>>> parse_directive_list(' ')
|
|
537
|
+
{}
|
|
538
|
+
>>> (parse_directive_list('boundscheck=True') ==
|
|
539
|
+
... {'boundscheck': True})
|
|
540
|
+
True
|
|
541
|
+
>>> parse_directive_list(' asdf')
|
|
542
|
+
Traceback (most recent call last):
|
|
543
|
+
...
|
|
544
|
+
ValueError: Expected "=" in option "asdf"
|
|
545
|
+
>>> parse_directive_list('boundscheck=hey')
|
|
546
|
+
Traceback (most recent call last):
|
|
547
|
+
...
|
|
548
|
+
ValueError: boundscheck directive must be set to True or False, got 'hey'
|
|
549
|
+
>>> parse_directive_list('unknown=True')
|
|
550
|
+
Traceback (most recent call last):
|
|
551
|
+
...
|
|
552
|
+
ValueError: Unknown option: "unknown"
|
|
553
|
+
>>> warnings = parse_directive_list('warn.all=True')
|
|
554
|
+
>>> len(warnings) > 1
|
|
555
|
+
True
|
|
556
|
+
>>> sum(warnings.values()) == len(warnings) # all true.
|
|
557
|
+
True
|
|
558
|
+
"""
|
|
559
|
+
if current_settings is None:
|
|
560
|
+
result = {}
|
|
561
|
+
else:
|
|
562
|
+
result = current_settings
|
|
563
|
+
for item in s.split(','):
|
|
564
|
+
item = item.strip()
|
|
565
|
+
if not item:
|
|
566
|
+
continue
|
|
567
|
+
if '=' not in item:
|
|
568
|
+
raise ValueError('Expected "=" in option "%s"' % item)
|
|
569
|
+
name, value = [s.strip() for s in item.strip().split('=', 1)]
|
|
570
|
+
if name not in _directive_defaults:
|
|
571
|
+
found = False
|
|
572
|
+
if name.endswith('.all'):
|
|
573
|
+
prefix = name[:-3]
|
|
574
|
+
for directive in _directive_defaults:
|
|
575
|
+
if directive.startswith(prefix):
|
|
576
|
+
found = True
|
|
577
|
+
parsed_value = parse_directive_value(directive, value, relaxed_bool=relaxed_bool)
|
|
578
|
+
result[directive] = parsed_value
|
|
579
|
+
if not found and not ignore_unknown:
|
|
580
|
+
raise ValueError('Unknown option: "%s"' % name)
|
|
581
|
+
elif directive_types.get(name) is list:
|
|
582
|
+
if name in result:
|
|
583
|
+
result[name].append(value)
|
|
584
|
+
else:
|
|
585
|
+
result[name] = [value]
|
|
586
|
+
else:
|
|
587
|
+
parsed_value = parse_directive_value(name, value, relaxed_bool=relaxed_bool)
|
|
588
|
+
result[name] = parsed_value
|
|
589
|
+
return result
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def parse_variable_value(value):
|
|
593
|
+
"""
|
|
594
|
+
Parses value as an option value for the given name and returns
|
|
595
|
+
the interpreted value.
|
|
596
|
+
|
|
597
|
+
>>> parse_variable_value('True')
|
|
598
|
+
True
|
|
599
|
+
>>> parse_variable_value('true')
|
|
600
|
+
'true'
|
|
601
|
+
>>> parse_variable_value('us-ascii')
|
|
602
|
+
'us-ascii'
|
|
603
|
+
>>> parse_variable_value('str')
|
|
604
|
+
'str'
|
|
605
|
+
>>> parse_variable_value('123')
|
|
606
|
+
123
|
|
607
|
+
>>> parse_variable_value('1.23')
|
|
608
|
+
1.23
|
|
609
|
+
|
|
610
|
+
"""
|
|
611
|
+
if value == "True":
|
|
612
|
+
return True
|
|
613
|
+
elif value == "False":
|
|
614
|
+
return False
|
|
615
|
+
elif value == "None":
|
|
616
|
+
return None
|
|
617
|
+
elif value.isdigit():
|
|
618
|
+
return int(value)
|
|
619
|
+
else:
|
|
620
|
+
try:
|
|
621
|
+
value = float(value)
|
|
622
|
+
except Exception:
|
|
623
|
+
# Not a float
|
|
624
|
+
pass
|
|
625
|
+
return value
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def parse_compile_time_env(s, current_settings=None):
|
|
629
|
+
"""
|
|
630
|
+
Parses a comma-separated list of pragma options. Whitespace
|
|
631
|
+
is not considered.
|
|
632
|
+
|
|
633
|
+
>>> parse_compile_time_env(' ')
|
|
634
|
+
{}
|
|
635
|
+
>>> (parse_compile_time_env('HAVE_OPENMP=True') ==
|
|
636
|
+
... {'HAVE_OPENMP': True})
|
|
637
|
+
True
|
|
638
|
+
>>> parse_compile_time_env(' asdf')
|
|
639
|
+
Traceback (most recent call last):
|
|
640
|
+
...
|
|
641
|
+
ValueError: Expected "=" in option "asdf"
|
|
642
|
+
>>> parse_compile_time_env('NUM_THREADS=4') == {'NUM_THREADS': 4}
|
|
643
|
+
True
|
|
644
|
+
>>> parse_compile_time_env('unknown=anything') == {'unknown': 'anything'}
|
|
645
|
+
True
|
|
646
|
+
"""
|
|
647
|
+
if current_settings is None:
|
|
648
|
+
result = {}
|
|
649
|
+
else:
|
|
650
|
+
result = current_settings
|
|
651
|
+
for item in s.split(','):
|
|
652
|
+
item = item.strip()
|
|
653
|
+
if not item:
|
|
654
|
+
continue
|
|
655
|
+
if '=' not in item:
|
|
656
|
+
raise ValueError('Expected "=" in option "%s"' % item)
|
|
657
|
+
name, value = [s.strip() for s in item.split('=', 1)]
|
|
658
|
+
result[name] = parse_variable_value(value)
|
|
659
|
+
return result
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
# ------------------------------------------------------------------------
|
|
663
|
+
# CompilationOptions are constructed from user input and are the `option`
|
|
664
|
+
# object passed throughout the compilation pipeline.
|
|
665
|
+
|
|
666
|
+
class CompilationOptions:
|
|
667
|
+
r"""
|
|
668
|
+
See default_options at the end of this module for a list of all possible
|
|
669
|
+
options and CmdLine.usage and CmdLine.parse_command_line() for their
|
|
670
|
+
meaning.
|
|
671
|
+
"""
|
|
672
|
+
def __init__(self, defaults=None, **kw):
|
|
673
|
+
self.include_path = []
|
|
674
|
+
if defaults:
|
|
675
|
+
if isinstance(defaults, CompilationOptions):
|
|
676
|
+
defaults = defaults.__dict__
|
|
677
|
+
else:
|
|
678
|
+
defaults = default_options
|
|
679
|
+
|
|
680
|
+
options = dict(defaults)
|
|
681
|
+
options.update(kw)
|
|
682
|
+
|
|
683
|
+
# let's assume 'default_options' contains a value for most known compiler options
|
|
684
|
+
# and validate against them
|
|
685
|
+
unknown_options = set(options) - set(default_options)
|
|
686
|
+
# ignore valid options that are not in the defaults
|
|
687
|
+
unknown_options.difference_update(['include_path'])
|
|
688
|
+
if unknown_options:
|
|
689
|
+
message = "got unknown compilation option%s, please remove: %s" % (
|
|
690
|
+
's' if len(unknown_options) > 1 else '',
|
|
691
|
+
', '.join(unknown_options))
|
|
692
|
+
raise ValueError(message)
|
|
693
|
+
|
|
694
|
+
directive_defaults = get_directive_defaults()
|
|
695
|
+
directives = dict(options['compiler_directives']) # copy mutable field
|
|
696
|
+
# check for invalid directives
|
|
697
|
+
unknown_directives = set(directives) - set(directive_defaults)
|
|
698
|
+
if unknown_directives:
|
|
699
|
+
message = "got unknown compiler directive%s: %s" % (
|
|
700
|
+
's' if len(unknown_directives) > 1 else '',
|
|
701
|
+
', '.join(unknown_directives))
|
|
702
|
+
raise ValueError(message)
|
|
703
|
+
options['compiler_directives'] = directives
|
|
704
|
+
if directives.get('np_pythran', False) and not options['cplus']:
|
|
705
|
+
import warnings
|
|
706
|
+
warnings.warn("C++ mode forced when in Pythran mode!")
|
|
707
|
+
options['cplus'] = True
|
|
708
|
+
if 'language_level' not in kw and directives.get('language_level'):
|
|
709
|
+
options['language_level'] = directives['language_level']
|
|
710
|
+
elif not options.get('language_level'):
|
|
711
|
+
options['language_level'] = directive_defaults.get('language_level')
|
|
712
|
+
if 'formal_grammar' in directives and 'formal_grammar' not in kw:
|
|
713
|
+
options['formal_grammar'] = directives['formal_grammar']
|
|
714
|
+
|
|
715
|
+
self.__dict__.update(options)
|
|
716
|
+
|
|
717
|
+
def configure_language_defaults(self, source_extension):
|
|
718
|
+
if source_extension == 'py':
|
|
719
|
+
if self.compiler_directives.get('binding') is None:
|
|
720
|
+
self.compiler_directives['binding'] = True
|
|
721
|
+
|
|
722
|
+
def get_fingerprint(self):
|
|
723
|
+
r"""
|
|
724
|
+
Return a string that contains all the options that are relevant for cache invalidation.
|
|
725
|
+
"""
|
|
726
|
+
# Collect only the data that can affect the generated file(s).
|
|
727
|
+
data = {}
|
|
728
|
+
|
|
729
|
+
for key, value in self.__dict__.items():
|
|
730
|
+
if key in ['show_version', 'errors_to_stderr', 'verbose', 'quiet']:
|
|
731
|
+
# verbosity flags have no influence on the compilation result
|
|
732
|
+
continue
|
|
733
|
+
elif key in ['output_file', 'output_dir']:
|
|
734
|
+
# ignore the exact name of the output file
|
|
735
|
+
continue
|
|
736
|
+
elif key in ['depfile']:
|
|
737
|
+
# external build system dependency tracking file does not influence outputs
|
|
738
|
+
continue
|
|
739
|
+
elif key in ['timestamps']:
|
|
740
|
+
# the cache cares about the content of files, not about the timestamps of sources
|
|
741
|
+
continue
|
|
742
|
+
elif key in ['cache']:
|
|
743
|
+
# hopefully caching has no influence on the compilation result
|
|
744
|
+
continue
|
|
745
|
+
elif key in ['compiler_directives']:
|
|
746
|
+
# directives passed on to the C compiler do not influence the generated C code
|
|
747
|
+
continue
|
|
748
|
+
elif key in ['include_path']:
|
|
749
|
+
# this path changes which headers are tracked as dependencies,
|
|
750
|
+
# it has no influence on the generated C code
|
|
751
|
+
continue
|
|
752
|
+
elif key in ['working_path']:
|
|
753
|
+
# this path changes where modules and pxd files are found;
|
|
754
|
+
# their content is part of the fingerprint anyway, their
|
|
755
|
+
# absolute path does not matter
|
|
756
|
+
continue
|
|
757
|
+
elif key in ['create_extension']:
|
|
758
|
+
# create_extension() has already mangled the options, e.g.,
|
|
759
|
+
# embedded_metadata, when the fingerprint is computed so we
|
|
760
|
+
# ignore it here.
|
|
761
|
+
continue
|
|
762
|
+
elif key in ['build_dir']:
|
|
763
|
+
# the (temporary) directory where we collect dependencies
|
|
764
|
+
# has no influence on the C output
|
|
765
|
+
continue
|
|
766
|
+
elif key in ['use_listing_file', 'generate_pxi', 'annotate', 'annotate_coverage_xml']:
|
|
767
|
+
# all output files are contained in the cache so the types of
|
|
768
|
+
# files generated must be part of the fingerprint
|
|
769
|
+
data[key] = value
|
|
770
|
+
elif key in ['formal_grammar', 'evaluate_tree_assertions']:
|
|
771
|
+
# these bits can change whether compilation to C passes/fails
|
|
772
|
+
data[key] = value
|
|
773
|
+
elif key in ['embedded_metadata', 'emit_linenums',
|
|
774
|
+
'c_line_in_traceback', 'gdb_debug',
|
|
775
|
+
'relative_path_in_code_position_comments']:
|
|
776
|
+
# the generated code contains additional bits when these are set
|
|
777
|
+
data[key] = value
|
|
778
|
+
elif key in ['cplus', 'language_level', 'compile_time_env', 'np_pythran']:
|
|
779
|
+
# assorted bits that, e.g., influence the parser
|
|
780
|
+
data[key] = value
|
|
781
|
+
elif key in ['capi_reexport_cincludes', 'common_utility_include_dir']:
|
|
782
|
+
if value:
|
|
783
|
+
# our caching implementation does not yet include fingerprints of all the header files
|
|
784
|
+
raise NotImplementedError(f'{key} is not compatible with Cython caching')
|
|
785
|
+
else:
|
|
786
|
+
# any unexpected option should go into the fingerprint; it's better
|
|
787
|
+
# to recompile than to return incorrect results from the cache.
|
|
788
|
+
data[key] = value
|
|
789
|
+
|
|
790
|
+
def to_fingerprint(item):
|
|
791
|
+
r"""
|
|
792
|
+
Recursively turn item into a string, turning dicts into lists with
|
|
793
|
+
deterministic ordering.
|
|
794
|
+
"""
|
|
795
|
+
if isinstance(item, dict):
|
|
796
|
+
item = sorted([(repr(key), to_fingerprint(value)) for key, value in item.items()])
|
|
797
|
+
return repr(item)
|
|
798
|
+
|
|
799
|
+
return to_fingerprint(data)
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
# ------------------------------------------------------------------------
|
|
803
|
+
#
|
|
804
|
+
# Set the default options depending on the platform
|
|
805
|
+
#
|
|
806
|
+
# ------------------------------------------------------------------------
|
|
807
|
+
|
|
808
|
+
default_options = dict(
|
|
809
|
+
show_version=0,
|
|
810
|
+
use_listing_file=0,
|
|
811
|
+
errors_to_stderr=1,
|
|
812
|
+
cplus=0,
|
|
813
|
+
output_file=None,
|
|
814
|
+
depfile=None,
|
|
815
|
+
annotate=None,
|
|
816
|
+
annotate_coverage_xml=None,
|
|
817
|
+
generate_pxi=0,
|
|
818
|
+
capi_reexport_cincludes=0,
|
|
819
|
+
working_path="",
|
|
820
|
+
timestamps=None,
|
|
821
|
+
verbose=0,
|
|
822
|
+
quiet=0,
|
|
823
|
+
compiler_directives={},
|
|
824
|
+
embedded_metadata={},
|
|
825
|
+
evaluate_tree_assertions=False,
|
|
826
|
+
emit_linenums=False,
|
|
827
|
+
relative_path_in_code_position_comments=True,
|
|
828
|
+
c_line_in_traceback=None,
|
|
829
|
+
language_level=None, # warn but default to 2
|
|
830
|
+
formal_grammar=False,
|
|
831
|
+
gdb_debug=False,
|
|
832
|
+
compile_time_env=None,
|
|
833
|
+
module_name=None,
|
|
834
|
+
common_utility_include_dir=None,
|
|
835
|
+
output_dir=None,
|
|
836
|
+
build_dir=None,
|
|
837
|
+
cache=None,
|
|
838
|
+
create_extension=None,
|
|
839
|
+
np_pythran=False,
|
|
840
|
+
legacy_implicit_noexcept=None,
|
|
841
|
+
shared_c_file_path=None,
|
|
842
|
+
shared_utility_qualified_name = None,
|
|
843
|
+
)
|