summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-01-02 12:26:33 +0100
committerDave Andreoli <dave@gurumeditation.it>2015-01-02 12:26:33 +0100
commit1a3fa101e1d84528533af96023bb8f2d2500897a (patch)
treeef3e856e48df58979ebc0ea15f00bec818653a3a /setup.py
parent03f2f286e22ddf4fc94f14124d7c608610495044 (diff)
Changed the way we check and enable Cython usage
* Cython is disable by default in dist tarballs (checking if Makefile exists) * Cython is enabled by default in git version * Only blacklist Cython in py3 (it is broken only there) * Now respect two env vars: DISABLE_CYTHON or ENABLE_CYTHON * Always use LooseVersion for checking Cython version
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py119
1 files changed, 54 insertions, 65 deletions
diff --git a/setup.py b/setup.py
index be093fe..5de4e68 100755
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@ VERSION = "%d.%d" % (vers[0], vers[1] if vers[2] < 99 else vers[1] + 1)
18 18
19# dependencies 19# dependencies
20CYTHON_MIN_VERSION = "0.19" 20CYTHON_MIN_VERSION = "0.19"
21CYTHON_BLACKLIST = ("0.21.1", "0.21.2") 21CYTHON_BLACKLIST = ("0.21.1", "0.21.2") # only used if py3
22EFL_MIN_VER = RELEASE 22EFL_MIN_VER = RELEASE
23ELM_MIN_VER = RELEASE 23ELM_MIN_VER = RELEASE
24 24
@@ -100,59 +100,7 @@ def pkg_config(name, require, min_vers=None):
100 name, ver, min_vers)) 100 name, ver, min_vers))
101 101
102 102
103# === cython or pre-generated c files === 103# === setup.py clean_generated_files command ===
104if os.getenv("DISABLE_CYTHON"):
105 module_suffix = ".c"
106
107 def cythonize(modules, *args, **kwargs):
108 return modules
109else:
110 try:
111 from Cython.Build import cythonize
112 import Cython.Compiler.Options
113 except ImportError:
114 if not os.path.exists(os.path.join(script_path, "efl/eo/efl.eo.c")):
115 raise SystemExit("Requires Cython >= %s (http://cython.org/)" % (
116 CYTHON_MIN_VERSION))
117 module_suffix = ".c"
118
119 def cythonize(modules, *args, **kwargs):
120 return modules
121 else:
122 module_suffix = ".pyx"
123 try:
124 try:
125 assert StrictVersion(Cython.__version__) >= \
126 StrictVersion(CYTHON_MIN_VERSION)
127 except ValueError:
128 print("""
129Your Cython version string (%s) is weird. We'll attempt to
130check that it's higher than the minimum required: %s, but
131this is unreliable.\n
132If you run into any problems during or after installation it
133may be caused by version of Cython that's too old.""" % (
134 Cython.__version__, CYTHON_MIN_VERSION
135 )
136 )
137 assert LooseVersion(Cython.__version__) >= \
138 LooseVersion(CYTHON_MIN_VERSION)
139 except AssertionError:
140 raise SystemExit("Requires Cython >= %s (http://cython.org/)" % (
141 CYTHON_MIN_VERSION))
142
143 # Cython PyMethod_New() is broken! blacklisted
144 if Cython.__version__ in CYTHON_BLACKLIST:
145 raise SystemExit("Cython %s is broken! Use another release." %
146 Cython.__version__)
147
148 # Stop compilation on first error
149 Cython.Compiler.Options.fast_fail = True
150 # Generates HTML files with annotated source
151 Cython.Compiler.Options.annotate = False
152 # Set to False to disable docstrings
153 Cython.Compiler.Options.docstrings = True
154
155
156class CleanGenerated(Command): 104class CleanGenerated(Command):
157 description = "Clean C and html files generated by Cython" 105 description = "Clean C and html files generated by Cython"
158 user_options = [] 106 user_options = []
@@ -177,6 +125,18 @@ class CleanGenerated(Command):
177 os.remove(dbus_ml_path) 125 os.remove(dbus_ml_path)
178 126
179 127
128# === use cython or pre-generated C files ===
129USE_CYTHON = False
130if os.getenv("DISABLE_CYTHON") is not None:
131 USE_CYTHON = False
132elif os.getenv("ENABLE_CYTHON") is not None:
133 USE_CYTHON = True
134elif not os.path.exists(os.path.join(script_path, "efl/eo/efl.eo.c")):
135 USE_CYTHON = True
136elif os.path.exists(os.path.join(script_path, "Makefile")):
137 USE_CYTHON = True
138
139
180ext_modules = [] 140ext_modules = []
181py_modules = [] 141py_modules = []
182packages = ["efl"] 142packages = ["efl"]
@@ -194,10 +154,36 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
194 154
195 # === Cython === 155 # === Cython ===
196 sys.stdout.write("Checking for Cython: ") 156 sys.stdout.write("Checking for Cython: ")
197 if module_suffix == ".c": 157 if USE_CYTHON:
198 sys.stdout.write("no need, using pre-generated C files\n") 158 # check if cython is installed
199 else: 159 try:
160 from Cython.Build import cythonize
161 import Cython.Compiler.Options
162 except ImportError:
163 raise SystemExit("not found! Needed >= %s" % (CYTHON_MIN_VERSION))
164
165 # check min version
166 if LooseVersion(Cython.__version__) < LooseVersion(CYTHON_MIN_VERSION):
167 raise SystemExit("too old! Found %s Needed %s" % (
168 Cython.__version__, CYTHON_MIN_VERSION))
169
170 # Cython PyMethod_New() is broken for py3! blacklisted
171 if sys.version_info[0] > 2 and Cython.__version__ in CYTHON_BLACKLIST:
172 raise SystemExit("found %s, it's broken! Need another release" %
173 Cython.__version__)
174
200 sys.stdout.write("OK, found %s\n" % Cython.__version__) 175 sys.stdout.write("OK, found %s\n" % Cython.__version__)
176 module_suffix = ".pyx"
177 # Stop compilation on first error
178 Cython.Compiler.Options.fast_fail = True
179 # Generates HTML files with annotated source
180 Cython.Compiler.Options.annotate = False
181 # Set to False to disable docstrings
182 Cython.Compiler.Options.docstrings = True
183
184 else:
185 sys.stdout.write("not needed, using pre-generated C files\n")
186 module_suffix = ".c"
201 187
202 # === Eina === 188 # === Eina ===
203 eina_cflags, eina_libs = pkg_config('Eina', 'eina', EFL_MIN_VER) 189 eina_cflags, eina_libs = pkg_config('Eina', 'eina', EFL_MIN_VER)
@@ -411,6 +397,16 @@ if set(("build", "build_ext", "install", "bdist", "sdist")) & set(sys.argv):
411 397
412 packages.append("efl.elementary") 398 packages.append("efl.elementary")
413 399
400 # Cythonize all the external modules (if needed)
401 if USE_CYTHON:
402 ext_modules = cythonize(ext_modules,
403 include_path=["include"],
404 compiler_directives={
405 #"c_string_type": "unicode",
406 #"c_string_encoding": "utf-8",
407 "embedsignature": True,
408 })
409
414 410
415setup( 411setup(
416 name="python-efl", 412 name="python-efl",
@@ -452,13 +448,6 @@ setup(
452 }, 448 },
453 packages=packages, 449 packages=packages,
454 ext_package="efl", 450 ext_package="efl",
455 ext_modules=cythonize(ext_modules, 451 ext_modules=ext_modules,
456 include_path=["include"],
457 compiler_directives={
458 #"c_string_type": "unicode",
459 #"c_string_encoding": "utf-8",
460 "embedsignature": True,
461 }
462 ),
463 py_modules=py_modules, 452 py_modules=py_modules,
464) 453)