Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 160 lines (141 sloc) 5.196 kb
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
1 import sys, os
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
2 from distutils.core import Extension
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
3
4 try:
bfd7af30 » scoder
2007-07-29 [svn r2714] prefer Cython over patched Pyrex in imports
5 from Cython.Distutils import build_ext as build_pyx
18e90c09 » scoder
2007-10-20 [svn r2968] print Cython version in setup.py
6 import Cython.Compiler.Version
7 print("Building with Cython %s." % Cython.Compiler.Version.version)
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
8 CYTHON_INSTALLED = True
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
9 except ImportError:
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
10 CYTHON_INSTALLED = False
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
11
77d47bda » scoder
2007-10-22 [svn r2983] cleanup
12 EXT_MODULES = ["lxml.etree", "lxml.objectify","lxml.pyclasslookup"]
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
13
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
14 def env_var(name):
732e3e79 » scoder
2007-02-14 [svn r2100] env_map removed (by Sidnei)
15 value = os.getenv(name, '')
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
16 return value.split(os.pathsep)
17
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
18 def ext_modules(static_include_dirs, static_library_dirs, static_cflags):
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
19 if CYTHON_INSTALLED:
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
20 source_extension = ".pyx"
21 else:
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
22 print ("NOTE: Trying to build without Cython, pre-generated "
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
23 "'src/lxml/etree.c' needs to be available.")
24 source_extension = ".c"
c0a5688e » scoder
2007-02-24 [svn r2150] support building without objectify
25
26 if OPTION_WITHOUT_OBJECTIFY:
27 modules = [ entry for entry in EXT_MODULES if entry[0] != 'objectify' ]
28 else:
29 modules = EXT_MODULES
30
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
31 _include_dirs = include_dirs(static_include_dirs)
32 _library_dirs = library_dirs(static_library_dirs)
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
33 _cflags = cflags(static_cflags)
34 _define_macros = define_macros()
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
35 _libraries = libraries()
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
36
37 if OPTION_AUTO_RPATH:
38 runtime_library_dirs = _library_dirs
39 else:
40 runtime_library_dirs = []
41
42 result = []
77d47bda » scoder
2007-10-22 [svn r2983] cleanup
43 for module in modules:
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
44 result.append(
45 Extension(
77d47bda » scoder
2007-10-22 [svn r2983] cleanup
46 module,
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
47 sources = ["src/lxml/" + module + source_extension],
48 extra_compile_args = ['-w'] + _cflags,
49 define_macros = _define_macros,
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
50 include_dirs = _include_dirs,
51 library_dirs = _library_dirs,
52 runtime_library_dirs = runtime_library_dirs,
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
53 libraries = _libraries,
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
54 ))
55 return result
56
57 def extra_setup_args():
58 result = {}
9e68316b » scoder
2007-08-31 [svn r2800] switch to Cython completely, currently requires fake Pyre…
59 if CYTHON_INSTALLED:
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
60 result['cmdclass'] = {'build_ext': build_pyx}
61 return result
62
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
63 def libraries():
64 if sys.platform in ('win32',):
65 libs = ['libxslt', 'libexslt', 'libxml2', 'iconv']
66 else:
67 libs = ['xslt', 'exslt', 'xml2', 'z', 'm']
68 if OPTION_STATIC:
69 if sys.platform in ('win32',):
70 libs = ['%s_a' % lib for lib in libs]
71 if sys.platform in ('win32',):
72 libs.extend(['zlib', 'WS2_32'])
73 return libs
74
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
75 def library_dirs(static_library_dirs):
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
76 if OPTION_STATIC:
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
77 if not static_library_dirs:
78 static_library_dirs = env_var('LIBRARY')
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
79 assert static_library_dirs, "Static build not configured, see doc/build.txt"
80 return static_library_dirs
81 # filter them from xslt-config --libs
82 result = []
83 possible_library_dirs = flags('xslt-config --libs')
84 for possible_library_dir in possible_library_dirs:
85 if possible_library_dir.startswith('-L'):
86 result.append(possible_library_dir[2:])
87 return result
88
89 def include_dirs(static_include_dirs):
90 if OPTION_STATIC:
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
91 if not static_include_dirs:
92 static_include_dirs = env_var('INCLUDE')
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
93 assert static_include_dirs, "Static build not configured, see doc/build.txt"
94 return static_include_dirs
95 # filter them from xslt-config --cflags
96 result = []
97 possible_include_dirs = flags('xslt-config --cflags')
98 for possible_include_dir in possible_include_dirs:
99 if possible_include_dir.startswith('-I'):
100 result.append(possible_include_dir[2:])
101 return result
102
103 def cflags(static_cflags):
104 result = []
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
105 if OPTION_DEBUG_GCC:
106 result.append('-g2')
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
107
108 if OPTION_STATIC:
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
109 if not static_cflags:
110 static_cflags = env_var('CFLAGS')
fe1dbec1 » faassen
2006-11-22 [svn r2067] Refactor further:
111 assert static_cflags, "Static build not configured, see doc/build.txt"
112 result.extend(static_cflags)
113 return result
114
115 # anything from xslt-config --cflags that doesn't start with -I
116 possible_cflags = flags('xslt-config --cflags')
117 for possible_cflag in possible_cflags:
118 if not possible_cflag.startswith('-I'):
119 result.append(possible_cflag)
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
120 return result
121
122 def define_macros():
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
123 macros = []
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
124 if OPTION_WITHOUT_ASSERT:
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
125 macros.append(('PYREX_WITHOUT_ASSERTIONS', None))
59a770fd » scoder
2006-11-28 [svn r2077] support building without threading by passing --without-t…
126 if OPTION_WITHOUT_THREADING:
127 macros.append(('WITHOUT_THREADING', None))
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
128 return macros
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
129
130 def flags(cmd):
20ed400b » scoder
2007-10-10 [svn r2959] Py3 syntax fixes in build scripts
131 try:
132 import subprocess
133 except ImportError:
134 # Python 2.3
135 _, rf, ef = os.popen3(cmd)
136 else:
137 # Python 2.4+
a4dff800 » scoder
2008-01-19 [svn r3177] r3268@delle: sbehnel | 2008-01-19 14:21:46 +0100
138 p = subprocess.Popen(cmd, shell=True,
20ed400b » scoder
2007-10-10 [svn r2959] Py3 syntax fixes in build scripts
139 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
140 rf, ef = p.stdout, p.stderr
d1e09b49 » scoder
2007-09-24 [svn r2912] build setup clarification and error message for missing x…
141 errors = ef.read()
142 if errors:
20ed400b » scoder
2007-10-10 [svn r2959] Py3 syntax fixes in build scripts
143 print("ERROR: %s" % errors)
144 print("** make sure the development packages of libxml2 and libxslt are installed **\n")
145 return str(rf.read()).split()
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
146
147 def has_option(name):
148 try:
149 sys.argv.remove('--%s' % name)
150 return True
151 except ValueError:
152 return False
153
154 # pick up any commandline options
c0a5688e » scoder
2007-02-24 [svn r2150] support building without objectify
155 OPTION_WITHOUT_OBJECTIFY = has_option('without-objectify')
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
156 OPTION_WITHOUT_ASSERT = has_option('without-assert')
00a48913 » scoder
2006-11-28 [svn r2076] patch by Sidney da Silva: support passing compiler flags …
157 OPTION_WITHOUT_THREADING = has_option('without-threading')
a5f0f7f0 » faassen
2006-11-22 [svn r2061] Refactored setup.py into multiple files to be more readab…
158 OPTION_STATIC = has_option('static')
159 OPTION_DEBUG_GCC = has_option('debug-gcc')
ef619505 » faassen
2006-11-22 [svn r2063] Rename --rpath to --auto-rpath and add some notes to CHAN…
160 OPTION_AUTO_RPATH = has_option('auto-rpath')
Something went wrong with that request. Please try again.