From af5cb08093a24d9c64669a96ed71a360db569d17 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 1 Mar 2017 11:29:38 +0100 Subject: [PATCH] setup.py updates - parametrise module list - allow optional modules (pyopencl, PyQt4) - add setuptools - add compiler error detection - press return to continue --- setup.py | 187 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 76 deletions(-) diff --git a/setup.py b/setup.py index 078fbc2d..77434a78 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ packageManager = { } packageName = { - "PyQt": { + "PyQt4": { "OpenBSD": "py-qt4", "FreeBSD": "py27-qt4", "Debian": "python-qt4", @@ -32,7 +32,12 @@ packageName = { "openSUSE": "python-qt", "Fedora": "PyQt4", "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": { "OpenBSD": "py-msgpack", @@ -49,10 +54,34 @@ packageName = { "Debian": "python-pyopencl", "Ubuntu": "python-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(): if detectOS.result is not None: @@ -87,27 +116,14 @@ def detectOS(): def detectPrereqs(missing=False): available = [] - try: - import_module("PyQt4.QtCore") - if not missing: - available.append("PyQt") - except ImportError: - if missing: - available.append("PyQt") - try: - 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") + for module in packageName.keys(): + try: + import_module(module) + if not missing: + available.append(module) + except ImportError: + if missing: + available.append(module) return available @@ -116,27 +132,40 @@ def prereqToPackages(): print "%s %s" % ( packageManager[detectOS()], " ".join( 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__": detectOS.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 detectOS() is not None: print "It looks like you're using %s. " \ "It is highly recommended to use the package manager " \ "instead of setuptools." % (detectOS()) prereqToPackages() - sys.exit() + for module in detectPrereqs(True): + if not packageName[module]['optional']: + sys.exit() if not haveSetuptools: print "It looks like you're missing setuptools." 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__)) with open(os.path.join(here, 'README.md')) as f: README = f.read() @@ -147,49 +176,55 @@ if __name__ == "__main__": libraries=['pthread', 'crypto'], ) - dist = setup( - name='pybitmessage', - version=softwareVersion, - description="Reference client for Bitmessage: " - "a P2P communications protocol", - long_description=README, - license='MIT', - # TODO: add author info - #author='', - #author_email='', - url='https://bitmessage.org', - # TODO: add keywords - #keywords='', - install_requires=['msgpack-python'], - classifiers=[ - "License :: OSI Approved :: MIT License" - "Operating System :: OS Independent", - "Programming Language :: Python :: 2.7 :: Only", - "Topic :: Internet", - "Topic :: Security :: Cryptography", - "Topic :: Software Development :: Libraries :: Python Modules", - ], - package_dir={'pybitmessage': 'src'}, - packages=[ - 'pybitmessage', - 'pybitmessage.bitmessageqt', - 'pybitmessage.bitmessagecurses', - 'pybitmessage.messagetypes', - 'pybitmessage.network', - 'pybitmessage.pyelliptic', - 'pybitmessage.socks', - ], - package_data={'': [ - 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', - 'translations/*.ts', 'translations/*.qm', - 'images/*.png', 'images/*.ico', 'images/*.icns' - ]}, - ext_modules=[bitmsghash], - zip_safe=False, - #entry_points={ - # 'console_scripts': [ - # 'pybitmessage = pybitmessage.bitmessagemain:main' - # ] - #}, - scripts=['src/pybitmessage'] - ) + try: + dist = setup( + name='pybitmessage', + version=softwareVersion, + description="Reference client for Bitmessage: " + "a P2P communications protocol", + long_description=README, + license='MIT', + # TODO: add author info + #author='', + #author_email='', + url='https://bitmessage.org', + # TODO: add keywords + #keywords='', + install_requires=['msgpack-python'], + classifiers=[ + "License :: OSI Approved :: MIT License" + "Operating System :: OS Independent", + "Programming Language :: Python :: 2.7 :: Only", + "Topic :: Internet", + "Topic :: Security :: Cryptography", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + package_dir={'pybitmessage': 'src'}, + packages=[ + 'pybitmessage', + 'pybitmessage.bitmessageqt', + 'pybitmessage.bitmessagecurses', + 'pybitmessage.messagetypes', + 'pybitmessage.network', + 'pybitmessage.pyelliptic', + 'pybitmessage.socks', + ], + package_data={'': [ + 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem', + 'translations/*.ts', 'translations/*.qm', + 'images/*.png', 'images/*.ico', 'images/*.icns' + ]}, + ext_modules=[bitmsghash], + zip_safe=False, + #entry_points={ + # 'console_scripts': [ + # 'pybitmessage = pybitmessage.bitmessagemain:main' + # ] + #}, + 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() +