Completed
Push — master ( 65fc05...2474d8 )
by Stephan
01:10
created

find_version()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
1
#!/usr/bin/env python
2
"""
3
4
@todo:
5
 - Identify minimum dependency versions properly.
6
 - Figure out how to mark optional packages as optional.
7
 - Is there a more idiomatic way to handle install_requires for things which
8
   don't always install the requisite metadata for normal detection?
9
"""
10
11
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
12
__license__ = "GNU GPL 2.0 or later"
13
14
import io, os, re, sys
15
from setuptools import setup
16
17
# Requirements adapter for packages which may not be PyPI-installable
18
REQUIRES = ['python-xlib', ]
19
20
def test_for_imports(choices, package_name, human_package_name):
21
    """Detect packages without requiring egg metadata
22
23
    Fallback to either adding an install_requires entry or exiting with
24
    an error message.
25
    """
26
    if os.environ.get("IS_BUILDING_PACKAGE", None):
27
        return  # Allow packaging without runtime-only deps installed
28
29
    if isinstance(choices, basestring):
30
        choices = [choices]
31
32
    while choices:
33
        # Detect package without requiring egg metadata
34
        try:
35
            current = choices.pop(0)
36
            __import__(current)
37
        except ImportError:
38
            if choices:  # Allow a fallback chain
39
                continue
40
41
            if package_name:
42
                REQUIRES.append(package_name)
43
            else:
44
                print("Could not import '%s'. Please make sure you have %s "
45
                      "installed." % (current, human_package_name))
46
                sys.exit(1)
47
48
test_for_imports("gtk", "pygtk", "PyGTK")
49
test_for_imports("dbus", "dbus-python", "python-dbus")
50
51
# Get the version from the program rather than duplicating it here
52
# Source: https://packaging.python.org/en/latest/single_source_version.html
53
def read(*names, **kwargs):
54
    """Convenience wrapper for read()ing a file"""
55
    with io.open(os.path.join(os.path.dirname(__file__), *names),
56
              encoding=kwargs.get("encoding", "utf8")) as fobj:
57
        return fobj.read()
58
59
def find_version(*file_paths):
60
    """Extract the value of __version__ from the given file"""
61
    version_file = read(*file_paths)
62
    version_match = re.search(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]",
63
                              version_file, re.M)
64
    if version_match:
65
        return version_match.group(1)
66
    raise RuntimeError("Unable to find version string.")
67
68
if __name__ == '__main__':
69
    setup(
70
        name='QuickTile',
71
        version=find_version("quicktile.py"),
72
        author='Stephan Sokolow (deitarion/SSokolow)',
73
        author_email='http://ssokolow.com/ContactMe',
74
        description='Add keyboard-driven window-tiling to any X11 window '
75
                    'manager (inspired by WinSplit Revolution)',
76
        long_description=read("README.rst"),
77
        url="http://ssokolow.com/quicktile/",
78
79
        classifiers=[
80
            'Development Status :: 4 - Beta',
81
            'Environment :: X11 Applications :: GTK',
82
            'Intended Audience :: End Users/Desktop',
83
            'License :: OSI Approved :: GNU General Public License v2 or later'
84
            ' (GPLv2+)',
85
            'Natural Language :: English',
86
            'Operating System :: POSIX',
87
            'Programming Language :: Python :: 2 :: Only',
88
            'Topic :: Desktop Environment :: Window Managers',
89
            'Topic :: Utilities',
90
        ],
91
        keywords=('x11 desktop window tiling wm utility addon extension tile '
92
                  'layout positioning helper keyboard hotkey hotkeys shortcut '
93
                  'shortcuts tool'),
94
        license="GPL-2.0+",
95
96
        install_requires=REQUIRES,
97
98
        scripts=['quicktile.py'],
99
        data_files=[('share/applications', ['quicktile.desktop'])]
100
    )
101
102
# vim: set sw=4 sts=4 expandtab :
103