Skip to content

Commit 71a1fc0

Browse files
committed
Embed __version__ also in the cython generated module (Issue 167).
1 parent cab18c8 commit 71a1fc0

File tree

7 files changed

+52
-6
lines changed

7 files changed

+52
-6
lines changed

cefpython/cef3/linux/compile.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import subprocess
66
import platform
77
import stat
8+
import re
89

910
# This will not show "Segmentation fault" error message:
1011
# | subprocess.call(["python", "./wxpython.py"])
@@ -20,12 +21,21 @@
2021
# 5. To display debug backtrace type "cy bt"
2122
# 6. More commands: http://docs.cython.org/src/userguide/debugging.html
2223

23-
if len(sys.argv) > 1 and sys.argv[1] == "debug":
24+
if len(sys.argv) > 1 and "--debug" in sys.argv:
2425
DEBUG = True
2526
print("DEBUG mode On")
2627
else:
2728
DEBUG = False
2829

30+
if len(sys.argv) > 1 and re.search(r"^\d+\.\d+$", sys.argv[1]):
31+
VERSION = sys.argv[1]
32+
else:
33+
print("[compile.py] ERROR: expected first argument to be version number")
34+
print(" Allowed version format: \\d+\.\\d+")
35+
sys.exit(1)
36+
37+
print("VERSION=%s"%VERSION)
38+
2939
BITS = platform.architecture()[0]
3040
assert (BITS == "32bit" or BITS == "64bit")
3141

@@ -111,10 +121,16 @@
111121

112122
os.chdir("./setup")
113123

114-
ret = subprocess.call("python fix_includes.py", shell=True)
124+
ret = subprocess.call("python fix_pyx_files.py", shell=True)
115125
if ret != 0:
116126
sys.exit("ERROR")
117127

128+
# Create __version__.pyx after fix_pyx_files.py was called,
129+
# as that script deletes old pyx files before copying new ones.
130+
print("Creating __version__.pyx file")
131+
with open("__version__.pyx", "w") as fo:
132+
fo.write('__version__ = "{}"\n'.format(VERSION))
133+
118134
if DEBUG:
119135
ret = subprocess.call("python-dbg setup.py build_ext --inplace"
120136
" --cython-gdb", shell=True)
File renamed without changes.

cefpython/cef3/mac/compile.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import subprocess
66
import platform
77
import stat
8+
import re
89

910
# This will not show "Segmentation fault" error message:
1011
# | subprocess.call(["python", "./wxpython.py"])
@@ -20,12 +21,21 @@
2021
# 5. To display debug backtrace type "cy bt"
2122
# 6. More commands: http://docs.cython.org/src/userguide/debugging.html
2223

23-
if len(sys.argv) > 1 and sys.argv[1] == "debug":
24+
if len(sys.argv) > 1 and "--debug" in sys.argv:
2425
DEBUG = True
2526
print("DEBUG mode On")
2627
else:
2728
DEBUG = False
2829

30+
if len(sys.argv) > 1 and re.search(r"^\d+\.\d+$", sys.argv[1]):
31+
VERSION = sys.argv[1]
32+
else:
33+
print("[compile.py] ERROR: expected first argument to be version number")
34+
print(" Allowed version format: \\d+\.\\d+")
35+
sys.exit(1)
36+
37+
print("VERSION=%s"%VERSION)
38+
2939
BITS = platform.architecture()[0]
3040
assert (BITS == "32bit" or BITS == "64bit")
3141
PYTHON_CMD = "python"
@@ -129,10 +139,16 @@
129139

130140
os.chdir("./setup")
131141

132-
ret = subprocess.call(PYTHON_CMD+" fix_includes.py", shell=True)
142+
ret = subprocess.call(PYTHON_CMD+" fix_pyx_files.py", shell=True)
133143
if ret != 0:
134144
sys.exit("ERROR")
135145

146+
# Create __version__.pyx after fix_pyx_files.py was called,
147+
# as that script deletes old pyx files before copying new ones.
148+
print("Creating __version__.pyx file")
149+
with open("__version__.pyx", "w") as fo:
150+
fo.write('__version__ = "{}"\n'.format(VERSION))
151+
136152
if DEBUG:
137153
ret = subprocess.call(PYTHON_CMD+"-dbg setup.py build_ext --inplace"
138154
" --cython-gdb", shell=True)

cefpython/cef3/windows/compile.bat

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,18 @@ echo [compile.bat] Entering setup/ directory
176176
cd %setup%
177177

178178
echo [compile.bat] Copying .pyx files to setup/ directory and fixing includes
179-
python fix_includes.py
179+
python fix_pyx_files.py
180180
if %errorlevel% neq 0 (
181-
echo [compile.bat] ERROR: running fix_includes.py failed
181+
echo [compile.bat] ERROR: running fix_pyx_files.py failed
182+
exit /B 1
183+
)
184+
185+
:: __version__.pyx must be generated after running fix_pyx_files.py,
186+
:: as that script deletes old pyx files before copying new ones.
187+
echo [compile.bat] Creating __version__.pyx file
188+
echo __version__ = "%version%">>__version__.pyx
189+
if %errorlevel% neq 0 (
190+
echo [compile.bat] ERROR: writing __version__.pyx failed
182191
exit /B 1
183192
)
184193

File renamed without changes.

cefpython/cefpython.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
# like "bool(1)" being invalid, in pyx files.
8484

8585
# All .pyx files need to be included in this file.
86+
# Includes being made in other .pyx files are allowed to help
87+
# IDE completion, but will be removed during cython compilation.
88+
89+
# Version file is generated by the compile.bat/compile.py script.
90+
include "__version__.pyx"
8691

8792
include "cython_includes/compile_time_constants.pxi"
8893
include "imports.pyx"

0 commit comments

Comments
 (0)