Debian Codegraph @

setup.py

raw
1 import os
2 import re
3 import sys
4 import fnmatch
5 import os.path
6
7 # for command line options and supported environment variables, please
8 # see the end of 'setupinfo.py'
9
10 if sys.version_info[:2] < (3, 8):
11 print("This lxml version requires Python 3.8 or later.")
12 sys.exit(1)
13
14 from setuptools import setup
15
16 # make sure Cython finds include files in the project directory and not outside
17 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
18
19 import versioninfo
20 import setupinfo
21
22 # override these and pass --static for a static build. See
23 # doc/build.txt for more information. If you do not pass --static
24 # changing this will have no effect.
25 def static_env_list(name, separator=None):
26 return [x.strip() for x in os.environ.get(name, "").split(separator) if x.strip()]
27
28 STATIC_INCLUDE_DIRS = static_env_list("LXML_STATIC_INCLUDE_DIRS", separator=os.pathsep)
29 STATIC_LIBRARY_DIRS = static_env_list("LXML_STATIC_LIBRARY_DIRS", separator=os.pathsep)
30 STATIC_CFLAGS = static_env_list("LXML_STATIC_CFLAGS")
31 STATIC_BINARIES = static_env_list("LXML_STATIC_BINARIES", separator=os.pathsep)
32
33 # create lxml-version.h file
34 versioninfo.create_version_h()
35 lxml_version = versioninfo.version()
36 print("Building lxml version %s." % lxml_version)
37
38 OPTION_RUN_TESTS = setupinfo.has_option('run-tests')
39
40 branch_link = """
41 After an official release of a new stable series, bug fixes may become available at
42 https://github.com/lxml/lxml/tree/lxml-{branch_version} .
43 Running ``pip install https://github.com/lxml/lxml/archive/refs/heads/lxml-{branch_version}.tar.gz``
44 will install the unreleased branch state as soon as a maintenance branch has been established.
45 Note that this requires Cython to be installed at an appropriate version for the build.
46
47 """
48
49 if versioninfo.is_pre_release():
50 branch_link = ""
51
52 with open("requirements.txt", "r") as f:
53 deps = [line.strip() for line in f if ':' in line]
54
55 extra_options = {
56 'python_requires': '>=3.8', # NOTE: keep in sync with Trove classifier list below.
57
58 'extras_require': {
59 'source': deps,
60 'cssselect': 'cssselect>=0.7',
61 'html5': 'html5lib',
62 'htmlsoup': 'BeautifulSoup4',
63 'html_clean': 'lxml_html_clean',
64 },
65
66 'zip_safe': False,
67
68 'package_data': {
69 'lxml': [
70 'etree.h',
71 'etree_api.h',
72 'lxml.etree.h',
73 'lxml.etree_api.h',
74 # Include Cython source files for better traceback output.
75 '*.pyx',
76 '*.pxi',
77 ],
78 'lxml.includes': [
79 '*.pxd',
80 '*.h',
81 ],
82 'lxml.isoschematron': [
83 'resources/rng/iso-schematron.rng',
84 'resources/xsl/*.xsl',
85 'resources/xsl/iso-schematron-xslt1/*.xsl',
86 'resources/xsl/iso-schematron-xslt1/readme.txt',
87 ],
88 },
89
90 'package_dir': {
91 '': 'src'
92 },
93
94 'packages': [
95 'lxml', 'lxml.includes', 'lxml.html', 'lxml.isoschematron'
96 ],
97
98 **setupinfo.extra_setup_args(),
99 }
100
101
102 def setup_extra_options():
103 is_interesting_package = re.compile('^(libxml|libxslt|libexslt)$').match
104 is_interesting_header = re.compile(r'^(zconf|zlib|.*charset)\.h$').match
105
106 def extract_files(directories, pattern='*'):
107 def get_files(root, dir_path, files):
108 return [ (root, dir_path, filename)
109 for filename in fnmatch.filter(files, pattern) ]
110
111 file_list = []
112 for dir_path in directories:
113 dir_path = os.path.realpath(dir_path)
114 for root, dirs, files in os.walk(dir_path):
115 rel_dir = root[len(dir_path)+1:]
116 if is_interesting_package(rel_dir):
117 file_list.extend(get_files(root, rel_dir, files))
118 elif not rel_dir:
119 # include also top-level header files (zlib/iconv)
120 file_list.extend(
121 item for item in get_files(root, rel_dir, files)
122 if is_interesting_header(item[-1])
123 )
124 return file_list
125
126 def build_packages(files):
127 packages = {}
128 seen = set()
129 for root_path, rel_path, filename in files:
130 if filename in seen:
131 # libxml2/libxslt header filenames are unique
132 continue
133 seen.add(filename)
134 package_path = '.'.join(rel_path.split(os.sep))
135 if package_path in packages:
136 root, package_files = packages[package_path]
137 if root != root_path:
138 print("WARNING: conflicting directories found for include package '%s': %s and %s"
139 % (package_path, root_path, root))
140 continue
141 else:
142 package_files = []
143 packages[package_path] = (root_path, package_files)
144 package_files.append(filename)
145
146 return packages
147
148 # Copy Global Extra Options
149 extra_opts = dict(extra_options)
150
151 # Build ext modules
152 ext_modules = setupinfo.ext_modules(
153 STATIC_INCLUDE_DIRS, STATIC_LIBRARY_DIRS,
154 STATIC_CFLAGS, STATIC_BINARIES)
155 extra_opts['ext_modules'] = ext_modules
156
157 packages = extra_opts.get('packages', list())
158 package_dir = extra_opts.get('package_dir', dict())
159 package_data = extra_opts.get('package_data', dict())
160
161 # Add lxml.include with (lxml, libxslt headers...)
162 # python setup.py build --static --static-deps install
163 # python setup.py bdist_wininst --static
164 if setupinfo.OPTION_STATIC:
165 include_dirs = [] # keep them in order
166 for extension in ext_modules:
167 for inc_dir in extension.include_dirs:
168 if inc_dir not in include_dirs:
169 include_dirs.append(inc_dir)
170
171 header_packages = build_packages(extract_files(include_dirs))
172
173 package_filename = "__init__.py"
174 for package_path, (root_path, filenames) in header_packages.items():
175 if not package_path:
176 # lxml.includes -> lxml.includes.extlibs
177 package_path = "extlibs"
178 package = 'lxml.includes.' + package_path
179 packages.append(package)
180
181 # create '__init__.py' to make sure it's considered a package
182 if package_filename not in filenames:
183 with open(os.path.join(root_path, package_filename), 'wb') as f:
184 pass
185 filenames.append(package_filename)
186
187 assert package not in package_data
188 package_data[package] = filenames
189 assert package not in package_dir
190 package_dir[package] = root_path
191
192 return extra_opts
193
194 setup(
195 name = "lxml",
196 version = lxml_version,
197 author="lxml dev team",
198 author_email="[email protected]",
199 maintainer="lxml dev team",
200 maintainer_email="[email protected]",
201 license="BSD-3-Clause",
202 url="https://lxml.de/",
203 project_urls={
204 "Source": "https://github.com/lxml/lxml",
205 "Bug Tracker": "https://bugs.launchpad.net/lxml",
206 },
207 description=(
208 "Powerful and Pythonic XML processing library"
209 " combining libxml2/libxslt with the ElementTree API."
210 ),
211 long_description=(("""\
212 lxml is a Pythonic, mature binding for the libxml2 and libxslt libraries.
213 It provides safe and convenient access to these libraries using the
214 ElementTree API.
215
216 It extends the ElementTree API significantly to offer support for XPath,
217 RelaxNG, XML Schema, XSLT, C14N and much more.
218
219 To contact the project, go to the `project home page <https://lxml.de/>`_
220 or see our bug tracker at https://launchpad.net/lxml
221
222 In case you want to use the current in-development version of lxml,
223 you can get it from the github repository at
224 https://github.com/lxml/lxml . Note that this requires Cython to
225 build the sources, see the build instructions on the project home page.
226
227 """ + branch_link).format(branch_version=versioninfo.branch_version())
228 + versioninfo.changes()),
229 classifiers=[
230 versioninfo.dev_status(),
231 'Intended Audience :: Developers',
232 'Intended Audience :: Information Technology',
233 'Programming Language :: Cython',
234 # NOTE: keep in sync with 'python_requires' list above.
235 'Programming Language :: Python :: 3',
236 'Programming Language :: Python :: 3.8',
237 'Programming Language :: Python :: 3.9',
238 'Programming Language :: Python :: 3.10',
239 'Programming Language :: Python :: 3.11',
240 'Programming Language :: Python :: 3.12',
241 'Programming Language :: Python :: 3.13',
242 'Programming Language :: Python :: 3.14',
243 'Programming Language :: Python :: 3.15',
244 'Programming Language :: C',
245 'Operating System :: OS Independent',
246 'Topic :: Text Processing :: Markup :: HTML',
247 'Topic :: Text Processing :: Markup :: XML',
248 'Topic :: Software Development :: Libraries :: Python Modules'
249 ],
250
251 **setup_extra_options()
252 )
253
254 if OPTION_RUN_TESTS:
255 print("Running tests.")
256 import test
257 try:
258 sys.exit( test.main(sys.argv[:1]) )
259 except ImportError:
260 pass # we assume that the binaries were not built with this setup.py run