Moved OS and package detection care to setuptools install command

This commit is contained in:
Dmitri Bogomolov 2017-03-25 11:48:45 +02:00
parent e97df3ad4d
commit 9aacef144b
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
1 changed files with 34 additions and 28 deletions

View File

@ -4,8 +4,10 @@ import os
import sys import sys
try: try:
from setuptools import setup, Extension from setuptools import setup, Extension
from setuptools.command.install import install
haveSetuptools = True haveSetuptools = True
except ImportError: except ImportError:
install = object
haveSetuptools = False haveSetuptools = False
from importlib import import_module from importlib import import_module
@ -127,7 +129,7 @@ def detectOS():
return detectOS.result return detectOS.result
def detectPrereqs(missing=False): def detectPrereqs(missing=True):
available = [] available = []
for module in packageName.keys(): for module in packageName.keys():
try: try:
@ -144,47 +146,51 @@ def prereqToPackages():
print "You can install the requirements by running, as root:" print "You can install the requirements by running, as root:"
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()))
for package in detectPrereqs(True): for package in detectPrereqs():
try: if packageName[package].get('optional'):
if packageName[package]['optional']: print packageName[package].get('description')
print packageName[package]['description']
except KeyError:
pass
def compilerToPackages(): def compilerToPackages():
if not detectOS() in compiling: if not detectOS() in compiling:
return return
print "You can install the requirements by running, as root:" print "You can install the requirements by running, as root:"
print "%s %s" % ( print "%s %s" % (
packageManager[detectOS()], compiling[detectOS()]) packageManager[detectOS.result], compiling[detectOS.result])
if __name__ == "__main__":
detectOS.result = None class InstallCmd(install):
detectPrereqs.result = None def run(self):
if detectPrereqs(True) != [] and detectOS() in packageManager: detectOS.result = None
if detectOS() is not None: prereqs = detectPrereqs()
if prereqs and detectOS() in packageManager:
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.result)
prereqToPackages() prereqToPackages()
try: try:
for module in detectPrereqs(True): for module in prereqs:
if not packageName[module]['optional']: if not packageName[module]['optional']:
sys.exit() sys.exit()
except KeyError: except KeyError:
sys.exit() sys.exit()
if not haveSetuptools:
print "It looks like you're missing setuptools."
sys.exit()
if detectPrereqs(True) != [] and sys.stdin.isatty(): if not haveSetuptools:
print "Press Return to continue" print "It looks like you're missing setuptools."
try: sys.exit()
nothing = raw_input()
except NameError:
pass
if prereqs and sys.stdin.isatty():
print "Press Return to continue"
try:
raw_input()
except NameError:
pass
return install.run(self)
if __name__ == "__main__":
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()
@ -197,7 +203,7 @@ if __name__ == "__main__":
installRequires = [] installRequires = []
# this will silently accept alternative providers of msgpack if they are already installed # this will silently accept alternative providers of msgpack if they are already installed
if "msgpack" in detectPrereqs(True): if "msgpack" in detectPrereqs():
installRequires.append("msgpack-python") installRequires.append("msgpack-python")
try: try:
@ -254,7 +260,8 @@ if __name__ == "__main__":
# 'pybitmessage = pybitmessage.bitmessagemain:main' # 'pybitmessage = pybitmessage.bitmessagemain:main'
# ] # ]
}, },
scripts=['src/pybitmessage'] scripts=['src/pybitmessage'],
cmdclass={'install': InstallCmd}
) )
except SystemExit as err: except SystemExit as err:
print err.message print err.message
@ -262,4 +269,3 @@ if __name__ == "__main__":
print "It looks like building the package failed.\n" \ print "It looks like building the package failed.\n" \
"You may be missing a C++ compiler and the OpenSSL headers." "You may be missing a C++ compiler and the OpenSSL headers."
compilerToPackages() compilerToPackages()