forked from Asvel/pygs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
154 lines (124 loc) · 4.77 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import shutil
import subprocess
from errno import ENOENT
from distutils import log
from distutils.command.build_clib import build_clib
from distutils.command.build_ext import build_ext
import codecs
from setuptools import setup, Extension
from setuptools.command.bdist_egg import NATIVE_EXTENSIONS
# determine Qt version to build for
qt_api = os.environ.get('QT_SELECT', '5')
if qt_api not in ('4', '5'):
print("Qt version {} not supported for pyqxtgs build".format(qt_api))
sys.exit(1)
pyqxtgs = "pyqxtgs{}".format(qt_api)
def makedirs(name):
if not os.path.exists(name):
os.makedirs(name)
def try_initialize_compiler(compiler):
if not getattr(compiler, 'initialized', True) and hasattr(compiler, 'initialize'):
compiler.initialize()
def check_call(command, cwd):
try:
subprocess.check_call(command, cwd=cwd)
except OSError as ex:
if ex.errno == ENOENT:
ex.strerror = "{0} not found, please make sure {0} is in PATH".format(command[0])
raise ex
class build_clib_with_qmake(build_clib):
def build_libraries(self, libraries):
clib_not_qmake = []
for (lib_name, build_info) in libraries:
if build_info['qmake']:
log.info("building '%s' library", lib_name)
# init
try_initialize_compiler(self.compiler)
makedirs(self.build_temp)
# qmake
sources = os.path.abspath(build_info['sources'][0])
check_call(["qmake", sources], cwd=self.build_temp)
# make
make = "nmake" if self.compiler.compiler_type == 'msvc' else "make" # FIXME
check_call([make], cwd=self.build_temp)
else:
clib_not_qmake.append((lib_name, build_info))
build_clib.build_libraries(self, clib_not_qmake)
class build_ext_with_sip(build_ext):
def build_extensions(self):
build_ext.build_extensions(self)
# copy libs to ext dir
pyqt = 'PyQt%s' % os.environ.get('QT_SELECT', '5')
ext_dir = os.path.join(os.path.dirname(self.get_ext_fullpath('_')), pyqt)
makedirs(ext_dir)
for filename in os.listdir(self.build_temp):
if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS:
shutil.copy(os.path.join(self.build_temp, filename), ext_dir)
def build_extension(self, ext):
if ext.language == 'sip':
log.info("building '%s' extension", ext.name)
# init
try_initialize_compiler(self.compiler)
makedirs(self.build_temp)
# configure
config = os.path.abspath(ext.sources[0])
check_call([sys.executable, config], cwd=self.build_temp)
# make
make = "nmake" if self.compiler.compiler_type == 'msvc' else "make" # FIXME
check_call([make], cwd=self.build_temp)
else:
build_ext.build_libraries(self, ext)
with codecs.open("README.rst", encoding="utf-8") as f:
long_description = f.read()
setup(
name="PyQxtGlobalShortcut",
version="0.2.3",
description="Python bindings to libqxt's QxtGlobalShortcut",
long_description=long_description,
url="https://github.com/frispete/PyQxtGlobalShortcut",
author="Hans-Peter Jansen",
author_email="[email protected]",
license="GPLv3",
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications :: Qt",
"Intended Audience :: Developers",
"Topic :: Desktop Environment",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: User Interfaces",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.1",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
],
keywords="shortcut hotkey QxtGlobalShortcut libqxt pyqt qt",
ext_modules=[
Extension(
name=pyqxtgs,
sources=["pyqxtgs/configure.py"],
language="sip",
),
],
libraries=[
("QxtGlobalShortcut", {
'sources': ['lib/qxtglobalshortcut.pro'],
'qmake': True,
}),
],
cmdclass={
'build_clib': build_clib_with_qmake,
'build_ext': build_ext_with_sip,
}
)