forked from ssokolow/quicktile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·137 lines (116 loc) · 4.74 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
"""
@todo:
- Identify minimum dependency versions properly.
- Figure out how to mark optional packages as optional.
- Is there a more idiomatic way to handle install_requires for things which
don't always install the requisite metadata for normal detection?
"""
from __future__ import print_function
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__license__ = "GNU GPL 2.0 or later"
import io, os, re, sys
from setuptools import setup
# Requirements adapter for packages which may not be PyPI-installable
REQUIRES = []
# TODO: Look up how to make this a setuptools feature
# REQUIRES = ['python-xlib',]
# Look outside the virtualenv for PyGTK
# Source: https://stackoverflow.com/a/27471354/435253
try:
# pylint: disable=unused-import
import gtk # NOQA
except ImportError:
print('--------------')
import subprocess
instdir = subprocess.check_output([
'/usr/bin/python',
'-c',
'import os, pygtk; print os.path.dirname(pygtk.__file__)',
]).strip()
for dst_base in sys.path:
if dst_base.strip():
break
for d in ['pygtk.pth', 'pygtk.py', 'gtk-2.0', 'gobject', 'glib',
'cairo']:
src = os.path.join(instdir, d)
dst = os.path.join(dst_base, d)
if os.path.exists(src) and not os.path.exists(dst):
print('linking', d, 'to', dst_base)
os.symlink(src, dst)
def test_for_imports(choices, package_name, human_package_name):
"""Detect packages without requiring egg metadata
Fallback to either adding an install_requires entry or exiting with
an error message.
"""
if os.environ.get("IS_BUILDING_PACKAGE", None):
return # Allow packaging without runtime-only deps installed
if isinstance(choices, basestring):
choices = [choices]
while choices:
# Detect package without requiring egg metadata
try:
current = choices.pop(0)
__import__(current)
except ImportError:
if choices: # Allow a fallback chain
continue
if package_name:
REQUIRES.append(package_name)
else:
print("Could not import '%s'. Please make sure you have %s "
"installed." % (current, human_package_name))
sys.exit(1)
test_for_imports("gtk", "pygtk", "PyGTK")
test_for_imports("wnck", "python-wnck", "python-wnck")
# TODO: Look up how to make this a setuptools feature
# test_for_imports("dbus", "dbus-python", "python-dbus")
# Get the version from the program rather than duplicating it here
# Source: https://packaging.python.org/en/latest/single_source_version.html
def read(*names, **kwargs):
"""Convenience wrapper for read()ing a file"""
with io.open(os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")) as fobj:
return fobj.read()
def find_version(*file_paths):
"""Extract the value of __version__ from the given file"""
version_file = read(*file_paths)
version_match = re.search(r"^__version__\s*=\s*['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
if __name__ == '__main__':
setup(
name='QuickTile',
version=find_version("quicktile", "version.py"),
author='Stephan Sokolow (deitarion/SSokolow)',
author_email='http://ssokolow.com/ContactMe',
description='Add keyboard-driven window-tiling to any X11 window '
'manager (inspired by WinSplit Revolution)',
long_description=read("README.rst"),
url="http://ssokolow.com/quicktile/",
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: X11 Applications :: GTK',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License v2 or later'
' (GPLv2+)',
'Natural Language :: English',
'Operating System :: POSIX',
'Programming Language :: Python :: 2 :: Only',
'Topic :: Desktop Environment :: Window Managers',
'Topic :: Utilities',
],
keywords=('x11 desktop window tiling wm utility addon extension tile '
'layout positioning helper keyboard hotkey hotkeys shortcut '
'shortcuts tool'),
license="GPL-2.0+",
install_requires=REQUIRES,
packages=['quicktile'],
entry_points={
'console_scripts': ['quicktile=quicktile.__main__:main']
},
data_files=[('share/applications', ['quicktile.desktop'])]
)
# vim: set sw=4 sts=4 expandtab :