Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 161 lines (140 sloc) 5.373 kb
fce754a Chris Benoit initial release of http-parser.
b3no authored
1 # -*- coding: utf-8 -
2 #
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
3 # This file is part of http-parser released under the MIT license.
fce754a Chris Benoit initial release of http-parser.
b3no authored
4 # See the NOTICE for more information.
5
6 from __future__ import with_statement
d73f505 Benoit Chesneau fix setup.py and rebuild the extension.
authored
7 from distutils.errors import CCompilerError, DistutilsExecError, \
8 DistutilsPlatformError
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
9 from distutils.command.build_ext import build_ext
10 from distutils.command.sdist import sdist as _sdist
fce754a Chris Benoit initial release of http-parser.
b3no authored
11 import glob
12 from imp import load_source
627e6f2 Mike Gilbert Set encoding explicitly when reading files in setup.py
floppym authored
13 import io
fce754a Chris Benoit initial release of http-parser.
b3no authored
14 import os
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
15 import shutil
fce754a Chris Benoit initial release of http-parser.
b3no authored
16 import sys
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
17 import traceback
fce754a Chris Benoit initial release of http-parser.
b3no authored
18
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
19 from setuptools import setup, find_packages, Extension, Feature
20
07f3ca4 Chris Benoit we don't support version of python < 2.6 let the user know.
b3no authored
21 if not hasattr(sys, 'version_info') or \
966793d Benoit Chesneau remove support of py25 .
authored
22 sys.version_info < (2, 6, 0, 'final'):
07f3ca4 Chris Benoit we don't support version of python < 2.6 let the user know.
b3no authored
23 raise SystemExit("http-parser requires Python 2.6x or later")
fce754a Chris Benoit initial release of http-parser.
b3no authored
24
d73f505 Benoit Chesneau fix setup.py and rebuild the extension.
authored
25 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
26 if sys.platform == 'win32' and sys.version_info > (2, 6):
27 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
28 # find the compiler
29 ext_errors += (IOError,)
30
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
31 http_parser = load_source("http_parser", os.path.join("http_parser",
32 "__init__.py"))
d7325d2 Benoit Chesneau compatibility with pypy.
authored
33
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
34 IS_PYPY = hasattr(sys, 'pypy_version_info')
fce754a Chris Benoit initial release of http-parser.
b3no authored
35 CLASSIFIERS = [
36 'Development Status :: 4 - Beta',
37 'Environment :: Other Environment',
38 'Intended Audience :: Developers',
39 'License :: OSI Approved :: MIT License',
40 'Operating System :: MacOS :: MacOS X',
41 'Operating System :: POSIX',
42 'Programming Language :: Python',
3f5ff59 Benoit Chesneau fix categories
authored
43 'Programming Language :: Python :: 2.6',
44 'Programming Language :: Python :: 2.7',
45 'Programming Language :: Python :: 3',
fce754a Chris Benoit initial release of http-parser.
b3no authored
46 'Topic :: Internet',
47 'Topic :: Utilities',
48 'Topic :: Software Development :: Libraries :: Python Modules',
49 ]
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
50 VERSION = http_parser.__version__
51
52 # get long description
627e6f2 Mike Gilbert Set encoding explicitly when reading files in setup.py
floppym authored
53 with io.open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf8') as f:
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
54 LONG_DESCRIPTION = f.read()
55
56 def _system(cmd):
57 cmd = ' '.join(cmd)
58 sys.stderr.write('Running %r in %s\n' % (cmd, os.getcwd()))
59 return os.system(cmd)
60
61 def make(done=[]):
62 if not done:
63 if os.path.exists('Makefile'):
64 if "PYTHON" not in os.environ:
65 os.environ["PYTHON"] = sys.executable
66 if os.system('make'):
67 sys.exit(1)
68 done.append(1)
69
70 class sdist(_sdist):
71
72 def run(self):
73 renamed = False
74 if os.path.exists('Makefile'):
75 make()
76 os.rename('Makefile', 'Makefile.ext')
77 renamed = True
78 try:
79 return _sdist.run(self)
80 finally:
81 if renamed:
82 os.rename('Makefile.ext', 'Makefile')
fce754a Chris Benoit initial release of http-parser.
b3no authored
83
d73f505 Benoit Chesneau fix setup.py and rebuild the extension.
authored
84 class BuildFailed(Exception):
85 pass
86
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
87 class my_build_ext(build_ext):
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
88
89 def build_extension(self, ext):
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
90 make()
91 try:
92 result = build_ext.build_extension(self, ext)
93 except ext_errors:
94 if getattr(ext, 'optional', False):
95 raise BuildFailed
96 else:
97 raise
98 # hack: create a symlink from build/../core.so to
99 # http_parser/parser.so
100 # to prevent "ImportError: cannot import name core" failures
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
101 try:
102 fullname = self.get_ext_fullname(ext.name)
103 modpath = fullname.split('.')
104 filename = self.get_ext_filename(ext.name)
105 filename = os.path.split(filename)[-1]
106 if not self.inplace:
107 filename = os.path.join(*modpath[:-1] + [filename])
d73f505 Benoit Chesneau fix setup.py and rebuild the extension.
authored
108 path_to_build_core_so = os.path.abspath(os.path.join(self.build_lib,
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
109 filename))
d73f505 Benoit Chesneau fix setup.py and rebuild the extension.
authored
110 path_to_core_so = os.path.abspath(os.path.join('http_parser',
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
111 os.path.basename(path_to_build_core_so)))
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
112 if path_to_build_core_so != path_to_core_so:
113 try:
114 os.unlink(path_to_core_so)
115 except OSError:
116 pass
117 if hasattr(os, 'symlink'):
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
118 sys.stderr.write('Linking %s to %s\n' % (
119 path_to_build_core_so, path_to_core_so))
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
120 os.symlink(path_to_build_core_so, path_to_core_so)
121 else:
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
122 sys.stderr.write('Copying %s to %s\n' % (
123 path_to_build_core_so, path_to_core_so))
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
124 shutil.copyfile(path_to_build_core_so, path_to_core_so)
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
125 except Exception:
c3bba77 Chris Benoit make sure we can install http-parser witout cpython if parser.c exists.
b3no authored
126 traceback.print_exc()
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
127 return result
128
129
130 def run_setup(with_binary):
131 extra = {}
132 if with_binary:
133 extra.update(dict(
134 ext_modules = [
135 Extension('http_parser.parser', [
50e2bf1 Benoit Chesneau fix setup
authored
136 os.path.join('http_parser', 'http_parser.c'),
137 os.path.join('http_parser', 'parser.c')
138 ], ['parser'])],
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
139 cmdclass=dict(build_ext=my_build_ext, sdist=sdist)
140 ))
141
142
143 setup(
144 name = 'http-parser',
145 version = VERSION,
146 description = 'http request/response parser',
147 long_description = LONG_DESCRIPTION,
148 author = 'Benoit Chesneau',
149 author_email = 'benoitc@e-engura.com',
150 license = 'MIT',
151 url = 'http://github.com/benoitc/http-parser',
152 classifiers = CLASSIFIERS,
153 platforms=['any'],
154 packages = find_packages(),
155 ** extra
fce754a Chris Benoit initial release of http-parser.
b3no authored
156 )
157
d7325d2 Benoit Chesneau compatibility with pypy.
authored
158
fce754a Chris Benoit initial release of http-parser.
b3no authored
159 if __name__ == "__main__":
23c74fe Benoit Chesneau use setuptools to install http_parser.
authored
160 run_setup(not IS_PYPY)
Something went wrong with that request. Please try again.