forked from enthought/comtypes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
147 lines (127 loc) · 4.69 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
"comtypes package install script"
import sys
import os
import ctypes
from distutils.core import Command
from setuptools import setup
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
from distutils.command.build_py import build_py
with open('README') as readme_stream:
readme = readme_stream.read()
class test(Command):
# Original version of this class posted
# by Berthold Hoellmann to [email protected]
description = "run tests"
user_options = [
('tests=', 't',
"comma-separated list of packages that contain test modules"),
('use-resources=', 'u',
"resources to use - resource names are defined by tests"),
('refcounts', 'r',
"repeat tests to search for refcount leaks (requires 'sys.gettotalrefcount')"),
]
boolean_options = ["refcounts"]
def initialize_options(self):
self.use_resources = ""
self.refcounts = False
self.tests = "comtypes.test"
self.failure = False
def finalize_options(self):
if self.refcounts and not hasattr(sys, "gettotalrefcount"):
raise Exception("refcount option requires Python debug build")
self.tests = self.tests.split(",")
self.use_resources = self.use_resources.split(",")
def run(self):
build = self.reinitialize_command('build')
build.run()
if build.build_lib is not None:
sys.path.insert(0, build.build_lib)
# Register our ATL COM tester dll
import comtypes.test
script_path = os.path.dirname(__file__)
source_dir = os.path.abspath(os.path.join(script_path, "source"))
comtypes.test.register_server(source_dir)
comtypes.test.use_resources.extend(self.use_resources)
for name in self.tests:
package = __import__(name, globals(), locals(), ['*'])
sys.stdout.write("Testing package %s %s\n"
% (name, (sys.version, sys.platform, os.name)))
package_failure = comtypes.test.run_tests(package,
"test_*.py",
self.verbose,
self.refcounts)
self.failure = self.failure or package_failure
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: Microsoft :: Windows',
'Operating System :: Microsoft :: Windows :: Windows CE',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries :: Python Modules',
]
def read_version():
# Determine the version number by reading it from the file
# 'comtypes\__init__.py'. We cannot import this file (with py3,
# at least) because it is in py2.x syntax.
ns = {}
for line in open("comtypes/__init__.py"):
if line.startswith("__version__ = "):
exec(line, ns)
break
return ns["__version__"]
if sys.version_info >= (3, 0):
# install_script does not work in Python 3 (python bug)
# Another distutils bug: it doesn't accept an empty options dict
options = {"foo": {}}
## options = {}
else:
options={"bdist_wininst": {"install_script": "clear_comtypes_cache.py"}}
setup_params = dict(
name="comtypes",
description="Pure Python COM package",
long_description = readme,
author="Thomas Heller",
author_email="[email protected]",
url="http://starship.python.net/crew/theller/comtypes",
download_url="https://github.com/enthought/comtypes/releases",
license="MIT License",
package_data={
"comtypes.test": [
"TestComServer.idl",
"TestComServer.tlb",
"TestDispServer.idl",
"TestDispServer.tlb",
"mytypelib.idl",
"mylib.idl",
"mylib.tlb"
"urlhist.tlb",
"test_jscript.js",
]},
classifiers=classifiers,
scripts=["clear_comtypes_cache.py"],
options=options,
cmdclass={
'test': test,
'build_py': build_py,
},
version=read_version(),
packages=[
"comtypes",
"comtypes.client",
"comtypes.server",
"comtypes.tools",
"comtypes.test",
],
)
if __name__ == '__main__':
dist = setup(**setup_params)
# Exit with a failure code if only running the tests and they failed
if dist.commands == ['test']:
command = dist.command_obj['test']
sys.exit(command.failure)