forked from Varbin/xtea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
131 lines (109 loc) · 3.82 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
from __future__ import with_statement # Reading README
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
from distutils.errors import (
CCompilerError,
DistutilsExecError,
DistutilsPlatformError
)
import re
import platform
import sys
import traceback
EXCLUDE_EXTENSION_FLAG = '--exclude-extension'
BUILD_EXTENSION = not any((
platform.python_implementation() != "CPython",
sys.version_info[0] < 3,
(sys.platform == 'win32'
and sys.version_info[0] == 3
and sys.version_info[1] == 4),
'test' in sys.argv[1:],
'develop' in sys.argv[1:],
EXCLUDE_EXTENSION_FLAG in sys.argv
))
if EXCLUDE_EXTENSION_FLAG in sys.argv:
sys.argv.pop(sys.argv.index(EXCLUDE_EXTENSION_FLAG))
def get_file(name):
try:
with open(name) as f:
return f.read()
except IOError: # OSError on Py3
return ''
META_FILE = get_file("xtea/__init__.py")
def find_meta(meta):
"""
Extract __*meta*__ from META_FILE.
Source: https://github.com/python-attrs/attrs/blob/master/setup.py#L73
"""
meta_match = re.search(
r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M
)
if meta_match:
return meta_match.group(1)
raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))
long_text = get_file("README.rst") + "\n\n" + get_file("changelog.rst")
kwargs = dict(
name='xtea',
version=find_meta("version"),
description="A python version of XTEA",
long_description=long_text,
author=find_meta("author"),
author_email=find_meta("email"),
url="https://github.com/Varbin/xtea/wiki",
download_url="https://github.com/Varbin/xtea",
bugtrack_url="https://github.com/Varbin/xtea/issues",
keywords="xtea tea encryption cryptography",
license=find_meta("license"),
packages=["xtea"],
classifiers=[
"Development Status :: 4 - Beta",
"License :: Public Domain",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Security",
"Topic :: Security :: Cryptography"
],
setup_requires=['pytest-runner'],
tests_require=['pytest'],
install_requires=['pep272-encryption>=0.3'],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*'
)
if BUILD_EXTENSION:
n_args = kwargs.copy()
n_args["ext_modules"] = [
Extension('_xtea',
sources=['xtea.c'],
optional=True,
py_limited_api=True)
]
try:
setup(**n_args)
except CCompilerError:
sys.stderr.write("Could not install extension module - "
"is your C compiler working correctly?\n")
except DistutilsPlatformError:
sys.stderr.write("Could not install extension module - "
"platform error?\n")
except DistutilsExecError:
sys.stderr.write("Could not install extension module - "
"is a C compiler installed?\n")
except Exception as e: # noqa
sys.stderr.write("Could not install with extension module, "
"but this might not be the cause.\n")
sys.stderr.write("This is the error:\n")
traceback.print_exc()
else:
sys.exit(0)
setup(**kwargs)