Added: Support installing system dependencies of optional extra_requires components

This commit is contained in:
coffeedogs 2018-05-18 15:56:47 +01:00
parent 7445665963
commit 6bb5b32b6a
No known key found for this signature in database
GPG Key ID: 9D818C503D0B7E70
3 changed files with 69 additions and 10 deletions

View File

@ -1,4 +1,13 @@
"""Check dependendies and give recommendations about how to satisfy them"""
"""
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.
"""
from distutils.errors import CompileError
try:
@ -12,6 +21,29 @@ from importlib import import_module
import os
import sys
from setup import EXTRAS_REQUIRE
PROJECT_ROOT = os.path.abspath('..')
sys.path.insert(0, PROJECT_ROOT)
# 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": [""],
"Debian": ["libcap-dev"],
"Ubuntu": [""],
"Ubuntu 12": [""],
"openSUSE": [""],
"Fedora": [""],
"Guix": [""],
"Gentoo": [""],
},
}
PACKAGE_MANAGER = {
"OpenBSD": "pkg_add",
"FreeBSD": "pkg install",
@ -199,6 +231,7 @@ if not compiler:
if prereqs:
mandatory = list(x for x in prereqs if "optional" not in PACKAGES[x] or not PACKAGES[x]["optional"])
optional = list(x for x in prereqs if "optional" in PACKAGES[x] and PACKAGES[x]["optional"])
if mandatory:
print "Missing mandatory dependencies: %s" % (" ".join(mandatory))
if optional:
@ -206,6 +239,28 @@ if prereqs:
for package in optional:
print PACKAGES[package].get('description')
# 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
]),
])
print "Optional dependency `pip install .[{}]` would require `{}` to be run as root".format(lhs, rhs_cmd)
if (not compiler or prereqs) and detectOS() in PACKAGE_MANAGER:
print "You can install the missing dependencies by running, as root:"
if not compiler:

View File

@ -1 +0,0 @@
python_prctl

View File

@ -1,13 +1,24 @@
#!/usr/bin/env python2.7
import os
import sys
import shutil
from setuptools import setup, Extension
from setuptools.command.install import install
from src.version import softwareVersion
EXTRAS_REQUIRE = {
'gir': ['pygobject'],
'notify2': ['notify2'],
'pyopencl': ['pyopencl'],
'prctl': ['python_prctl'], # Named threads
'qrcode': ['qrcode'],
'sound;platform_system=="Windows"': ['winsound']
}
class InstallCmd(install):
def run(self):
# prepare icons directories
@ -78,13 +89,7 @@ if __name__ == "__main__":
# TODO: add keywords
#keywords='',
install_requires=installRequires,
extras_require={
'gir': ['pygobject'],
'qrcode': ['qrcode'],
'pyopencl': ['pyopencl'],
'notify2': ['notify2'],
'sound;platform_system=="Windows"': ['winsound']
},
extras_require=EXTRAS_REQUIRE,
classifiers=[
"License :: OSI Approved :: MIT License"
"Operating System :: OS Independent",