forked from LudovicRousseau/pyscard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·198 lines (167 loc) · 7.35 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#! /usr/bin/env python
"""Setup file for distutils
__author__ = "http://www.gemalto.com"
Copyright 2001-2012 gemalto
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
This file is part of pyscard.
pyscard is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
pyscard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""
from distutils.util import get_platform
import distutils.command.install as install_orig
import inspect
import sys
from setuptools import setup, Extension
from setuptools.command.bdist_egg import bdist_egg
from setuptools.command.install import install
if sys.version_info[0:2] < (2, 6):
raise RuntimeError("pyscard requires Python 2.6+ to build.")
if get_platform() in ('win32', 'win-amd64'):
platform__cc_defines = [('WIN32', '100')]
platform_swig_opts = ['-DWIN32']
platform_sources = ['smartcard/scard/scard.rc']
platform_libraries = ['winscard']
platform_include_dirs = []
platform_extra_compile_args = []
platform_extra_link_args = []
elif 'cygwin-' in get_platform():
platform__cc_defines = [('WIN32', '100')]
platform_swig_opts = ['-DWIN32']
platform_sources = []
platform_libraries = ['winscard']
platform_include_dirs = []
platform_extra_compile_args = []
platform_extra_link_args = []
elif 'macosx-10.' in get_platform():
if 'macosx-10.6' in get_platform():
macosx_define = '__LEOPARD__' # Snow Leopard, Python 2.6
else:
macosx_define = '__LION__' # Lion (and above), Python 2.7
platform__cc_defines = [('PCSCLITE', '1'),
('__APPLE__', '1'),
(macosx_define, '1')]
platform_swig_opts = ['-DPCSCLITE', '-D__APPLE__', '-D' + macosx_define]
platform_sources = []
platform_libraries = []
platform_include_dirs = []
platform_extra_compile_args = ['-v', '-arch', 'i386',
'-arch', 'x86_64', '-ggdb']
platform_extra_link_args = ['-arch', 'i386', '-arch', 'x86_64', '-ggdb']
# Other (GNU/Linux, etc.)
#
else:
platform__cc_defines = [('PCSCLITE', '1')]
platform_swig_opts = ['-DPCSCLITE']
platform_sources = []
platform_libraries = []
platform_include_dirs = ['/usr/include/PCSC']
platform_extra_compile_args = [] # ['-ggdb', '-O0']
platform_extra_link_args = [] # ['-ggdb']
VERSION_INFO = (1, 9, 3, 0)
VERSION_STR = '%i.%i.%i' % VERSION_INFO[:3]
VERSION_ALT = '%i,%01i,%01i,%04i' % VERSION_INFO
# Workaround for `pip install` and direct `setup.py install`
class InstallBuildExtFirst(install):
"""Workaround substitute `install` command"""
def run(self):
# Run built_ext first so that SWIG generated files are included
self.run_command("build_ext")
# Copy the rest of the logic from setuptools install so that the
# stack frame logic is preserved
# Explicit request for old-style install? Just do it
if self.old_and_unmanageable or self.single_version_externally_managed:
return install_orig.install.run(self)
try:
have_called_from_setup = self._called_from_setup is not None
except AttributeError:
have_called_from_setup = False
if not have_called_from_setup or not self._called_from_setup(inspect.currentframe()):
# Run in backward-compatibility mode to support bdist_* commands.
install_orig.install.run(self)
else:
self.do_egg_install()
# Workaround for `easy_install`
class BdistEggBuildExtFirst(bdist_egg):
"""Workaround substitute `bdist_egg` command"""
def run(self):
# Run build_ext first so that SWIG generated files are included
self.run_command("build_ext")
return bdist_egg.run(self)
kw = {'name': "pyscard",
'version': VERSION_STR,
'description': "Smartcard module for Python.",
'author': "Jean-Daniel Aussel",
'author_email': "aussel.jean-daniel@gemalto.com",
'url': "http://www.gemalto.com",
'long_description': 'Smartcard package for Python',
'license': 'GNU LESSER GENERAL PUBLIC LICENSE',
'platforms': ['linux', 'win32'],
'packages': ["smartcard",
"smartcard.pcsc",
"smartcard.pyro",
"smartcard.reader",
"smartcard.scard",
"smartcard.sw",
"smartcard.util",
"smartcard.wx",
],
'package_dir': {"": "."},
'package_data': {
"smartcard/wx": ["resources/*.ico"],
},
'cmdclass': {
'install': InstallBuildExtFirst,
'bdist_egg': BdistEggBuildExtFirst,
},
# the _scard.pyd extension to build
'ext_modules': [Extension("smartcard.scard._scard",
define_macros=[
('VER_PRODUCTVERSION', VERSION_ALT),
('VER_PRODUCTVERSION_STR', VERSION_STR)]
+ platform__cc_defines,
include_dirs=['smartcard/scard/'] \
+ platform_include_dirs,
sources=["smartcard/scard/helpers.c",
"smartcard/scard/winscarddll.c",
"smartcard/scard/scard.i"] \
+ platform_sources,
libraries=platform_libraries,
extra_compile_args=platform_extra_compile_args,
extra_link_args=platform_extra_link_args,
swig_opts=['-outdir',
'smartcard/scard'] \
+ platform_swig_opts)],
'extras_require': {
'Gui': ['wxPython'],
'Pyro': ['Pyro'],
},
'test_suite': 'test',
'classifiers': [
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: GNU Lesser General Public License v2 '
'or later (LGPLv2+)',
'Intended Audience :: Developers',
'Operating System :: Unix',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Security ',
]
}
# FIXME Sourceforge downloads are unauthenticated, migrate to PyPI
kw['download_url'] = ('http://sourceforge.net/projects/%(name)s/files'
'/%(name)s/%(name)s%%20%(version)s'
'/%(name)s-%(version)s.tar.gz/download' % kw)
setup(**kw)