-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
382 lines (352 loc) · 13.2 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2023-04-20
:License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.
"""
import os
import sys
import setuptools
class TestWithPytest(setuptools.Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2021-06-25, 2023-03-31, 2023-04-19
:License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.
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: 2021-06-25, 2023-03-31, 2023-04-19
"""
# pylint: disable=too-many-branches
# env python3 setup.py run_pytest
if self.src == 'installed':
pass
elif self.src == 'local':
sys.path.insert(0, os.path.abspath('src'))
else:
raise Exception(
"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:
# env python3 setup.py run_pytest --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=py_fuse_git_bare_fs', '--no-cov-on-fail',
'--cov-report=html:' + coverage_dir,
'--cov-report=term:skip-covered']
if self.pylint:
pyargs += ['--pylint']
if self.pytestverbose:
pyargs += ['--verbose']
pyargs += ['tests/py_fuse_git_bare_fs_repo_class.py']
pyargs += ['tests/py_fuse_git_bare_fs_repotools_dulwich.py']
pyargs += ['tests/py_fuse_git_bare_fs_repotools_git.py']
if self.src == 'installed':
pyargs += ['tests/script_fuse_git_bare_fs_repo.py']
pyargs += ['tests/script_fuse_git_bare_fs_tree.py']
pyargs += ['tests/script_fuse_git_bare_fs_tree_gitolite.py']
pyargs += ['tests/script_fuse_git_bare_fs_tree_annex.py']
pyargs += ['tests/main.py']
pyplugins = []
print('call: pytest', ' '.join(pyargs))
sys.exit(pytest.main(pyargs, pyplugins))
class TestWithUnittest(setuptools.Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2021-06-25, 2023-04-19, 2023-04-20
:License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.
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: 2021-06-25, 2023-04-19, 2023-04-20
"""
# env python3 setup.py run_unittest
if self.src == 'installed':
pass
elif self.src == 'local':
sys.path.insert(0, os.path.abspath('src'))
else:
raise Exception(
"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():
if module in ['fuse', 'fusepy']:
try:
importlib.import_module('fusepy')
except ModuleNotFoundError:
# pylint: disable=import-error,unused-variable
# pylint: disable=unused-variable,unused-import
import fuse as fusepy
else:
importlib.import_module(module)
loader = unittest.defaultTestLoader
suite.addTest(loader.loadTestsFromTestCase(
TestRequiredModuleImport))
if self.src == 'installed':
tests.scripts(suite)
status = unittest.TextTestRunner(verbosity=2).run(suite)
if status.wasSuccessful():
sys.exit(0)
else:
sys.exit(1)
class CheckModules(setuptools.Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2017-01-08, 2023-03-31
:License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.
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, 2023-03-31, 2023-04-20
"""
# 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(f"try to load {module}")
try:
importlib.import_module(module)
if self.verbose:
print(" loaded.")
except ImportError:
fuse_or_fusepy = set(['fuse', 'fusepy'])
if module in ['fuse', 'fusepy']:
fuse_or_fusepy = set(['fuse', 'fusepy'])
fuse_or_fusepy.remove(module)
alternative_module = fuse_or_fusepy.pop()
if self.verbose:
print(f"try to load alternative {alternative_module}")
try:
importlib.import_module(alternative_module)
if self.verbose:
print(" loaded.")
continue
except ImportError:
pass
i += 1
summary += f"module '{module}' is not available\n"
sys.exit(f"module '{module}' is not available <---WARNING---")
print(f"\nSummary\n{i} modules are not available (not unique)\n" +
f"{summary}\n")
sys.exit(0)
class CheckModulesModulefinder(setuptools.Command):
"""
:Author: Daniel Mohr
:Email: [email protected]
:Date: 2017-01-08, 2023-03-31
:License: GNU GENERAL PUBLIC LICENSE, Version 2, June 1991.
checking for modules need to run the scripts (modulefinder)
"""
description = "checking for modules need to run the scripts (modulefinder)"
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, 2023-03-31
"""
# pylint: disable=bad-option-value,import-outside-toplevel
import modulefinder
for script in self.distribution.scripts:
print(f"\nchecking for modules used in '{script}':")
finder = modulefinder.ModuleFinder()
finder.run_script(script)
finder.report()
# necessary modules
REQUIRED_MODULES = ['argparse',
'errno',
'fuse',
'fusepy',
'grp',
'hashlib',
'logging',
'os',
'os.path',
'pwd',
're',
'setuptools',
'subprocess',
'sys',
'threading',
'time',
'warnings']
# optional modules for python3 setup.py check_modules
REQUIRED_MODULES += ['importlib']
# optional modules for python3 setup.py check_modules_modulefinder
REQUIRED_MODULES += ['modulefinder']
# modules to build doc
# REQUIRED_MODULES += ['sphinx', 'sphinxarg', 'recommonmark']
# modules to run tests with unittest
REQUIRED_MODULES += ['shutil', 'tempfile', 'unittest']
# modules to run tests with pytest
REQUIRED_MODULES += ['pytest']
# optional modules to run tests with pytest in parallel
REQUIRED_MODULES += ['xdist']
# optional modules to use the python module dulwich instead of the
# command line tool git, which is used via shell and subprocess and
# the starting process is therefore slow:
# REQUIRED_MODULES += ['dulwich']
setuptools.setup(
name='fuse_git_bare_fs',
version='2023.04.20',
cmdclass={
'check_modules': CheckModules,
'check_modules_modulefinder': CheckModulesModulefinder,
'run_unittest': TestWithUnittest,
'run_pytest': TestWithPytest},
description='Tool to mount the working tree '
'of a git bare repository as a filesystem in user space (fuse).',
long_description='',
keywords='mount fuse git bare repository working tree',
author='Daniel Mohr',
author_email='[email protected]',
maintainer='Daniel Mohr',
maintainer_email='[email protected]',
url='https://dlr-pa.github.io/fuse_git_bare_fs/',
download_url='https://github.com/dlr-pa/fuse_git_bare_fs',
package_dir={'': 'src'},
packages=['py_fuse_git_bare_fs'],
scripts=['src/scripts/fuse_git_bare_fs'],
license='GNU GENERAL PUBLIC LICENSE, Version 2, June 1991',
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'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',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: System :: Filesystems'],
requires=REQUIRED_MODULES
)