2018-05-22 13:16:13 +02:00
|
|
|
#!/usr/bin/env python2
|
2018-05-18 16:56:47 +02:00
|
|
|
"""
|
|
|
|
Check dependendies and give recommendations about how to satisfy them
|
|
|
|
|
|
|
|
Limitations:
|
|
|
|
|
|
|
|
* Does not detect whether packages are already installed. Solving this requires writing more of a configuration
|
|
|
|
management system. Or we could switch to an existing one.
|
|
|
|
* Not fully PEP508 compliant. Not slightly. It makes bold assumptions about the simplicity of the contents of
|
|
|
|
EXTRAS_REQUIRE. This is fine because most developers do, too.
|
|
|
|
"""
|
2017-09-19 16:27:42 +02:00
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
import os
|
2017-09-19 16:27:42 +02:00
|
|
|
from distutils.errors import CompileError
|
|
|
|
try:
|
|
|
|
from setuptools.dist import Distribution
|
|
|
|
from setuptools.extension import Extension
|
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
HAVE_SETUPTOOLS = True
|
2018-05-22 13:16:13 +02:00
|
|
|
# another import from setuptools is in setup.py
|
|
|
|
from setup import EXTRAS_REQUIRE
|
2017-09-19 16:27:42 +02:00
|
|
|
except ImportError:
|
|
|
|
HAVE_SETUPTOOLS = False
|
2018-05-22 13:16:13 +02:00
|
|
|
EXTRAS_REQUIRE = []
|
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
from importlib import import_module
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
from src.depends import detectOS, PACKAGES, PACKAGE_MANAGER
|
2018-05-18 16:56:47 +02:00
|
|
|
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
COMPILING = {
|
|
|
|
"Debian": "build-essential libssl-dev",
|
|
|
|
"Ubuntu": "build-essential libssl-dev",
|
|
|
|
"Fedora": "gcc-c++ redhat-rpm-config python-devel openssl-devel",
|
|
|
|
"openSUSE": "gcc-c++ libopenssl-devel python-devel",
|
|
|
|
"optional": False,
|
|
|
|
}
|
2018-05-18 16:56:47 +02:00
|
|
|
|
|
|
|
# OS-specific dependencies for optional components listed in EXTRAS_REQUIRE
|
|
|
|
EXTRAS_REQUIRE_DEPS = {
|
|
|
|
# The values from setup.EXTRAS_REQUIRE
|
|
|
|
'python_prctl': {
|
|
|
|
# The packages needed for this requirement, by OS
|
|
|
|
"OpenBSD": [""],
|
|
|
|
"FreeBSD": [""],
|
2018-05-22 13:16:13 +02:00
|
|
|
"Debian": ["libcap-dev python-prctl"],
|
|
|
|
"Ubuntu": ["libcap-dev python-prctl"],
|
|
|
|
"Ubuntu 12": ["libcap-dev python-prctl"],
|
2018-05-18 16:56:47 +02:00
|
|
|
"openSUSE": [""],
|
2018-05-22 13:16:13 +02:00
|
|
|
"Fedora": ["prctl"],
|
2018-05-18 16:56:47 +02:00
|
|
|
"Guix": [""],
|
2018-05-22 13:16:13 +02:00
|
|
|
"Gentoo": ["dev-python/python-prctl"],
|
2018-05-18 16:56:47 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
def detectPrereqs(missing=True):
|
|
|
|
available = []
|
|
|
|
for module in PACKAGES:
|
|
|
|
try:
|
|
|
|
import_module(module)
|
|
|
|
if not missing:
|
|
|
|
available.append(module)
|
|
|
|
except ImportError:
|
|
|
|
if missing:
|
|
|
|
available.append(module)
|
|
|
|
return available
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
def prereqToPackages():
|
|
|
|
if not detectPrereqs():
|
|
|
|
return
|
2018-05-22 13:16:13 +02:00
|
|
|
print("%s %s" % (
|
2017-09-19 16:27:42 +02:00
|
|
|
PACKAGE_MANAGER[detectOS()], " ".join(
|
2018-05-22 13:16:13 +02:00
|
|
|
PACKAGES[x][detectOS()] for x in detectPrereqs())))
|
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
def compilerToPackages():
|
|
|
|
if not detectOS() in COMPILING:
|
|
|
|
return
|
2018-05-22 13:16:13 +02:00
|
|
|
print("%s %s" % (
|
|
|
|
PACKAGE_MANAGER[detectOS.result], COMPILING[detectOS.result]))
|
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
def testCompiler():
|
|
|
|
if not HAVE_SETUPTOOLS:
|
|
|
|
# silent, we can't test without setuptools
|
|
|
|
return True
|
|
|
|
|
|
|
|
bitmsghash = Extension(
|
|
|
|
'bitmsghash',
|
|
|
|
sources=['src/bitmsghash/bitmsghash.cpp'],
|
|
|
|
libraries=['pthread', 'crypto'],
|
|
|
|
)
|
|
|
|
|
|
|
|
dist = Distribution()
|
|
|
|
dist.ext_modules = [bitmsghash]
|
|
|
|
cmd = build_ext(dist)
|
|
|
|
cmd.initialize_options()
|
|
|
|
cmd.finalize_options()
|
|
|
|
cmd.force = True
|
|
|
|
try:
|
|
|
|
cmd.run()
|
|
|
|
except CompileError:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
fullPath = os.path.join(cmd.build_lib, cmd.get_ext_filename("bitmsghash"))
|
|
|
|
return os.path.isfile(fullPath)
|
|
|
|
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
prereqs = detectPrereqs()
|
2017-09-19 16:27:42 +02:00
|
|
|
compiler = testCompiler()
|
|
|
|
|
|
|
|
if (not compiler or prereqs) and detectOS() in PACKAGE_MANAGER:
|
2018-05-22 13:16:13 +02:00
|
|
|
print(
|
|
|
|
"It looks like you're using %s. "
|
|
|
|
"It is highly recommended to use the package manager\n"
|
|
|
|
"to install the missing dependencies." % detectOS.result)
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
if not compiler:
|
2018-05-22 13:16:13 +02:00
|
|
|
print(
|
|
|
|
"Building the bitmsghash module failed.\n"
|
|
|
|
"You may be missing a C++ compiler and/or the OpenSSL headers.")
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
if prereqs:
|
2018-05-22 13:16:13 +02:00
|
|
|
mandatory = [x for x in prereqs if not PACKAGES[x].get("optional")]
|
|
|
|
optional = [x for x in prereqs if PACKAGES[x].get("optional")]
|
2017-09-19 16:27:42 +02:00
|
|
|
if mandatory:
|
2018-05-22 13:16:13 +02:00
|
|
|
print("Missing mandatory dependencies: %s" % " ".join(mandatory))
|
2017-09-19 16:27:42 +02:00
|
|
|
if optional:
|
2018-05-22 13:16:13 +02:00
|
|
|
print("Missing optional dependencies: %s" % " ".join(optional))
|
2017-09-19 16:27:42 +02:00
|
|
|
for package in optional:
|
2018-05-22 13:16:13 +02:00
|
|
|
print(PACKAGES[package].get('description'))
|
2017-09-19 16:27:42 +02:00
|
|
|
|
2018-05-18 16:56:47 +02:00
|
|
|
# Install the system dependencies of optional extras_require components
|
|
|
|
OPSYS = detectOS()
|
|
|
|
CMD = PACKAGE_MANAGER[OPSYS] if OPSYS in PACKAGE_MANAGER else 'UNKNOWN_INSTALLER'
|
|
|
|
for lhs, rhs in EXTRAS_REQUIRE.items():
|
|
|
|
if rhs and any([
|
|
|
|
EXTRAS_REQUIRE_DEPS[x][OPSYS]
|
|
|
|
for x in rhs
|
|
|
|
if x in EXTRAS_REQUIRE_DEPS
|
|
|
|
]):
|
|
|
|
rhs_cmd = ''.join([
|
|
|
|
CMD,
|
|
|
|
' ',
|
|
|
|
' '.join([
|
|
|
|
''. join([
|
|
|
|
xx for xx in EXTRAS_REQUIRE_DEPS[x][OPSYS]
|
|
|
|
])
|
|
|
|
for x in rhs
|
|
|
|
if x in EXTRAS_REQUIRE_DEPS
|
|
|
|
]),
|
|
|
|
])
|
2018-05-22 13:16:13 +02:00
|
|
|
print(
|
|
|
|
"Optional dependency `pip install .[{}]` would require `{}`"
|
|
|
|
" to be run as root".format(lhs, rhs_cmd))
|
2018-05-18 16:56:47 +02:00
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
|
|
|
|
print("You can install the missing dependencies by running, as root:")
|
2017-09-19 16:27:42 +02:00
|
|
|
if not compiler:
|
|
|
|
compilerToPackages()
|
|
|
|
prereqToPackages()
|
|
|
|
else:
|
2018-05-22 13:16:13 +02:00
|
|
|
print("All the dependencies satisfied, you can install PyBitmessage")
|