-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
142 lines (121 loc) · 5.18 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
# ------------------------------------------------------------------------
# Copyright (c) 2022-present, SeetaCloud, Co.,Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
"""Python setup script."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import shutil
import subprocess
import sys
import setuptools
import setuptools.command.build_py
import setuptools.command.install
def parse_args():
"""Parse arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('--version', default=None)
args, unknown = parser.parse_known_args()
args.git_version = None
args.long_description = ''
sys.argv = [sys.argv[0]] + unknown
if args.version is None and os.path.exists('version.txt'):
with open('version.txt', 'r') as f:
args.version = f.read().strip()
if os.path.exists('.git'):
try:
git_version = subprocess.check_output(
['git', 'rev-parse', 'HEAD'], cwd='./')
args.git_version = git_version.decode('ascii').strip()
except (OSError, subprocess.CalledProcessError):
pass
if os.path.exists('README.md'):
with open(os.path.join('README.md'), encoding='utf-8') as f:
args.long_description = f.read()
return args
def clean_builds():
for path in ['build', 'codewithgpu.egg-info']:
if os.path.exists(path):
shutil.rmtree(path)
if os.path.exists('codewithgpu/version.py'):
os.remove('codewithgpu/version.py')
def find_packages(top):
"""Return the python sources installed to package."""
packages = []
for root, _, _ in os.walk(top):
if os.path.exists(os.path.join(root, '__init__.py')):
packages.append(root)
return packages
def find_package_data(top):
"""Return the external data installed to package."""
protos = ['data/record.proto', 'data/tf_record.proto']
return protos
class BuildPyCommand(setuptools.command.build_py.build_py):
"""Enhanced 'build_py' command."""
def build_packages(self):
with open('codewithgpu/version.py', 'w') as f:
f.write("from __future__ import absolute_import\n"
"from __future__ import division\n"
"from __future__ import print_function\n\n"
"version = '{}'\n"
"git_version = '{}'\n".format(args.version, args.git_version))
protoc = self.get_finalized_command('install').protoc
if protoc is not None:
cmd = '{} -I codewithgpu/data --python_out codewithgpu/data '
cmd += 'codewithgpu/data/record.proto '
cmd += 'codewithgpu/data/tf_record.proto'
subprocess.call(cmd.format(protoc), shell=True)
self.packages = find_packages('codewithgpu')
super(BuildPyCommand, self).build_packages()
def build_package_data(self):
self.package_data = {'codewithgpu': find_package_data('codewithgpu')}
super(BuildPyCommand, self).build_package_data()
class InstallCommand(setuptools.command.install.install):
"""Enhanced 'install' command."""
user_options = setuptools.command.install.install.user_options
user_options += [('protoc=', None, "path to the protobuf compiler")]
def initialize_options(self):
self.protoc = None
super(InstallCommand, self).initialize_options()
self.old_and_unmanageable = True
args = parse_args()
setuptools.setup(
name='codewithgpu',
version=args.version,
description='CodeWithGPU Python Client',
long_description=args.long_description,
long_description_content_type='text/markdown',
url='https://github.com/seetacloud/codewithgpu',
author='SeetaCloud',
license='Apache License',
packages=find_packages('codewithgpu'),
cmdclass={'build_py': BuildPyCommand, 'install': InstallCommand},
install_requires=[],
entry_points={"console_scripts": ["cg = codewithgpu.cli:main_cli"]},
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: C++',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Artificial Intelligence'],
)
clean_builds()