-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup.py
executable file
·187 lines (162 loc) · 6.59 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
"""Datatest: Test driven data-wrangling and data validation."""
import ast
import optparse
import os
import subprocess
import sys
import warnings
try:
from setuptools import setup
from setuptools import Command
except ImportError:
from distutils.core import setup
from distutils.core import Command
WORKING_DIR = os.path.dirname(os.path.abspath(__file__))
class TestCommand(Command):
"""Implement 'setup.py test' command."""
user_options = [
('verbose', 'v', 'Verbose testing output'),
('failfast', 'f', 'Stop testing on first fail or error'),
]
boolean_options = ['verbose', 'failfast']
description = 'run test suite'
def initialize_options(self):
self.verbose = None
self.failfast = None
def finalize_options(self):
cmd_args = sys.argv # Since "verbose" is
cmd_args = cmd_args[cmd_args.index('test'):] # also a global option
# for setup.py, we need
parser = optparse.OptionParser() # to parse only args
parser.add_option( # after the command.
'--verbose', '-v', action='store_true', default=False)
opts, _ = parser.parse_args(cmd_args)
self.verbose = opts.verbose
if self.failfast is None:
self.failfast = False
elif sys.version_info[:2] in [(2, 6), (3, 1)]:
msg = 'failfast option not supported in this version of Python'
warnings.warn(msg)
self.failfast = False
def run(self):
# Print "skipping" notice if missing optional packages.
missing_optionals = self._get_missing_optionals()
if missing_optionals:
msg = 'optionals not installed: {0}\nskipping some tests'
print(msg.format(', '.join(missing_optionals)))
# Prepare test command.
if sys.version_info[:2] in [(2, 6), (3, 1)]:
args = [sys.executable, '-B', '-O', '-W default',
'tests/discover.py', '-t', WORKING_DIR, '-s' ,'tests']
else:
args = [sys.executable, '-B', '-O', '-W default', '-m', 'unittest',
'discover', '-t', WORKING_DIR, '-s', 'tests']
if self.verbose:
args.append('--verbose')
if self.failfast:
args.append('--failfast')
# Run tests.
sys.exit(subprocess.call(args))
def _get_missing_optionals(self):
# Returns a list of missing optional packages.
optional_packages = [
'dbfread',
'numpy',
'pandas',
'squint',
'xlrd', # <- support for MS Excel files
]
missing_optionals = []
for package in optional_packages:
try:
__import__(package)
except ImportError:
missing_optionals.append(package)
return missing_optionals
class RestrictedCommand(Command):
"""Dummy command to restrict setup.py actions."""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
raise Exception('This command is currently restricted.')
def get_version(filepath):
"""Return value of file's __version__ attribute."""
fullpath = os.path.join(WORKING_DIR, filepath)
with open(fullpath) as fh:
for line in fh:
line = line.strip()
if line.startswith('__version__'):
return ast.parse(line).body[0].value.s
raise Exception('Unable to find __version__ attribute.')
if __name__ == '__main__':
original_dir = os.path.abspath(os.getcwd())
try:
os.chdir(WORKING_DIR)
with open('README.rst') as file:
long_description = file.read()
setup(
# Required meta-data:
name='datatest',
version=get_version('datatest/__init__.py'),
url='https://github.com/shawnbrown/datatest', # Homepage link.
packages=[
'datatest',
'datatest.__past__',
'datatest.__past__.squint',
'datatest._compatibility',
'datatest._compatibility.collections',
'datatest._vendor',
],
# Additional fields:
install_requires=[], # <- No hard requirements!
keywords='data wrangling testing validation',
project_urls={
'Documentation': 'https://datatest.readthedocs.io/',
},
python_requires='>=2.6, !=3.0.*, !=3.1.*',
description='Test driven data-wrangling and data validation.',
long_description=long_description,
long_description_content_type='text/x-rst',
author='Shawn Brown',
license='Apache 2.0',
classifiers = [
'Topic :: Software Development :: Quality Assurance',
'Topic :: Software Development :: Testing',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Development Status :: 4 - Beta',
'Framework :: Pytest',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'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',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
entry_points={
'pytest11': [
'datatest = datatest._pytest_plugin',
],
},
cmdclass={
'test': TestCommand,
# Restrict setup commands (use twine instead):
'register': RestrictedCommand, # Use: twine register dist/*
'upload': RestrictedCommand, # Use: twine upload dist/*
'upload_docs': RestrictedCommand,
},
)
finally:
os.chdir(original_dir)