Merge PR 1258 into v0.6

This commit is contained in:
Peter Šurda 2018-06-12 00:26:30 +02:00
commit 1f6a7adf03
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
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 from distutils.errors import CompileError
try: try:
@ -12,6 +21,29 @@ from importlib import import_module
import os import os
import sys 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 = { PACKAGE_MANAGER = {
"OpenBSD": "pkg_add", "OpenBSD": "pkg_add",
"FreeBSD": "pkg install", "FreeBSD": "pkg install",
@ -199,6 +231,7 @@ if not compiler:
if prereqs: if prereqs:
mandatory = list(x for x in prereqs if "optional" not in PACKAGES[x] or not PACKAGES[x]["optional"]) 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"]) optional = list(x for x in prereqs if "optional" in PACKAGES[x] and PACKAGES[x]["optional"])
if mandatory: if mandatory:
print "Missing mandatory dependencies: %s" % (" ".join(mandatory)) print "Missing mandatory dependencies: %s" % (" ".join(mandatory))
if optional: if optional:
@ -206,6 +239,28 @@ if prereqs:
for package in optional: for package in optional:
print PACKAGES[package].get('description') 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: if (not compiler or prereqs) and detectOS() in PACKAGE_MANAGER:
print "You can install the missing dependencies by running, as root:" print "You can install the missing dependencies by running, as root:"
if not compiler: if not compiler:

View File

@ -1 +0,0 @@
python_prctl

View File

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