Simplify setup.py, support more distros
This should force Python 2 on Gentoo (though it worked with default config), and work again with Arch. The find_executable() function should work on POSIX and Windows platforms. It is also easily possible to override executables. Generally the code is shorter and PEP8 compliant.
This commit is contained in:
parent
be801532d3
commit
e69adf357b
1 changed files with 35 additions and 79 deletions
114
setup.py
114
setup.py
|
|
@ -29,97 +29,53 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def check_executable_win(executable, error):
|
def find_executable(name, names):
|
||||||
pathsrc = "PATH" # Where to get the path
|
envname = '%s_EXECUTABLE' % name.upper()
|
||||||
pathextsrc = "PATHEXT" # Where to get the extension list
|
if os.getenv(envname):
|
||||||
dotfirst = 1 # Should we look in the current directory also?
|
return os.getenv(envname)
|
||||||
|
paths = os.getenv('PATH', os.defpath).split(os.pathsep)
|
||||||
path = os.environ[pathsrc]
|
exts = os.getenv('PATHEXT', os.pathsep).split(os.pathsep)
|
||||||
path = filter(None, path.split(";"))
|
for name in names:
|
||||||
|
for path in paths:
|
||||||
if dotfirst:
|
for ext in exts:
|
||||||
path = ["."] + path
|
fpath = os.path.join(path, name) + ext
|
||||||
|
if os.path.exists(fpath) and os.access(fpath, os.X_OK):
|
||||||
pathext = os.environ[pathextsrc]
|
return fpath
|
||||||
pathext = filter(None, pathext.split(";"))
|
|
||||||
|
|
||||||
# The command name we are looking for
|
|
||||||
cmdName = executable
|
|
||||||
|
|
||||||
# Is the command name really a file name?
|
|
||||||
if '.' in cmdName:
|
|
||||||
# Fake it by making pathext a list of one empty string.
|
|
||||||
pathext = ['']
|
|
||||||
|
|
||||||
# Loop over the directories on the path, looking for the file.
|
|
||||||
for d in path:
|
|
||||||
for e in pathext:
|
|
||||||
filePath = os.path.join(d, cmdName + e)
|
|
||||||
if os.path.exists(filePath):
|
|
||||||
return filePath.replace('\\', '/')
|
|
||||||
|
|
||||||
print >>sys.stderr, 'Error: %s is not installed on your system.' % executable
|
|
||||||
if error:
|
|
||||||
print >>sys.stderr, error
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def check_executable_unix(executable, error):
|
|
||||||
with open('/dev/null', 'w') as devnull:
|
|
||||||
process = subprocess.Popen(['which', executable], stdout=devnull)
|
|
||||||
return_code = process.wait()
|
|
||||||
if return_code == 0:
|
|
||||||
return executable
|
|
||||||
else:
|
|
||||||
print >>sys.stderr, 'Error: %s is not installed on your system.' % executable
|
|
||||||
if error:
|
|
||||||
print >>sys.stderr, error
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
|
||||||
check_executable = check_executable_win
|
|
||||||
else:
|
|
||||||
check_executable = check_executable_unix
|
|
||||||
|
|
||||||
|
|
||||||
def build_qt():
|
def build_qt():
|
||||||
print 'Building Qt applications'
|
print 'Building Qt applications'
|
||||||
pyuic4 = check_executable('pyuic4', 'Install PyQt4-devel or disable Qt applications (with --no-qt).')
|
make = find_executable('make', ('gmake', 'make'))
|
||||||
|
pyuic4 = find_executable('pyuic4', ('python2-pyuic4', 'pyuic4-2.7', 'pyuic4-2.6', 'pyuic4-2.5', 'pyuic4'))
|
||||||
|
if not pyuic4 or not make:
|
||||||
|
print >>sys.stderr, 'Install PyQt4-devel or disable Qt applications (with --no-qt).'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
subprocess.check_call([make, '-C', 'weboob/applications/qboobmsg/ui', 'PYUIC=%s' % pyuic4])
|
||||||
env = {'PYUIC': pyuic4, 'PATH': os.environ['PATH']}
|
subprocess.check_call([make, '-C', 'weboob/applications/qhavedate/ui', 'PYUIC=%s' % pyuic4])
|
||||||
extraMakeFlag = ['-e']
|
subprocess.check_call([make, '-C', 'weboob/applications/qwebcontentedit/ui', 'PYUIC=%s' % pyuic4])
|
||||||
else:
|
subprocess.check_call([make, '-C', 'weboob/applications/qflatboob/ui', 'PYUIC=%s' % pyuic4])
|
||||||
env = None
|
subprocess.check_call([make, '-C', 'weboob/tools/application/qt', 'PYUIC=%s' % pyuic4])
|
||||||
extraMakeFlag = []
|
|
||||||
|
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/applications/qboobmsg/ui'], env=env)
|
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/applications/qhavedate/ui'], env=env)
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/applications/qvideoob/ui'], env=env)
|
subprocess.check_call([make, '-C', 'weboob/applications/qvideoob/ui', 'PYUIC=%s' % pyuic4])
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/applications/qwebcontentedit/ui'], env=env)
|
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/applications/qflatboob/ui'], env=env)
|
|
||||||
subprocess.check_call(['make']+extraMakeFlag+['-C', 'weboob/tools/application/qt'], env=env)
|
|
||||||
|
|
||||||
|
|
||||||
class Options(object):
|
class Options(object):
|
||||||
pass
|
hildon = False
|
||||||
|
qt = True
|
||||||
|
xdg = True
|
||||||
|
|
||||||
options = Options()
|
options = Options()
|
||||||
options.hildon = False
|
|
||||||
options.qt = True
|
|
||||||
options.xdg = True
|
|
||||||
|
|
||||||
args = list(sys.argv)
|
args = list(sys.argv)
|
||||||
if '--hildon' in args and '--no-hildon' in args:
|
if '--hildon' in args and '--no-hildon' in args:
|
||||||
print '--hildon and --no-hildon options are incompatible'
|
print >>sys.stderr, '--hildon and --no-hildon options are incompatible'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if '--qt' in args and '--no-qt' in args:
|
if '--qt' in args and '--no-qt' in args:
|
||||||
print '--qt and --no-qt options are incompatible'
|
print >>sys.stderr, '--qt and --no-qt options are incompatible'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if '--xdg' in args and '--no-xdg' in args:
|
if '--xdg' in args and '--no-xdg' in args:
|
||||||
print '--xdg and --no-xdg options are incompatible'
|
print >>sys.stderr, '--xdg and --no-xdg options are incompatible'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if '--hildon' in args or os.environ.get('HILDON') == 'true':
|
if '--hildon' in args or os.environ.get('HILDON') == 'true':
|
||||||
|
|
@ -161,7 +117,7 @@ else:
|
||||||
|
|
||||||
hildon_packages = set((
|
hildon_packages = set((
|
||||||
'weboob.applications.masstransit',
|
'weboob.applications.masstransit',
|
||||||
),)
|
))
|
||||||
qt_packages = set((
|
qt_packages = set((
|
||||||
'weboob.applications.qboobmsg',
|
'weboob.applications.qboobmsg',
|
||||||
'weboob.applications.qboobmsg.ui',
|
'weboob.applications.qboobmsg.ui',
|
||||||
|
|
@ -175,7 +131,7 @@ qt_packages = set((
|
||||||
'weboob.applications.qwebcontentedit.ui'
|
'weboob.applications.qwebcontentedit.ui'
|
||||||
'weboob.applications.qflatboob',
|
'weboob.applications.qflatboob',
|
||||||
'weboob.applications.qflatboob.ui'
|
'weboob.applications.qflatboob.ui'
|
||||||
))
|
))
|
||||||
|
|
||||||
if not options.hildon:
|
if not options.hildon:
|
||||||
packages = packages - hildon_packages
|
packages = packages - hildon_packages
|
||||||
|
|
@ -184,16 +140,16 @@ if not options.qt:
|
||||||
|
|
||||||
data_files = [
|
data_files = [
|
||||||
('share/man/man1', glob.glob('man/*')),
|
('share/man/man1', glob.glob('man/*')),
|
||||||
]
|
]
|
||||||
if options.xdg:
|
if options.xdg:
|
||||||
data_files.extend([
|
data_files.extend([
|
||||||
('share/applications', glob.glob('desktop/*')),
|
('share/applications', glob.glob('desktop/*')),
|
||||||
('share/icons/hicolor/64x64/apps', glob.glob('icons/*')),
|
('share/icons/hicolor/64x64/apps', glob.glob('icons/*')),
|
||||||
])
|
])
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='weboob',
|
name='weboob',
|
||||||
version = '0.d',
|
version='0.d',
|
||||||
description='Weboob, Web Outside Of Browsers',
|
description='Weboob, Web Outside Of Browsers',
|
||||||
long_description=open('README').read(),
|
long_description=open('README').read(),
|
||||||
author='Romain Bignon',
|
author='Romain Bignon',
|
||||||
|
|
@ -234,5 +190,5 @@ setup(
|
||||||
# 'Routes', # python-routes
|
# 'Routes', # python-routes
|
||||||
# 'simplejson', # python-simplejson
|
# 'simplejson', # python-simplejson
|
||||||
# 'WebOb', # python-webob
|
# 'WebOb', # python-webob
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue