-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
executable file
·122 lines (110 loc) · 3.98 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
#!/usr/bin/env python
"""
Standard python setup.py file for MLaaS4HEP
"""
import os
import sys
import fnmatch
import subprocess
from distutils.core import setup, Command
class TestCommand(Command):
"Class to implement test actions"
user_options = []
def run(self):
pass
def initialize_options(self):
pass
def finalize_options(self):
pass
def datafiles(dir, pattern=None):
"""Return list of data files in provided relative dir"""
files = []
for dirname, dirnames, filenames in os.walk(dir):
for subdirname in dirnames:
files.append(os.path.join(dirname, subdirname))
for filename in filenames:
if filename[-1] == '~':
continue
# match file name pattern (e.g. *.css) if one given
if pattern and not fnmatch.fnmatch(filename, pattern):
continue
files.append(os.path.join(dirname, filename))
return files
def main():
"Main setup"
# this try/except block is taking care of setting up proper
# version either by reading it from MLaaS4HEP package
# this part is used by pip to get the package version
try:
import MLaaS4HEP
version = MLaaS4HEP.__version__
except:
version = '0.0.0'
init = 'src/python/MLaaS4HEP/__init__.py'
if os.path.exists(init):
with open(init) as istream:
for line in istream.readlines():
line = line.replace('\n', '')
if line.startswith('__version__'):
version = str(line.split('=')[-1]).strip().replace("'", "").replace('"', '')
ver = sys.version.split(' ')[0]
pver = '.'.join(ver.split('.')[:-1])
lpath = 'lib/python{}/site-packages'.format(pver)
dist = setup(
name = 'MLaaS4HEP',
version = version,
author = 'Valentin Kuznetsov',
author_email = 'vkuznet@gmail.com',
license = 'MIT',
description = 'MLaaS framework for HEP',
long_description = 'MLaaS framework for HEP',
packages = ['MLaaS4HEP'],
package_dir = {'MLaaS4HEP': 'src/python/MLaaS4HEP'},
install_requires = ['keras', 'numpy', 'pandas', 'uproot', 'pyarrow'],
scripts = ['bin/%s'%s for s in os.listdir('bin')],
url = 'https://github.com/dmwm/MLaaS4HEP',
data_files = [],
cmdclass = {'test': TestCommand},
classifiers = [
"Programming Language :: Python",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
],
)
def read_init(init_file):
"Read package init file and return its content"
init = None
with open(init_file) as istream:
init = istream.read()
return init
def write_version(init_file, init_content):
"Write package init file with given content"
if not init_content:
init_content = \
"""
__version__ = '0.0.0'
__all__ = []
"""
if init_file:
with open(init_file, 'w') as ostream:
ostream.write(init_content)
def version():
"Return git tag version of the package or custom version"
cmd = 'git tag --list | tail -1'
ver = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
ver = str(ver.decode("utf-8")).replace('\n', '')
ver = ver if ver else '0.0.0'
return ver
if __name__ == "__main__":
# This part is used by `python setup.py sdist` to build package tar-ball
# read git version
ver = version()
# read package init file
init_file = 'src/python/MLaaS4HEP/__init__.py'
init = read_init(init_file)
# replace package init file with our version
write_version(init_file, init.replace('0.0.0', ver))
# execute setup main
main()
# put back original content of package init file
write_version(init_file, init.replace(ver, '0.0.0'))