-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
152 lines (142 loc) · 5.88 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from setuptools.extension import Extension
from setuptools import setup, find_packages
import os
from os.path import splitext
import logging
import platform
from glob import glob
VERSION = "0.1.0"
ext_macros = []
logger = logging.getLogger('scurl')
try:
from Cython.Compiler import Options as CythonOptions
except ImportError as e:
logger.debug('Cython is not installed on your env.\
Please get the latest version of Cython and try again!')
if os.environ.get('CYTHON_TRACE'):
if platform.python_implementation() != 'PyPy':
# enable linetrace in Cython
ext_macros.append(('CYTHON_TRACE', '1'))
cython_defaults = CythonOptions.get_directive_defaults()
cython_defaults['linetrace'] = True
logger.warning('Warning: Enabling line tracing in Cython extension.\
This will make the performance of the library less effective!')
cgurl_ext_sources = [
'scurl/cgurl.pyx',
'third_party/chromium/base/callback_internal.cc',
'third_party/chromium/base/at_exit.cc',
'third_party/chromium/base/lazy_instance_helpers.cc',
'third_party/chromium/base/strings/utf_string_conversion_utils.cc',
'third_party/chromium/base/strings/string_piece.cc',
'third_party/chromium/base/strings/string16.cc',
'third_party/chromium/base/strings/string_util.cc',
'third_party/chromium/base/strings/utf_string_conversions.cc',
'third_party/chromium/base/strings/string_util_constants.cc',
'third_party/chromium/base/third_party/icu/icu_utf.cc',
'third_party/chromium/url/gurl.cc',
'third_party/chromium/url/url_canon.cc',
'third_party/chromium/url/url_canon_etc.cc',
# 'third_party/chromium/url/url_canon_icu.cc',
'third_party/chromium/url/url_canon_filesystemurl.cc',
'third_party/chromium/url/url_canon_fileurl.cc',
'third_party/chromium/url/url_canon_host.cc',
'third_party/chromium/url/url_canon_internal.cc',
'third_party/chromium/url/url_canon_ip.cc',
'third_party/chromium/url/url_canon_mailtourl.cc',
'third_party/chromium/url/url_canon_path.cc',
'third_party/chromium/url/url_canon_pathurl.cc',
'third_party/chromium/url/url_canon_query.cc',
'third_party/chromium/url/url_canon_relative.cc',
'third_party/chromium/url/url_canon_stdstring.cc',
'third_party/chromium/url/url_canon_stdurl.cc',
'third_party/chromium/url/url_constants.cc',
'third_party/chromium/url/url_parse_file.cc',
'third_party/chromium/url/url_util.cc',
'third_party/chromium/url/third_party/mozilla/url_parse.cc',
]
canonicalize_ext_sources = [
'scurl/canonicalize.pyx',
'third_party/chromium/base/callback_internal.cc',
'third_party/chromium/base/at_exit.cc',
'third_party/chromium/base/lazy_instance_helpers.cc',
'third_party/chromium/base/strings/utf_string_conversion_utils.cc',
'third_party/chromium/base/strings/string_piece.cc',
'third_party/chromium/base/strings/string16.cc',
'third_party/chromium/base/strings/string_util.cc',
'third_party/chromium/base/strings/utf_string_conversions.cc',
'third_party/chromium/base/strings/string_util_constants.cc',
'third_party/chromium/base/third_party/icu/icu_utf.cc',
'third_party/chromium/url/url_canon.cc',
'third_party/chromium/url/url_canon_path.cc',
'third_party/chromium/url/url_canon_internal.cc',
'third_party/chromium/url/url_canon_stdstring.cc',
]
extension = [
Extension(
name="scurl.cgurl",
sources=cgurl_ext_sources,
language="c++",
extra_compile_args=["-std=gnu++14", "-I./third_party/chromium/",
"-fPIC", "-Ofast", "-pthread", "-w", '-DU_COMMON_IMPLEMENTATION'],
extra_link_args=["-std=gnu++14", "-w"],
include_dirs=['.'],
define_macros=ext_macros
),
Extension(
name="scurl.canonicalize",
sources=canonicalize_ext_sources,
language="c++",
extra_compile_args=["-std=gnu++14", "-I./third_party/chromium/",
"-fPIC", "-Ofast", "-pthread", "-w"],
extra_link_args=["-std=gnu++14", "-w"],
include_dirs=['.'],
define_macros=ext_macros
)
]
if not os.path.isfile("scurl/cgurl.cpp"):
try:
from Cython.Build import cythonize
ext_modules = cythonize(extension, annotate=True)
except ImportError:
print("scurl/cgurl.cpp not found and Cython failed to run to recreate it. Please install/upgrade Cython and try again.")
raise
else:
ext_modules = extension
ext_modules[0].sources[0] = "scurl/cgurl.cpp"
ext_modules[1].sources[0] = "scurl/canonicalize.cpp"
try:
import pypandoc
long_description = pypandoc.convert('README.md', 'rst')
except ImportError:
long_description = open('README.md').read()
setup(
name="scurl",
packages=find_packages(exclude=('tests', 'tests.*')),
version=VERSION,
description="",
license="Apache License, Version 2.0",
url="https://github.com/scrapy/scurl",
keywords=["urlparse", "urlsplit", "urljoin", "url", "parser", "urlparser", "parsing", "gurl", "cython", "faster", "speed", "performance"],
platforms='any',
classifiers=[
"Programming Language :: Python",
'Programming Language :: Python :: 2',
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries"
],
install_requires=[
'six>=1.5.2',
],
long_description=long_description,
ext_modules=ext_modules,
include_package_data=True,
zip_safe=False
)