-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsetup.py
executable file
·154 lines (124 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
148
149
150
151
152
153
154
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Name: Yubico Python Client
# Description: Python class for verifying Yubico One Time Passwords (OTPs).
#
# Author: Tomaz Muraus (http://www.tomaz.me)
# License: BSD
#
# Copyright (c) 2010-2019, Tomaž Muraus
# Copyright (c) 2012, Yubico AB
# All rights reserved.
import os
import re
import sys
import logging
from glob import glob
from os.path import splitext, basename, join as pjoin
from unittest import TextTestRunner, TestLoader
from distutils.core import Command
from setuptools import setup
sys.path.insert(0, pjoin(os.path.dirname(__file__)))
TEST_PATHS = ['tests']
version_re = re.compile(
r'__version__ = (\(.*?\))')
cwd = os.path.dirname(os.path.abspath(__file__))
version = None
with open(os.path.join(cwd, 'yubico_client', '__init__.py')) as fp:
for line in fp:
match = version_re.search(line)
if match:
version = eval(match.group(1)) # pylint: disable=eval-used
break
if not version:
raise Exception('Cannot find version in __init__.py')
class TestCommand(Command):
description = 'run test suite'
user_options = []
log_paths = []
# Set to False to preserve mock server log files even if the tests succeed
delete_mock_server_logs_on_success = True
def initialize_options(self):
FORMAT = '%(asctime)-15s [%(levelname)s] %(message)s'
logging.basicConfig(format=FORMAT)
THIS_DIR = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, THIS_DIR)
for test_path in TEST_PATHS:
sys.path.insert(0, pjoin(THIS_DIR, test_path))
self._dir = os.getcwd()
def finalize_options(self):
pass
def run(self):
self._run_mock_api_server()
succeeded = self._run_tests()
status_code = 0 if succeeded else 1
if succeeded and self.delete_mock_server_logs_on_success:
# On success we delete mock server log files
for file_path in self.log_paths:
if not os.path.isfile(file_path):
continue
os.unlink(file_path)
sys.exit(status_code)
def _run_tests(self):
testfiles = []
for test_path in TEST_PATHS:
for t in glob(pjoin(self._dir, test_path, 'test_*.py')):
testfiles.append('.'.join(
[test_path.replace('/', '.'), splitext(basename(t))[0]]))
tests = TestLoader().loadTestsFromNames(testfiles)
t = TextTestRunner(verbosity=2)
res = t.run(tests)
return res.wasSuccessful()
def _run_mock_api_server(self):
# pylint: disable=import-outside-toplevel
from test_utils.process_runners import TCPProcessRunner
script = pjoin(os.path.dirname(__file__), 'tests/mock_http_server.py')
for port in [8881, 8882, 8883]:
args = [script, '--port=%s' % (port)]
log_path = 'mock_api_server_%s.log' % (port)
wait_for_address = ('127.0.0.1', port)
server = TCPProcessRunner(args=args,
wait_for_address=wait_for_address,
log_path=log_path)
server.setUp()
self.log_paths.append(log_path)
with open('CHANGES.rst') as fp:
CHANGELOG = fp.read()
setup(
name='yubico-client',
version='.' . join(map(str, version)),
description='Library for verifying Yubikey One Time Passwords (OTPs)',
long_description=open('README.rst').read() + '\n\n' + CHANGELOG,
author='Tomaz Muraus',
author_email='[email protected]',
license='BSD',
url='https://github.com/Kami/python-yubico-client/',
download_url='https://github.com/Kami/python-yubico-client/releases',
packages=['yubico_client'],
provides=['yubico_client'],
install_requires=[
'requests>=2.7,<3.0',
],
cmdclass={
'test': TestCommand,
},
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'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 :: PyPy',
'Topic :: Security',
'Topic :: Software Development :: Libraries :: Python Modules',
]
)