setup.py updates

- parametrise module list
- allow optional modules (pyopencl, PyQt4)
- add setuptools
- add compiler error detection
- press return to continue
This commit is contained in:
Peter Šurda 2017-03-01 11:29:38 +01:00
parent 15077c9388
commit af5cb08093
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

187
setup.py
View File

@ -24,7 +24,7 @@ packageManager = {
} }
packageName = { packageName = {
"PyQt": { "PyQt4": {
"OpenBSD": "py-qt4", "OpenBSD": "py-qt4",
"FreeBSD": "py27-qt4", "FreeBSD": "py27-qt4",
"Debian": "python-qt4", "Debian": "python-qt4",
@ -32,7 +32,12 @@ packageName = {
"openSUSE": "python-qt", "openSUSE": "python-qt",
"Fedora": "PyQt4", "Fedora": "PyQt4",
"Guix": "python2-pyqt@4.11.4", "Guix": "python2-pyqt@4.11.4",
"Gentoo": "dev-python/PyQt4" "Gentoo": "dev-python/PyQt4",
'optional': True,
'description': "You only need PyQt if you want to use the GUI. " \
"When only running as a daemon, this can be skipped.\n" \
"However, you would have to install it manually " \
"because setuptools does not support PyQt."
}, },
"msgpack": { "msgpack": {
"OpenBSD": "py-msgpack", "OpenBSD": "py-msgpack",
@ -49,10 +54,34 @@ packageName = {
"Debian": "python-pyopencl", "Debian": "python-pyopencl",
"Ubuntu": "python-pyopencl", "Ubuntu": "python-pyopencl",
"Fedora": "python2-pyopencl", "Fedora": "python2-pyopencl",
"Gentoo": "dev-python/pyopencl" "openSUSE": "",
"OpenBSD": "",
"Guix": "",
"Gentoo": "dev-python/pyopencl",
"optional": True,
'description': "If you install pyopencl, you will be able to use " \
"GPU acceleration for proof of work. \n" \
"You also need a compatible GPU and drivers."
},
"setuptools": {
"OpenBSD": "py-setuptools",
"FreeBSD": "py27-setuptools",
"Debian": "python-setuptools",
"Ubuntu": "python-setuptools",
"Fedora": "python2-setuptools",
"openSUSE": "python-setuptools",
"Guix": "python2-setuptools",
"Gentoo": "",
} }
} }
compiling = {
"Debian": "build-essential libssl-dev",
"Ubuntu": "build-essential libssl-dev",
"Fedora": "gcc-c++ redhat-rpm-config python-devel",
"openSUSE": "gcc-c++ libopenssl-devel python-devel",
}
def detectOS(): def detectOS():
if detectOS.result is not None: if detectOS.result is not None:
@ -87,27 +116,14 @@ def detectOS():
def detectPrereqs(missing=False): def detectPrereqs(missing=False):
available = [] available = []
try: for module in packageName.keys():
import_module("PyQt4.QtCore") try:
if not missing: import_module(module)
available.append("PyQt") if not missing:
except ImportError: available.append(module)
if missing: except ImportError:
available.append("PyQt") if missing:
try: available.append(module)
import_module("msgpack")
if not missing:
available.append("msgpack")
except ImportError:
if missing:
available.append("msgpack")
try:
import_module("pyopencl")
if not missing:
available.append("pyopencl")
except ImportError:
if missing:
available.append("pyopencl")
return available return available
@ -116,27 +132,40 @@ def prereqToPackages():
print "%s %s" % ( print "%s %s" % (
packageManager[detectOS()], " ".join( packageManager[detectOS()], " ".join(
packageName[x][detectOS()] for x in detectPrereqs(True))) packageName[x][detectOS()] for x in detectPrereqs(True)))
for package in detectPrereqs(True):
if packageName[package]['optional']:
print packageName[package]['description']
def compilerToPackages():
if not detectOS() in compiling:
return
print "You can install the requirements by running, as root:"
print "%s %s" % (
packageManager[detectOS()], compiling[detectOS()])
if __name__ == "__main__": if __name__ == "__main__":
detectOS.result = None detectOS.result = None
detectPrereqs.result = None detectPrereqs.result = None
if "PyQt" in detectPrereqs(True):
print "You only need PyQt if you want to use the GUI. " \
"When only running as a daemon, this can be skipped.\n" \
"However, you would have to install it manually " \
"because setuptools does not support pyqt."
if detectPrereqs(True) != [] and detectOS() in packageManager: if detectPrereqs(True) != [] and detectOS() in packageManager:
if detectOS() is not None: if detectOS() is not None:
print "It looks like you're using %s. " \ print "It looks like you're using %s. " \
"It is highly recommended to use the package manager " \ "It is highly recommended to use the package manager " \
"instead of setuptools." % (detectOS()) "instead of setuptools." % (detectOS())
prereqToPackages() prereqToPackages()
sys.exit() for module in detectPrereqs(True):
if not packageName[module]['optional']:
sys.exit()
if not haveSetuptools: if not haveSetuptools:
print "It looks like you're missing setuptools." print "It looks like you're missing setuptools."
sys.exit() sys.exit()
if detectPrereqs(True) != []:
print "Press Return to continue"
try:
nothing = raw_input
except NameError:
pass
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md')) as f: with open(os.path.join(here, 'README.md')) as f:
README = f.read() README = f.read()
@ -147,49 +176,55 @@ if __name__ == "__main__":
libraries=['pthread', 'crypto'], libraries=['pthread', 'crypto'],
) )
dist = setup( try:
name='pybitmessage', dist = setup(
version=softwareVersion, name='pybitmessage',
description="Reference client for Bitmessage: " version=softwareVersion,
"a P2P communications protocol", description="Reference client for Bitmessage: "
long_description=README, "a P2P communications protocol",
license='MIT', long_description=README,
# TODO: add author info license='MIT',
#author='', # TODO: add author info
#author_email='', #author='',
url='https://bitmessage.org', #author_email='',
# TODO: add keywords url='https://bitmessage.org',
#keywords='', # TODO: add keywords
install_requires=['msgpack-python'], #keywords='',
classifiers=[ install_requires=['msgpack-python'],
"License :: OSI Approved :: MIT License" classifiers=[
"Operating System :: OS Independent", "License :: OSI Approved :: MIT License"
"Programming Language :: Python :: 2.7 :: Only", "Operating System :: OS Independent",
"Topic :: Internet", "Programming Language :: Python :: 2.7 :: Only",
"Topic :: Security :: Cryptography", "Topic :: Internet",
"Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Security :: Cryptography",
], "Topic :: Software Development :: Libraries :: Python Modules",
package_dir={'pybitmessage': 'src'}, ],
packages=[ package_dir={'pybitmessage': 'src'},
'pybitmessage', packages=[
'pybitmessage.bitmessageqt', 'pybitmessage',
'pybitmessage.bitmessagecurses', 'pybitmessage.bitmessageqt',
'pybitmessage.messagetypes', 'pybitmessage.bitmessagecurses',
'pybitmessage.network', 'pybitmessage.messagetypes',
'pybitmessage.pyelliptic', 'pybitmessage.network',
'pybitmessage.socks', 'pybitmessage.pyelliptic',
], 'pybitmessage.socks',
package_data={'': [ ],
'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', package_data={'': [
'translations/*.ts', 'translations/*.qm', 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem',
'images/*.png', 'images/*.ico', 'images/*.icns' 'translations/*.ts', 'translations/*.qm',
]}, 'images/*.png', 'images/*.ico', 'images/*.icns'
ext_modules=[bitmsghash], ]},
zip_safe=False, ext_modules=[bitmsghash],
#entry_points={ zip_safe=False,
# 'console_scripts': [ #entry_points={
# 'pybitmessage = pybitmessage.bitmessagemain:main' # 'console_scripts': [
# ] # 'pybitmessage = pybitmessage.bitmessagemain:main'
#}, # ]
scripts=['src/pybitmessage'] #},
) scripts=['src/pybitmessage']
)
except SystemExit:
print "It looks like building the package failed.\n" \
"You may be missing a C++ compiler and the OpenSSL headers."
compilerToPackages()