Commit 487c1ff8 authored by Michael Büsch's avatar Michael Büsch

cython: Add posix/win annotations

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent 83559f15
...@@ -19,6 +19,8 @@ In order to support both compiling the Awlsim core with Cython and running the s ...@@ -19,6 +19,8 @@ In order to support both compiling the Awlsim core with Cython and running the s
* `#@cy` : Enable (un-comment) this line during Cython patching. * `#@cy` : Enable (un-comment) this line during Cython patching.
* `#@cy2` : Enable (un-comment) this line during Cython patching, if compiling for Python 2. * `#@cy2` : Enable (un-comment) this line during Cython patching, if compiling for Python 2.
* `#@cy3` : Enable (un-comment) this line during Cython patching, if compiling for Python 3. * `#@cy3` : Enable (un-comment) this line during Cython patching, if compiling for Python 3.
* `#@cy-posix` : Enable (un-comment) this line during Cython patching, if compiling for a Posix platform.
* `#@cy-win` : Enable (un-comment) this line during Cython patching, if compiling for a Windows platform.
* `#@nocy` : Disable (comment) this line during Cython patching. * `#@nocy` : Disable (comment) this line during Cython patching.
* `#@no-cython-patch` : Do not touch this line during cython patching. * `#@no-cython-patch` : Do not touch this line during cython patching.
* `#+NoneToNULL` : Transform all `None` keywords in this line into `NULL`. * `#+NoneToNULL` : Transform all `None` keywords in this line into `NULL`.
......
# #
# Cython patcher # Cython patcher
# v1.15 # v1.16
# #
# Copyright (C) 2012-2018 Michael Buesch <m@bues.ch> # Copyright (C) 2012-2018 Michael Buesch <m@bues.ch>
# #
...@@ -40,6 +40,8 @@ CythonBuildExtension = None ...@@ -40,6 +40,8 @@ CythonBuildExtension = None
_Cython_Distutils_build_ext = None _Cython_Distutils_build_ext = None
_cythonPossible = None _cythonPossible = None
_cythonBuildUnits = [] _cythonBuildUnits = []
_isWindows = os.name.lower() in {"nt", "ce"}
_isPosix = os.name.lower() == "posix"
def getSystemMemBytesCount(): def getSystemMemBytesCount():
...@@ -137,16 +139,20 @@ def pyCythonPatch(fromFile, toFile): ...@@ -137,16 +139,20 @@ def pyCythonPatch(fromFile, toFile):
if not line.endswith("\n"): if not line.endswith("\n"):
line += "\n" line += "\n"
return line return line
if "#@cy" in stripLine and\ if "#@cy-posix" in stripLine:
not "#@cy2" in stripLine and\ if _isPosix:
not "#@cy3" in stripLine: line = uncomment(line, "#@cy-posix")
line = uncomment(line, "#@cy") elif "#@cy-win" in stripLine:
if sys.version_info[0] < 3: if _isWindows:
if "#@cy2" in stripLine: line = uncomment(line, "#@cy-win")
elif "#@cy2" in stripLine:
if sys.version_info[0] < 3:
line = uncomment(line, "#@cy2") line = uncomment(line, "#@cy2")
else: elif "#@cy3" in stripLine:
if "#@cy3" in stripLine: if sys.version_info[0] >= 3:
line = uncomment(line, "#@cy3") line = uncomment(line, "#@cy3")
elif "#@cy" in stripLine:
line = uncomment(line, "#@cy")
# Sprinkle magic cdef/cpdef, as requested by #+cdef/#+cpdef # Sprinkle magic cdef/cpdef, as requested by #+cdef/#+cpdef
if "#+cdef-" in stripLine: if "#+cdef-" in stripLine:
...@@ -198,9 +204,11 @@ def pyCythonPatch(fromFile, toFile): ...@@ -198,9 +204,11 @@ def pyCythonPatch(fromFile, toFile):
line = re.sub(r'\b(0x[0-9a-fA-F]+)\b', r'\1LL', line) line = re.sub(r'\b(0x[0-9a-fA-F]+)\b', r'\1LL', line)
# Comment all lines containing #@nocy # Comment all lines containing #@nocy
# or #@cyX for the not matching version.
if "#@nocy" in stripLine: if "#@nocy" in stripLine:
line = "#" + line line = "#" + line
# Comment all lines containing #@cyX
# for the not matching version.
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
if "#@cy3" in stripLine: if "#@cy3" in stripLine:
line = "#" + line line = "#" + line
...@@ -208,6 +216,15 @@ def pyCythonPatch(fromFile, toFile): ...@@ -208,6 +216,15 @@ def pyCythonPatch(fromFile, toFile):
if "#@cy2" in stripLine: if "#@cy2" in stripLine:
line = "#" + line line = "#" + line
# Comment all lines containing #@cy-posix/win
# for the not matching platform.
if _isPosix:
if "#@cy-win" in stripLine:
line = "#" + line
elif _isWindows:
if "#@cy-posix" in stripLine:
line = "#" + line
# Remove compat stuff # Remove compat stuff
line = line.replace("absolute_import,", "") line = line.replace("absolute_import,", "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment