Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

only use Cython for building when required or explicitly requested

  • Loading branch information...
commit 792c629e2d9490db8993b7665114ddca8a1fb8aa 1 parent 8d9daa7
@scoder scoder authored
Showing with 31 additions and 19 deletions.
  1. +7 −4 Makefile
  2. +6 −1 doc/build.txt
  3. +18 −14 setupinfo.py
View
11 Makefile
@@ -1,18 +1,21 @@
PYTHON?=python
-PYTHON3?=python3.0
+PYTHON3?=python3
TESTFLAGS=-p -v
TESTOPTS=
SETUPFLAGS=
LXMLVERSION=`cat version.txt`
+PY2_WITH_CYTHON=$(shell $(PYTHON) -c 'import Cython.Compiler' >/dev/null 2>/dev/null && echo " --with-cython" || true)
+PY3_WITH_CYTHON=$(shell $(PYTHON3) -c 'import Cython.Compiler' >/dev/null 2>/dev/null && echo " --with-cython" || true)
+
all: inplace
# Build in-place
inplace:
- $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i
+ $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i $(PY2_WITH_CYTHON)
build:
- $(PYTHON) setup.py $(SETUPFLAGS) build
+ $(PYTHON) setup.py $(SETUPFLAGS) build $(PY2_WITH_CYTHON)
test_build: build
$(PYTHON) test.py $(TESTFLAGS) $(TESTOPTS)
@@ -24,7 +27,7 @@ test_inplace: inplace
test_inplace3: inplace
$(MAKE) clean
- $(PYTHON3) setup.py $(SETUPFLAGS) build_ext -i
+ $(PYTHON3) setup.py $(SETUPFLAGS) build_ext -i $(PY3_WITH_CYTHON)
$(PYTHON3) test.py $(TESTFLAGS) $(TESTOPTS)
PYTHONPATH=src:$(PYTHONPATH) $(PYTHON3) selftest.py
PYTHONPATH=src:$(PYTHONPATH) $(PYTHON3) selftest2.py
View
7 doc/build.txt
@@ -81,10 +81,15 @@ or::
python setup.py bdist_egg # requires 'setuptools' or 'distribute'
+To (re-)build the C sources with Cython, you must additionally pass the
+option ``--with-cython``::
+
+ python setup.py build --with-cython
+
If you want to test lxml from the source directory, it is better to build it
in-place like this::
- python setup.py build_ext -i
+ python setup.py build_ext -i --with-cython
or, in Unix-like environments::
View
32 setupinfo.py
@@ -12,7 +12,7 @@
EXT_MODULES = ["lxml.etree", "lxml.objectify"]
-PACKAGE_PATH = "src/lxml/"
+PACKAGE_PATH = "src%slxml%s" % (os.path.sep, os.path.sep)
INCLUDE_PACKAGE_PATH = PACKAGE_PATH + 'includes'
if sys.version_info[0] >= 3:
@@ -56,26 +56,29 @@ def ext_modules(static_include_dirs, static_library_dirs,
libxslt_version=OPTION_LIBXSLT_VERSION,
multicore=OPTION_MULTICORE)
- if CYTHON_INSTALLED:
+ if OPTION_WITHOUT_OBJECTIFY:
+ modules = [ entry for entry in EXT_MODULES
+ if 'objectify' not in entry ]
+ else:
+ modules = EXT_MODULES
+
+ c_files_exist = [ os.path.exists('%s%s.c' % (PACKAGE_PATH, module)) for module in modules ]
+
+ if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or False in c_files_exist):
source_extension = ".pyx"
print("Building with Cython %s." % Cython.Compiler.Version.version)
-
# generate module cleanup code
from Cython.Compiler import Options
Options.generate_cleanup_code = 3
+ elif False in c_files_exist:
+ for exists, module in zip(c_files_exist, modules):
+ if not exists:
+ raise RuntimeError(
+ "ERROR: Trying to build without Cython, but pre-generated "
+ "'%s%s.c' is not available." % (PACKAGE_PATH, module))
else:
source_extension = ".c"
- if not os.path.exists(PACKAGE_PATH + 'lxml.etree.c'):
- print ("WARNING: Trying to build without Cython, but pre-generated "
- "'%slxml.etree.c' does not seem to be available." % PACKAGE_PATH)
- else:
- print ("Building without Cython.")
-
- if OPTION_WITHOUT_OBJECTIFY:
- modules = [ entry for entry in EXT_MODULES
- if 'objectify' not in entry ]
- else:
- modules = EXT_MODULES
+ print("Building without Cython.")
lib_versions = get_library_versions()
if lib_versions[0]:
@@ -347,6 +350,7 @@ def option_value(name):
OPTION_WITHOUT_ASSERT = has_option('without-assert')
OPTION_WITHOUT_THREADING = has_option('without-threading')
OPTION_WITHOUT_CYTHON = has_option('without-cython')
+OPTION_WITH_CYTHON = has_option('with-cython')
OPTION_WITH_CYTHON_GDB = has_option('cython-gdb')
OPTION_WITH_REFNANNY = has_option('with-refnanny')
if OPTION_WITHOUT_CYTHON:
Please sign in to comment.
Something went wrong with that request. Please try again.