Moved OS and package detection care to setuptools install command
This commit is contained in:
parent
e97df3ad4d
commit
9aacef144b
46
setup.py
46
setup.py
|
@ -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__":
|
|
||||||
|
class InstallCmd(install):
|
||||||
|
def run(self):
|
||||||
detectOS.result = None
|
detectOS.result = None
|
||||||
detectPrereqs.result = None
|
prereqs = detectPrereqs()
|
||||||
if detectPrereqs(True) != [] and detectOS() in packageManager:
|
if prereqs and detectOS() in packageManager:
|
||||||
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.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:
|
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) != [] and sys.stdin.isatty():
|
if prereqs and sys.stdin.isatty():
|
||||||
print "Press Return to continue"
|
print "Press Return to continue"
|
||||||
try:
|
try:
|
||||||
nothing = raw_input()
|
raw_input()
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user