Skip to content

Commit 7e167ac

Browse files
CzarekCzarek
authored andcommitted
Porting to Mac (Issue 21). The cefpython module compiles
fine. Created the BuildOnMac wiki page. Next task to do is a wxpython.py example.
1 parent b8d4481 commit 7e167ac

File tree

22 files changed

+567
-20
lines changed

22 files changed

+567
-20
lines changed

cefpython/cef3/cefpython_public_api.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
#if defined(OS_WIN)
3232
#include "windows/setup/cefpython.h"
33-
#endif
34-
35-
#if defined(OS_LINUX)
33+
#elif defined(OS_LINUX)
3634
#include "linux/setup/cefpython.h"
35+
#elif defined(OS_MACOSX)
36+
#include "mac/setup/cefpython.h"
3737
#endif
3838

3939
// CEFPYTHON_PUBLIC_API_H
40-
#endif
40+
#endif

cefpython/cef3/client_handler/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# -Wl,-z,relro
1010

1111
CC = g++
12-
CCFLAGS = -g -fPIC -Wall -Werror
12+
CCFLAGS = -g -fPIC -Wall -Werror $(CEF_CCFLAGS)
1313

1414
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
1515
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/cef.framework/
2+
/subprocess

cefpython/cef3/mac/compile.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import sys
2+
import os
3+
import glob
4+
import shutil
5+
import subprocess
6+
import platform
7+
import stat
8+
9+
# This will not show "Segmentation fault" error message:
10+
# | subprocess.call(["python", "./wxpython.py"])
11+
# You need to call it with shell=True for this kind of
12+
# error message to be shown:
13+
# | subprocess.call("python wxpython.py", shell=True)
14+
15+
# How to debug:
16+
# 1. Install "python-dbg" package
17+
# 2. Install "python-wxgtk2.8-dbg" package
18+
# 3. Run "python compile.py debug"
19+
# 4. In cygdb type "cy run"
20+
# 5. To display debug backtrace type "cy bt"
21+
# 6. More commands: http://docs.cython.org/src/userguide/debugging.html
22+
23+
if len(sys.argv) > 1 and sys.argv[1] == "debug":
24+
DEBUG = True
25+
print("DEBUG mode On")
26+
else:
27+
DEBUG = False
28+
29+
BITS = platform.architecture()[0]
30+
assert (BITS == "32bit" or BITS == "64bit")
31+
PYTHON_CMD = "python"
32+
if sys.maxint == 2147483647:
33+
BITS = "32bit"
34+
PYTHON_CMD = "arch -i386 python"
35+
36+
PYVERSION = str(sys.version_info[0])+str(sys.version_info[1])
37+
print("PYVERSION = %s" % PYVERSION)
38+
print("BITS = %s" % BITS)
39+
40+
os.environ["CC"] = "gcc"
41+
os.environ["CXX"] = "g++"
42+
43+
print("Compiling C++ projects")
44+
45+
# Need to allow continuing even when make fails, as it may
46+
# fail because the "public" function declaration is not yet
47+
# in "cefpython.h", but for it to be generated we need to run
48+
# cython compiling, so in this case you continue even when make
49+
# fails and then run the compile.py script again and this time
50+
# make should succeed.
51+
52+
os.chdir("./../../cpp_utils/")
53+
subprocess.call("rm -f *.o *.a", shell=True)
54+
55+
ret = subprocess.call("make -f Makefile", shell=True)
56+
if ret != 0:
57+
what = raw_input("make failed, press 'y' to continue, 'n' to stop: ")
58+
if what != "y":
59+
sys.exit(1)
60+
61+
os.chdir("./../cef3/client_handler/")
62+
subprocess.call("rm -f *.o *.a", shell=True)
63+
64+
ret = subprocess.call("make -f Makefile", shell=True)
65+
if ret != 0:
66+
what = raw_input("make failed, press 'y' to continue, 'n' to stop: ")
67+
if what != "y":
68+
sys.exit(1)
69+
70+
os.chdir("./../subprocess/")
71+
subprocess.call("rm -f *.o *.a", shell=True)
72+
subprocess.call("rm -f subprocess", shell=True)
73+
74+
ret = subprocess.call("make -f Makefile-libcefpythonapp", shell=True)
75+
if ret != 0:
76+
what = raw_input("make failed, press 'y' to continue, 'n' to stop: ")
77+
if what != "y":
78+
sys.exit(1)
79+
80+
ret = subprocess.call("make -f Makefile", shell=True)
81+
if ret != 0:
82+
what = raw_input("make failed, press 'y' to continue, 'n' to stop: ")
83+
if what != "y":
84+
sys.exit(1)
85+
subprocess_exe = "./../mac/binaries_%s/subprocess" % (BITS)
86+
if os.path.exists("./subprocess"):
87+
shutil.copyfile("./subprocess", subprocess_exe)
88+
st = os.stat(subprocess_exe)
89+
os.chmod(subprocess_exe, st.st_mode | stat.S_IEXEC)
90+
91+
# os.chdir("./../v8function_handler/")
92+
# ret = subprocess.call("make -f Makefile", shell=True)
93+
# if ret != 0:
94+
# what = raw_input("make failed, press 'y' to continue, 'n' to stop: ")
95+
# if what != "y":
96+
# sys.exit(1)
97+
98+
os.chdir("./../mac/")
99+
100+
try:
101+
os.remove("./binaries_%s/cefpython_py%s.so" % (BITS, PYVERSION))
102+
except OSError:
103+
pass
104+
105+
try:
106+
os.remove("./setup/cefpython_py%s.so" % PYVERSION)
107+
os.remove("./setup/cefpython_py%s_d.so" % PYVERSION)
108+
except OSError:
109+
pass
110+
111+
pyx_files = glob.glob("./setup/*.pyx")
112+
for f in pyx_files:
113+
os.remove(f)
114+
115+
try:
116+
shutil.rmtree("./setup/build")
117+
except OSError:
118+
pass
119+
120+
os.chdir("./setup")
121+
122+
ret = subprocess.call(PYTHON_CMD+" fix_includes.py", shell=True)
123+
if ret != 0:
124+
sys.exit("ERROR")
125+
126+
if DEBUG:
127+
ret = subprocess.call(PYTHON_CMD+"-dbg setup.py build_ext --inplace"
128+
" --cython-gdb", shell=True)
129+
else:
130+
ret = subprocess.call(PYTHON_CMD+" setup.py build_ext --inplace", shell=True)
131+
132+
if DEBUG:
133+
shutil.rmtree("./../binaries_%s/cython_debug/" % BITS, ignore_errors=True)
134+
shutil.copytree("./cython_debug/", "./../binaries_%s/cython_debug/" % BITS)
135+
136+
os.chdir("../")
137+
138+
oldpyxfiles = glob.glob("./setup/*.pyx")
139+
print("Removing old pyx files in /setup/: %s" % oldpyxfiles)
140+
for pyxfile in oldpyxfiles:
141+
if os.path.exists(pyxfile):
142+
os.remove(pyxfile)
143+
144+
if ret != 0:
145+
sys.exit("ERROR")
146+
147+
if DEBUG:
148+
os.rename("./setup/cefpython_py%s_d.so" % PYVERSION, "./binaries_%s/cefpython_py%s.so" % (BITS, PYVERSION))
149+
else:
150+
os.rename("./setup/cefpython_py%s.so" % PYVERSION, "./binaries_%s/cefpython_py%s.so" % (BITS, PYVERSION))
151+
152+
print("DONE")
153+
154+
os.chdir("./binaries_%s" % BITS)
155+
if DEBUG:
156+
subprocess.call("cygdb . --args python-dbg wxpython.py", shell=True)
157+
else:
158+
subprocess.call(PYTHON_CMD+" wxpython.py", shell=True)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build/
2+
cefpython.cpp
3+
cython_debug/
4+
*.pyx
5+
*.cpp
6+
*.a
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef __PYX_HAVE__cefpython_py27
2+
#define __PYX_HAVE__cefpython_py27
3+
4+
5+
#ifndef __PYX_HAVE_API__cefpython_py27
6+
7+
#ifndef __PYX_EXTERN_C
8+
#ifdef __cplusplus
9+
#define __PYX_EXTERN_C extern "C"
10+
#else
11+
#define __PYX_EXTERN_C extern
12+
#endif
13+
#endif
14+
15+
__PYX_EXTERN_C DL_IMPORT(void) PyBrowser_ShowDevTools(CefRefPtr<CefBrowser>);
16+
__PYX_EXTERN_C DL_IMPORT(void) PyTaskRunnable(int);
17+
__PYX_EXTERN_C DL_IMPORT(void) V8ContextHandler_OnContextCreated(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>);
18+
__PYX_EXTERN_C DL_IMPORT(void) V8ContextHandler_OnContextReleased(int, int64);
19+
__PYX_EXTERN_C DL_IMPORT(void) V8FunctionHandler_Execute(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString &, CefRefPtr<CefListValue>);
20+
__PYX_EXTERN_C DL_IMPORT(void) RemovePythonCallbacksForFrame(int);
21+
__PYX_EXTERN_C DL_IMPORT(bool) ExecutePythonCallback(CefRefPtr<CefBrowser>, int, CefRefPtr<CefListValue>);
22+
__PYX_EXTERN_C DL_IMPORT(bool) LifespanHandler_OnBeforePopup(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString const &, CefString const &, int const , CefWindowInfo &, CefRefPtr<CefClient> &, CefBrowserSettings &, bool *);
23+
__PYX_EXTERN_C DL_IMPORT(void) LifespanHandler_OnAfterCreated(CefRefPtr<CefBrowser>);
24+
__PYX_EXTERN_C DL_IMPORT(bool) LifespanHandler_RunModal(CefRefPtr<CefBrowser>);
25+
__PYX_EXTERN_C DL_IMPORT(bool) LifespanHandler_DoClose(CefRefPtr<CefBrowser>);
26+
__PYX_EXTERN_C DL_IMPORT(void) LifespanHandler_OnBeforeClose(CefRefPtr<CefBrowser>);
27+
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnAddressChange(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString const &);
28+
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnTitleChange(CefRefPtr<CefBrowser>, CefString const &);
29+
__PYX_EXTERN_C DL_IMPORT(bool) DisplayHandler_OnTooltip(CefRefPtr<CefBrowser>, CefString &);
30+
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnStatusMessage(CefRefPtr<CefBrowser>, CefString const &);
31+
__PYX_EXTERN_C DL_IMPORT(bool) DisplayHandler_OnConsoleMessage(CefRefPtr<CefBrowser>, CefString const &, CefString const &, int);
32+
__PYX_EXTERN_C DL_IMPORT(bool) KeyboardHandler_OnPreKeyEvent(CefRefPtr<CefBrowser>, CefKeyEvent const &, CefEventHandle, bool *);
33+
__PYX_EXTERN_C DL_IMPORT(bool) KeyboardHandler_OnKeyEvent(CefRefPtr<CefBrowser>, CefKeyEvent const &, CefEventHandle);
34+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnBeforeResourceLoad(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefRequest>);
35+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnBeforeBrowse(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefRequest>, bool);
36+
__PYX_EXTERN_C DL_IMPORT(CefRefPtr<CefResourceHandler>) RequestHandler_GetResourceHandler(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefRequest>);
37+
__PYX_EXTERN_C DL_IMPORT(void) RequestHandler_OnResourceRedirect(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString const &, CefString &);
38+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_GetAuthCredentials(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, bool, CefString const &, int, CefString const &, CefString const &, CefRefPtr<CefAuthCallback>);
39+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnQuotaRequest(CefRefPtr<CefBrowser>, CefString const &, int64, CefRefPtr<CefQuotaCallback>);
40+
__PYX_EXTERN_C DL_IMPORT(CefRefPtr<CefCookieManager>) RequestHandler_GetCookieManager(CefRefPtr<CefBrowser>, CefString const &);
41+
__PYX_EXTERN_C DL_IMPORT(void) RequestHandler_OnProtocolExecution(CefRefPtr<CefBrowser>, CefString const &, bool &);
42+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnBeforePluginLoad(CefRefPtr<CefBrowser>, CefString const &, CefString const &, CefRefPtr<CefWebPluginInfo>);
43+
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnCertificateError(int, CefString const &, CefRefPtr<CefAllowCertificateErrorCallback>);
44+
__PYX_EXTERN_C DL_IMPORT(void) RequestHandler_OnRendererProcessTerminated(CefRefPtr<CefBrowser>, enum cef_termination_status_t);
45+
__PYX_EXTERN_C DL_IMPORT(void) RequestHandler_OnPluginCrashed(CefRefPtr<CefBrowser>, CefString const &);
46+
__PYX_EXTERN_C DL_IMPORT(bool) CookieVisitor_Visit(int, CefCookie const &, int, int, bool &);
47+
__PYX_EXTERN_C DL_IMPORT(void) StringVisitor_Visit(int, CefString const &);
48+
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadingStateChange(CefRefPtr<CefBrowser>, bool, bool, bool);
49+
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadStart(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>);
50+
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, int);
51+
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadError(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, enum cef_errorcode_t, CefString const &, CefString const &);
52+
__PYX_EXTERN_C DL_IMPORT(void) BrowserProcessHandler_OnRenderProcessThreadCreated(CefRefPtr<CefListValue>);
53+
__PYX_EXTERN_C DL_IMPORT(void) BrowserProcessHandler_OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine>);
54+
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetRootScreenRect(CefRefPtr<CefBrowser>, CefRect &);
55+
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetViewRect(CefRefPtr<CefBrowser>, CefRect &);
56+
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetScreenRect(CefRefPtr<CefBrowser>, CefRect &);
57+
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetScreenPoint(CefRefPtr<CefBrowser>, int, int, int &, int &);
58+
__PYX_EXTERN_C DL_IMPORT(bool) RenderHandler_GetScreenInfo(CefRefPtr<CefBrowser>, CefScreenInfo &);
59+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPopupShow(CefRefPtr<CefBrowser>, bool);
60+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPopupSize(CefRefPtr<CefBrowser>, CefRect const &);
61+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnPaint(CefRefPtr<CefBrowser>, cef_paint_element_type_t, std::vector<CefRect> &, void const *, int, int);
62+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnCursorChange(CefRefPtr<CefBrowser>, CefCursorHandle);
63+
__PYX_EXTERN_C DL_IMPORT(void) RenderHandler_OnScrollOffsetChanged(CefRefPtr<CefBrowser>);
64+
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_ProcessRequest(int, CefRefPtr<CefRequest>, CefRefPtr<CefCallback>);
65+
__PYX_EXTERN_C DL_IMPORT(void) ResourceHandler_GetResponseHeaders(int, CefRefPtr<CefResponse>, int64 &, CefString &);
66+
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_ReadResponse(int, void *, int, int &, CefRefPtr<CefCallback>);
67+
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_CanGetCookie(int, CefCookie const &);
68+
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_CanSetCookie(int, CefCookie const &);
69+
__PYX_EXTERN_C DL_IMPORT(void) ResourceHandler_Cancel(int);
70+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnUploadProgress(int, CefRefPtr<CefURLRequest>, uint64, uint64);
71+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnDownloadProgress(int, CefRefPtr<CefURLRequest>, uint64, uint64);
72+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnDownloadData(int, CefRefPtr<CefURLRequest>, void const *, size_t);
73+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnRequestComplete(int, CefRefPtr<CefURLRequest>);
74+
__PYX_EXTERN_C DL_IMPORT(void) App_OnBeforeCommandLineProcessing_BrowserProcess(CefRefPtr<CefCommandLine>);
75+
__PYX_EXTERN_C DL_IMPORT(bool) JavascriptDialogHandler_OnJavascriptDialog(CefRefPtr<CefBrowser>, CefString const &, CefString const &, enum cef_jsdialog_type_t, CefString const &, CefString const &, CefRefPtr<CefJSDialogCallback>, bool &);
76+
__PYX_EXTERN_C DL_IMPORT(bool) JavascriptDialogHandler_OnBeforeUnloadJavascriptDialog(CefRefPtr<CefBrowser>, CefString const &, bool, CefRefPtr<CefJSDialogCallback>);
77+
__PYX_EXTERN_C DL_IMPORT(void) JavascriptDialogHandler_OnResetJavascriptDialogState(CefRefPtr<CefBrowser>);
78+
__PYX_EXTERN_C DL_IMPORT(void) JavascriptDialogHandler_OnJavascriptDialogClosed(CefRefPtr<CefBrowser>);
79+
__PYX_EXTERN_C DL_IMPORT(void) cefpython_GetDebugOptions(bool *, std::string *);
80+
__PYX_EXTERN_C DL_IMPORT(bool) ApplicationSettings_GetBool(char const *);
81+
__PYX_EXTERN_C DL_IMPORT(bool) ApplicationSettings_GetBoolFromDict(char const *, char const *);
82+
__PYX_EXTERN_C DL_IMPORT(std::string) ApplicationSettings_GetString(char const *);
83+
__PYX_EXTERN_C DL_IMPORT(int) CommandLineSwitches_GetInt(char const *);
84+
85+
#endif /* !__PYX_HAVE_API__cefpython_py27 */
86+
87+
#if PY_MAJOR_VERSION < 3
88+
PyMODINIT_FUNC initcefpython_py27(void);
89+
#else
90+
PyMODINIT_FUNC PyInit_cefpython_py27(void);
91+
#endif
92+
93+
#endif /* !__PYX_HAVE__cefpython_py27 */
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright (c) 2012-2014 The CEF Python authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
# First, it copies all .pyx files from upper directory to setup/.
6+
# Then, fixes repeating of "include" statements in pyx files.
7+
8+
# Only the mainfile needs to have "include" statements,
9+
# but we're using PyCharm and to get rid of "unresolved references"
10+
# and other errors displayed in pycharm we are adding "include"
11+
# statements in all of the pyx files.
12+
13+
# I'm not 100% sure how includes work in Cython, but I suspect that
14+
# a few includes of the same file will include the same content more
15+
# than once, it should work, but function and variable definitions are
16+
# duplicated, it is some kind of overhead and it could lead to some
17+
# problems in the future, better to fix it now.
18+
19+
# It also checks cdef & cpdef functions whether they are not missing "except *",
20+
# it is required to add it when returning non-python type.
21+
22+
import glob
23+
import os
24+
import re
25+
import shutil
26+
import sys
27+
28+
def ExceptAllMissing(content):
29+
30+
# This is not perfect, won't detect C++ custom types, but will find
31+
# the built-in types, templates and pointers.
32+
patterns = []
33+
patterns.append(
34+
r"\bcp?def\s+"
35+
"((int|short|long|double|char|unsigned|float|double|cpp_bool"
36+
"|cpp_string|cpp_wstring|uint64_t|uintptr_t|void"
37+
"|CefString)\s+)+"
38+
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
39+
patterns.append(
40+
r"\bcp?def\s+"
41+
# A template ends with bracket: CefRefPtr[CefBrowser]
42+
# or a pointer ends with asterisk: CefBrowser*
43+
"[^\s]+[\]*]\s+"
44+
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
45+
patterns.append(
46+
r"\bcp?def\s+"
47+
# A reference, eg. CefString&
48+
"[^\s]+&\s+"
49+
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
50+
51+
for pattern in patterns:
52+
match = re.search(pattern, content)
53+
if match: break
54+
55+
if match:
56+
lineNumber = (content.count("\n", 0, match.start()) + 1)
57+
return lineNumber
58+
59+
print("\n")
60+
mainfile = "cefpython.pyx"
61+
62+
pyxfiles = glob.glob("../../../*.pyx")
63+
if not len(pyxfiles):
64+
sys.exit(1)
65+
pyxfiles = [file for file in pyxfiles if file.find(mainfile) == -1]
66+
# Now, pyxfiles contains all pyx files except the mainfile (cefpython.pyx),
67+
# we do not fix includes in mainfile.
68+
69+
# So that this is the right directory we're in.
70+
if os.path.exists("setup"):
71+
print("Wrong directory, we should be inside setup!")
72+
sys.exit(1)
73+
74+
# Remove old pyx files in setup directory.
75+
oldpyxfiles = glob.glob("./*.pyx")
76+
print("Removing old pyx files in /setup/: %s" % oldpyxfiles)
77+
for pyxfile in oldpyxfiles:
78+
if os.path.exists(pyxfile):
79+
os.remove(pyxfile)
80+
81+
# Copying pyxfiles and reading its contents.
82+
83+
print("Copying .pyx files to /setup/: %s" % pyxfiles)
84+
shutil.copy("../../../%s" % mainfile, "./%s" % mainfile)
85+
# Rest of the files will be copied in for loop below.
86+
87+
print("Fixing includes in .pyx files:")
88+
for pyxfile in pyxfiles:
89+
newfile = "./%s" % os.path.basename(pyxfile)
90+
shutil.copy(pyxfile, newfile)
91+
pyxfile = newfile
92+
with open(pyxfile, "r") as pyxfileopened:
93+
content = pyxfileopened.read()
94+
lineNumber = ExceptAllMissing(content)
95+
if lineNumber:
96+
print("WARNING: 'except *' missing in a cdef/cpdef function, "
97+
"in file %s on line %d" % (os.path.basename(pyxfile), lineNumber))
98+
sys.exit(1)
99+
# Do not remove the newline - so that line numbers are exact with originals.
100+
(content, subs) = re.subn(r"^include[\t ]+[\"'][^\"'\n\r]+[\"'][\t ]*", "", content, flags=re.MULTILINE)
101+
if subs:
102+
print("%s includes removed in: %s" % (subs, os.path.basename(pyxfile)))
103+
# Reading and writing with the same handle using "r+" mode doesn't work,
104+
# you need to seek(0) and write the same amount of bytes that was in the
105+
# file, otherwise old data from the end of file stays.
106+
with open(pyxfile, "w") as pyxfileopened:
107+
pyxfileopened.write(content)
108+
109+
print("\n")

0 commit comments

Comments
 (0)