-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
366 lines (341 loc) · 12.4 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2023-05-09
:License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007.
"""
import argparse
import os
import sys
from setuptools import Command, setup
class TestWithPytest(Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2023-05-09
:License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007.
running automatic tests with pytest
"""
description = "running automatic tests with pytest"
user_options = [
('src=',
None,
'Choose what should be tested; installed: ' +
'test installed package and scripts (default); ' +
'local: test package direct from sources ' +
'(installing is not necessary). ' +
'The command line scripts are not tested for local. ' +
'default: installed'),
('coverage', None, 'use pytest-cov to generate a coverage report'),
('pylint', None, 'if given, run pylint'),
('pytestverbose', None, 'increase verbosity of pytest'),
('parallel', None, 'run tests in parallel')]
def initialize_options(self):
"""
:Author: Daniel Mohr
:Date: 2021-02-18
"""
# pylint: disable=attribute-defined-outside-init
self.src = 'installed'
self.coverage = False
self.pylint = False
self.pytestverbose = False
self.parallel = False
def finalize_options(self):
"""
:Author: Daniel Mohr
:Date: 2021-02-04
"""
def run(self):
"""
:Author: Daniel Mohr
:Date: 2023-05-09
"""
# pylint: disable=too-many-branches
if self.src == 'installed':
pass
elif self.src == 'local':
sys.path.insert(0, os.path.abspath('src'))
else:
raise argparse.ArgumentTypeError(
"error in command line: " +
"value for option 'src' is not 'installed' or 'local'")
sys.path.append(os.path.abspath('.'))
# https://docs.pytest.org/en/stable/contents.html
# https://pytest-cov.readthedocs.io/en/latest/
# pylint: disable=bad-option-value,import-outside-toplevel
import pytest
pyargs = []
if self.parallel:
try:
# if available, using parallel test run
# pylint: disable=unused-variable,unused-import
import xdist
if os.name == 'posix':
# since we are only running seconds,
# we use the load of the last minute:
nthreads = int(os.cpu_count() - os.getloadavg()[0])
# since we have only a few tests, limit overhead:
nthreads = min(4, nthreads)
nthreads = max(2, nthreads) # at least two threads
else:
nthreads = max(2, int(0.5 * os.cpu_count()))
pyargs += [f'-n {nthreads}']
except (ModuleNotFoundError, ImportError):
pass
if self.coverage:
coverage_dir = 'coverage_report/'
# first we need to clean the target directory
if os.path.isdir(coverage_dir):
files = os.listdir(coverage_dir)
for filename in files:
os.remove(os.path.join(coverage_dir, filename))
pyargs += ['--cov=dabu', '--no-cov-on-fail',
'--cov-report=html:' + coverage_dir,
'--cov-report=term:skip-covered']
if self.pylint:
pyargs += ['--pylint']
if self.pytestverbose:
pyargs += ['--verbose']
if self.src == 'installed':
pyargs += ['tests/main.py']
pyargs += ['tests/package_data.py']
pyargs += [
'tests/dabu_scripts_pydabu_check_arg_file_not_exists.py'
]
pyargs += ['tests/compare_json_schemas.py']
pyargs += ['tests/schema_org_data.py']
if self.src == 'installed':
pyargs += ['tests/script_pydabu.py']
pyargs += \
['tests/script_json_schema_from_schema_org.py']
pyplugins = []
print('call: pytest', ' '.join(pyargs))
sys.exit(pytest.main(pyargs, pyplugins))
class TestWithUnittest(Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2023-05-09
:License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007.
running automatic tests with unittest
"""
description = "running automatic tests with unittest"
user_options = [
("src=",
None,
'Choose what should be tested; installed: ' +
'test installed package and scripts (default); ' +
'local: test package direct from sources ' +
'(installing is not necessary). ' +
'The command line scripts are not tested for local. ' +
'default: installed')]
def initialize_options(self):
"""
:Author: Daniel Mohr
:Date: 2021-02-04
"""
# pylint: disable=attribute-defined-outside-init
self.src = 'installed'
def finalize_options(self):
"""
:Author: Daniel Mohr
:Date: 2021-02-04
"""
def run(self):
"""
:Author: Daniel Mohr
:Date: 2023-05-09
"""
if self.src == 'installed':
pass
elif self.src == 'local':
sys.path.insert(0, os.path.abspath('src'))
else:
raise argparse.ArgumentTypeError(
"error in command line: " +
"value for option 'src' is not 'installed' or 'local'")
sys.path.append(os.path.abspath('.'))
# pylint: disable=bad-option-value,import-outside-toplevel
import unittest
suite = unittest.TestSuite()
import tests
tests.module(suite)
setup_self = self
class TestRequiredModuleImport(unittest.TestCase):
# pylint: disable=missing-docstring
# pylint: disable=no-self-use
def test_required_module_import(self):
import importlib
for module in setup_self.distribution.metadata.get_requires():
importlib.import_module(module)
loader = unittest.defaultTestLoader
suite.addTest(loader.loadTestsFromTestCase(
TestRequiredModuleImport))
if self.src == 'installed':
tests.scripts(suite)
if unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful():
sys.exit(0)
else:
sys.exit(1)
res = unittest.TextTestRunner(verbosity=2).run(suite)
if res.wasSuccessful():
sys.exit(0)
else:
sys.exit(1)
class CheckModules(Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2017-01-08, 2022-07-01, 2023-05-09
:License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007.
checking for modules need to run the software
"""
description = "checking for modules need to run the software"
user_options = []
def initialize_options(self):
"""
:Author: Daniel Mohr
:Date: 2017-01-08
"""
def finalize_options(self):
"""
:Author: Daniel Mohr
:Date: 2017-01-08
"""
def run(self):
"""
:Author: Daniel Mohr
:Date: 2017-01-08, 2022-07-01, 2023-05-09
"""
# pylint: disable=bad-option-value,import-outside-toplevel
import importlib
summary = ""
i = 0
print("checking for modules need to run the software (scripts and")
print("modules/packages) of this package:\n")
print("checking for the modules mentioned in the 'setup.py':")
for module in self.distribution.metadata.get_requires():
if self.verbose:
print("try to load %s" % module)
try:
importlib.import_module(module)
if self.verbose:
print(" loaded.")
except ImportError:
i += 1
summary += f"module '{module}' is not available\n"
print(f"module '{module}' is not available <---WARNING---")
print(f"\nSummary\n{i} modules are not available (not unique)\n" +
f"{summary}\n")
if i > 0:
sys.exit(1)
else:
sys.exit(0)
# necessary modules
REQUIRED_MODULES = ['argparse',
'base64',
'datetime',
'getpass',
'hashlib',
'json',
'jsonschema',
'logging',
'os',
'os.path',
'pkgutil',
're',
'setuptools',
'subprocess',
'sys',
'tempfile',
'time',
'types',
'warnings']
# optional modules
REQUIRED_MODULES += ['cfchecker.cfchecks', 'netCDF4']
# optional modules to return version from module read from package metadata
REQUIRED_MODULES += ['pkg_resources']
# optional modules for python3 setup.py check_modules
REQUIRED_MODULES += ['importlib']
# optional modules for json_schema_from_schema_org
# REQUIRED_MODULES += ['bz2', 'gzip', 'lzma', 'ssl', 'urllib.request']
# modules to build doc
# REQUIRED_MODULES += ['sphinx', 'sphinxarg', 'recommonmark']
# modules to run tests with unittest
# REQUIRED_MODULES += ['unittest', 'shutil']
# modules to run tests with pytest
# REQUIRED_MODULES += ['pytest']
# optional modules to run tests with pytest in parallel
# REQUIRED_MODULES += ['xdist']
# optional modules to run tests with pytest and create coverage report
# REQUIRED_MODULES += ['pytest_cov']
LONG_DESCRIPTION_FILENAME = 'README.md'
if os.path.isfile('README.rst'):
LONG_DESCRIPTION_FILENAME = 'README.rst'
with open(LONG_DESCRIPTION_FILENAME) as file:
LONG_DESCRIPTION = file.read()
setup(
name='pydabu',
version='2023.05.09',
cmdclass={
'check_modules': CheckModules,
'run_unittest': TestWithUnittest,
'run_pytest': TestWithPytest},
description='software to check a data bubble.',
long_description=LONG_DESCRIPTION,
keywords=['data managment', 'metadata', 'data management plan'],
author='Daniel Mohr',
author_email='[email protected]',
maintainer='Daniel Mohr',
maintainer_email='[email protected]',
url='https://dlr-pa.gitlab.io/pydabu/',
download_url='https://gitlab.com/dlr-pa/pydabu',
package_dir={'': 'src'},
packages=[
'dabu',
'dabu.analyse_data_structure',
'dabu.check_nasa_ames_format',
'dabu.check_netcdf_file',
'dabu.compare_json_schemas',
'dabu.analyse_file_format',
'dabu.schema_org_data',
'dabu.scripts',
'dabu.scripts.pydabu',
'dabu.scripts.json_schema_from_schema_org'],
entry_points={
'console_scripts':
['pydabu=dabu.scripts.pydabu.pydabu_main:pydabu_main',
'json_schema_from_schema_org='
'dabu.scripts.json_schema_from_schema_org.'
'json_schema_from_schema_org_main:'
'json_schema_from_schema_org_main'],
},
package_data={'dabu': ['schemas/analyse_data_structure_output.schema',
'schemas/dabu.schema',
'schemas/dabu_requires.schema']},
license='GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007',
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Science/Research',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: '
'GNU General Public License v3 or later (GPLv3+)',
'Natural Language :: English',
'Operating System :: POSIX',
'Operating System :: POSIX :: BSD :: FreeBSD',
'Operating System :: POSIX :: BSD :: OpenBSD',
'Operating System :: POSIX :: Linux',
'Operating System :: Unix',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: System :: Archiving'],
# cat $(find | grep "py$") | egrep -i "^[ \t]*import .*$" | \
# egrep -i --only-matching "import .*$" | sort -u
requires=REQUIRED_MODULES,
provides=['dabu']
)