2018-05-22 13:16:13 +02:00
|
|
|
#!/usr/bin/env python2
|
2018-05-18 16:56:47 +02:00
|
|
|
"""
|
2019-12-27 13:32:43 +01:00
|
|
|
Check dependencies and give recommendations about how to satisfy them
|
2018-05-18 16:56:47 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................13')
|
2018-05-22 13:16:13 +02:00
|
|
|
import os
|
2018-07-22 13:20:07 +02:00
|
|
|
import sys
|
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-11-04 15:17:36 +01:00
|
|
|
EXTRAS_REQUIRE = {}
|
2018-05-22 13:16:13 +02:00
|
|
|
|
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": [""],
|
2021-02-08 19:14:48 +01:00
|
|
|
"Debian": ["libpcap-dev python-prctl"],
|
|
|
|
"Ubuntu": ["libpcap-dev python-prctl"],
|
|
|
|
"Ubuntu 12": ["libpcap-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):
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................60')
|
2017-09-19 16:27:42 +02:00
|
|
|
available = []
|
|
|
|
for module in PACKAGES:
|
|
|
|
try:
|
2021-02-08 19:14:48 +01:00
|
|
|
# import pdb;pdb.set_trace()
|
|
|
|
print('nodule---------: ', module)
|
2017-09-19 16:27:42 +02:00
|
|
|
import_module(module)
|
2021-02-08 19:14:48 +01:00
|
|
|
print('pass.........................')
|
2017-09-19 16:27:42 +02:00
|
|
|
if not missing:
|
|
|
|
available.append(module)
|
|
|
|
except ImportError:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('Fail.........................')
|
2017-09-19 16:27:42 +02:00
|
|
|
if missing:
|
|
|
|
available.append(module)
|
2021-02-08 19:14:48 +01:00
|
|
|
print('available------:', available)
|
2017-09-19 16:27:42 +02:00
|
|
|
return available
|
|
|
|
|
2018-05-22 13:16:13 +02:00
|
|
|
|
2017-09-19 16:27:42 +02:00
|
|
|
def prereqToPackages():
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................78')
|
2017-09-19 16:27:42 +02:00
|
|
|
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():
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................87')
|
2017-09-19 16:27:42 +02:00
|
|
|
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():
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................95')
|
2017-09-19 16:27:42 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................121')
|
2018-05-22 13:16:13 +02:00
|
|
|
prereqs = detectPrereqs()
|
2017-09-19 16:27:42 +02:00
|
|
|
compiler = testCompiler()
|
2021-02-08 19:14:48 +01:00
|
|
|
print('compiler-----------: ', compiler)
|
2017-09-19 16:27:42 +02:00
|
|
|
|
|
|
|
if (not compiler or prereqs) and detectOS() in PACKAGE_MANAGER:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................126')
|
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:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................133')
|
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:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................139')
|
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'
|
2021-02-08 19:14:48 +01:00
|
|
|
print('CMD---------------: ', CMD)
|
|
|
|
print('line...........................152')
|
2018-05-18 16:56:47 +02:00
|
|
|
for lhs, rhs in EXTRAS_REQUIRE.items():
|
2018-07-22 13:48:08 +02:00
|
|
|
if OPSYS is None:
|
|
|
|
break
|
2021-02-08 19:14:48 +01:00
|
|
|
print()
|
2018-05-18 16:56:47 +02:00
|
|
|
if rhs and any([
|
|
|
|
EXTRAS_REQUIRE_DEPS[x][OPSYS]
|
|
|
|
for x in rhs
|
|
|
|
if x in EXTRAS_REQUIRE_DEPS
|
|
|
|
]):
|
2021-02-08 19:14:48 +01:00
|
|
|
print('EXTRAS_REQUIRE_DEPS[x][OPSYS]: ', EXTRAS_REQUIRE_DEPS[rhs[0]][OPSYS])
|
2020-11-25 15:22:27 +01:00
|
|
|
try:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('lhs---------: ', lhs, rhs)
|
2020-11-25 15:22:27 +01:00
|
|
|
import_module(lhs)
|
2021-02-08 19:14:48 +01:00
|
|
|
print('pass..................167')
|
|
|
|
# import pdb;pdb.set_trace()
|
2020-11-25 15:22:27 +01:00
|
|
|
except Exception as e:
|
2021-02-08 19:14:48 +01:00
|
|
|
print('fail-----------------169')
|
2020-11-25 15:22:27 +01:00
|
|
|
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
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
print(
|
|
|
|
"Optional dependency `pip install .[{}]` would require `{}`"
|
|
|
|
" to be run as root".format(lhs, rhs_cmd))
|
2018-05-18 16:56:47 +02:00
|
|
|
|
2021-02-08 19:14:48 +01:00
|
|
|
print('line...........................179')
|
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()
|
2019-12-03 12:59:27 +01:00
|
|
|
if prereqs and mandatory:
|
2018-07-22 13:20:07 +02:00
|
|
|
sys.exit(1)
|
2017-09-19 16:27:42 +02:00
|
|
|
else:
|
2018-05-22 13:16:13 +02:00
|
|
|
print("All the dependencies satisfied, you can install PyBitmessage")
|