From 6bb5b32b6a88ab4b6367b4ff62798758fe06d444 Mon Sep 17 00:00:00 2001 From: coffeedogs Date: Fri, 18 May 2018 15:56:47 +0100 Subject: [PATCH] Added: Support installing system dependencies of optional extra_requires components --- checkdeps.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++- requirements.txt | 1 - setup.py | 21 +++++++++++------- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/checkdeps.py b/checkdeps.py index 05f00944..73e5994d 100644 --- a/checkdeps.py +++ b/checkdeps.py @@ -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: diff --git a/requirements.txt b/requirements.txt index 09b3a19c..e69de29b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -python_prctl diff --git a/setup.py b/setup.py index 12670ed6..4a750680 100644 --- a/setup.py +++ b/setup.py @@ -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",