forked from ludwigschwardt/python-gnureadline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·119 lines (108 loc) · 4.94 KB
/
setup.py
File metadata and controls
executable file
·119 lines (108 loc) · 4.94 KB
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
#!/usr/bin/env python
import os
import sys
from distutils.command.build_ext import build_ext
import subprocess
from setuptools import setup, Extension
if sys.platform == 'win32':
sys.exit('Error: this module is not meant to work on Windows (try pyreadline instead)')
here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
NEWS = open(os.path.join(here, 'NEWS.rst')).read()
VERSION = '6.3.3'
DESCRIPTION = 'The standard Python readline extension statically linked against the GNU readline library.'
LONG_DESCRIPTION = README + '\n\n' + NEWS
CLASSIFIERS = [
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
'Programming Language :: C',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
]
# Since we have the latest readline (post 4.2), enable all readline functionality
# These macros can be found in pyconfig.h.in in the main directory of the Python tarball
DEFINE_MACROS = [
('HAVE_RL_CALLBACK', None),
('HAVE_RL_CATCH_SIGNAL', None),
('HAVE_RL_COMPLETION_APPEND_CHARACTER', None),
('HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK', None),
('HAVE_RL_COMPLETION_MATCHES', None),
('HAVE_RL_COMPLETION_SUPPRESS_APPEND', None),
('HAVE_RL_PRE_INPUT_HOOK', None),
]
# Check if any of the distutils commands involves building the module,
# and check for quiet vs. verbose option
building = False
verbose = True
for s in sys.argv[1:]:
if s.startswith('bdist') or s.startswith('build') or s.startswith('install'):
building = True
if s in ['--quiet', '-q']:
verbose = False
if s in ['--verbose', '-v']:
verbose = True
# Build readline first, if it is not there and we are building the module
if building and not os.path.exists('readline/libreadline.a'):
if verbose:
print("\n============ Building the readline library ============\n")
os.system('cd rl && /bin/bash ./build.sh')
print("\n============ Building the readline extension module ============\n")
else:
os.system('cd rl && /bin/bash ./build.sh > /dev/null 2>&1')
# Add symlink that simplifies include and link paths to real library
if not (os.path.exists('readline') or os.path.islink('readline')):
os.symlink(os.path.join('rl','readline-lib'), 'readline')
# Workaround for OS X 10.9.2 and Xcode 5.1+
# The latest clang treats unrecognized command-line options as errors and the
# Python CFLAGS variable contains unrecognized ones (e.g. -mno-fused-madd).
# See Xcode 5.1 Release Notes (Compiler section) and
# http://stackoverflow.com/questions/22313407 for more details. This workaround
# follows the approach suggested in http://stackoverflow.com/questions/724664.
class build_ext_subclass(build_ext):
def build_extensions(self):
if sys.platform == 'darwin':
# Test the compiler that will actually be used to see if it likes flags
proc = subprocess.Popen(self.compiler.compiler + ['-v'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
clang_mesg = "clang: error: unknown argument: '-mno-fused-madd'"
if proc.returncode and stderr.splitlines()[0].startswith(clang_mesg):
for ext in self.extensions:
# Use temporary workaround to ignore invalid compiler option
# Hopefully -mno-fused-madd goes away before this workaround!
ext.extra_compile_args += ['-Wno-error=unused-command-line-argument-hard-error-in-future']
build_ext.build_extensions(self)
# First try version-specific readline.c, otherwise fall back to major-only version
source = os.path.join('Modules', '%d.%d' % sys.version_info[:2], 'readline.c')
if not os.path.exists(source):
source = os.path.join('Modules', '%d.x' % (sys.version_info[0],), 'readline.c')
setup(
name="gnureadline",
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
classifiers=CLASSIFIERS,
maintainer="Ludwig Schwardt; Sridhar Ratnakumar",
maintainer_email="[email protected]; [email protected]",
url="http://github.com/ludwigschwardt/python-gnureadline",
license="GNU GPL",
platforms=['MacOS X', 'Posix'],
include_package_data=True,
py_modules=['readline'],
cmdclass={'build_ext' : build_ext_subclass},
ext_modules=[
Extension(name="gnureadline",
sources=[source],
include_dirs=['.'],
define_macros=DEFINE_MACROS,
extra_objects=['readline/libreadline.a', 'readline/libhistory.a'],
libraries=['ncurses']
),
],
zip_safe=False,
)