-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
126 lines (108 loc) · 4.08 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
#!/usr/bin/env python
import re
import io
import os
import shutil
import distutils.command.clean
from pathlib import Path
from setuptools import setup, find_namespace_packages
from pkg_resources import get_distribution, DistributionNotFound
from ml.shutil import run as sh
cwd = Path(__file__).parent
pkg = sh('basename -s .git `git config --get remote.origin.url`').lower()
PKG = pkg.upper()
def write_version_py(path, major=None, minor=None, patch=None, suffix='', sha='Unknown'):
if major is None or minor is None or patch is None:
major, minor, patch = sh("git tag --sort=taggerdate | tail -1")[1:].split('.')
sha = sh("git rev-parse HEAD")
print(f"Build version {major}.{minor}.{patch}-{sha}")
path = Path(path).resolve()
pkg = path.name
PKG = pkg.upper()
version = f'{major}.{minor}.{patch}{suffix}'
if os.getenv(f'{PKG}_BUILD_VERSION'):
assert os.getenv(f'{PKG}_BUILD_NUMBER') is not None
build_number = int(os.getenv(f'{PKG}_BUILD_NUMBER'))
version = os.getenv(f'{PKG}_BUILD_VERSION')
if build_number > 1:
version += '.post' + str(build_number)
elif sha != 'Unknown':
version += '+' + sha[:7]
import time
content = f"""# GENERATED VERSION FILE
# TIME: {time.asctime()}
import ml, torch
__version__ = {repr(version)}
git_version = {repr(sha)}
cuda = torch.version.cuda
"""
with open(path / 'version.py', 'w') as f:
f.write(content)
return version
def dist_info(pkgname):
try:
return get_distribution(pkgname)
except DistributionNotFound:
return None
# TODO
class Clean(distutils.command.clean.clean):
def run(self):
import glob
import re
with open('.gitignore', 'r') as f:
ignores = f.read()
pat = re.compile(r'^#( BEGIN NOT-CLEAN-FILES )?')
for wildcard in filter(None, ignores.split('\n')):
match = pat.match(wildcard)
if match:
if match.group(1):
# Marker is found and stop reading .gitignore.
break
# Ignore lines which begin with '#'.
else:
for filename in glob.glob(wildcard):
print(f"removing {filename} to clean")
try:
os.remove(filename)
except OSError:
shutil.rmtree(filename, ignore_errors=True)
# It's an old-style class in Python 2.7...
distutils.command.clean.clean.run(self)
def readme():
with open('README.md', encoding='utf-8') as f:
content = f.read()
return content
if __name__ == '__main__':
version = write_version_py(pkg)
requirements = [
'torch',
]
namespaces = ['ml']
packages = find_namespace_packages(include=['ml.*'], exclude=('ml.csrc', 'ml.csrc.*'))
setup(
name=pkg.upper(),
version=version,
author='Farley Lai;Deep Patel',
url='https://gitlab.com/necla-ml/ML',
description=f"NECLA ML Library",
long_description=readme(),
keywords='machine learning, computer vision, natural language processing, distributed computing',
license='BSD-3',
classifiers=[
'License :: OSI Approved :: BSD License',
'Operating System :: macOS/Ubuntu 18.04+',
'Development Status :: 1 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
],
packages=namespaces + packages,
install_requires=requirements,
zip_safe=False)