-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
198 lines (165 loc) · 7.1 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
# coding=utf-8
# Copyright 2020 Konstantin Ustyuzhanin.
#
# 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.
"""Setup script for OSAR-keras.
This script will install OSAR-keras as a Python module.
See: https://github.com/ustyuzhaninky/OSAR-keras
"""
import argparse
import codecs
import datetime
import fnmatch
import os
import sys
from os import path
from setuptools import find_packages
from setuptools import setup
import codecs
from setuptools import find_packages
from setuptools import setup
from setuptools.command.install import install as InstallCommandBase
from setuptools.dist import Distribution
import osar_version
# Defaults if doing a release build.
TENSORFLOW_VERSION = 'tensorflow>=2.9.0'
class BinaryDistribution(Distribution):
def has_ext_modules(self):
return True
def find_files(pattern, root):
"""Return all the files matching pattern below root dir."""
for dirpath, _, files in os.walk(root):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(dirpath, filename)
class InstallCommand(InstallCommandBase):
"""Override the dir where the headers go."""
def finalize_options(self):
ret = super().finalize_options()
# We need to set this manually because we are not using setuptools to
# compile the shared libraries we are distributing.
self.install_lib = self.install_platlib
return ret
class SetupToolsHelper(object):
"""Helper to execute `setuptools.setup()`."""
def __init__(self, release=False, tf_version_override=None):
"""Initialize ReleaseBuilder class.
Args:
release: True to do a release build. False for a nightly build.
tf_version_override: Set to override the tf_version dependency.
"""
self.release = release
self.tf_version_override = tf_version_override
def _get_version(self):
"""Returns the version and project name to associate with the build."""
if self.release:
project_name = 'OSAR'
version = osar_version.__rel_version__
else:
project_name = 'OSAR-nightly'
version = osar_version.__dev_version__
version += datetime.datetime.now().strftime('%Y%m%d')
return version, project_name
def _get_required_packages(self):
"""Returns list of required packages."""
with open('requirements.txt', 'rt') as file:
required_packages = file.readlines()
return required_packages
def _get_tensorflow_packages(self):
"""Returns list of required packages if using OSAR."""
tf_packages = []
if self.release:
tf_version = TENSORFLOW_VERSION
else:
tf_version = 'tf-nightly'
# Overrides required versions if tf_version_override is set.
if self.tf_version_override:
tf_version = self.tf_version_override
tf_packages.append(tf_version)
return tf_packages
def run_setup(self):
# Builds the long description from the README.
root_path = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(root_path, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
version, project_name = self._get_version()
setup(
name=project_name,
version=version,
include_package_data=True,
packages=find_packages(exclude=['docs']), # Required
# package_data={'testdata': ['testdata/*.gin']},
install_requires=self._get_required_packages(),
extras_require={
'tensorflow': self._get_tensorflow_packages(),
},
distclass=BinaryDistribution,
cmdclass={
'install': InstallCommand,
},
headers=list(find_files('*.proto', 'osar')),
description='OSAR: An Objective Stimuli Active Repeater',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/ustyuzhaninky/OSAR-keras', # Optional
author='Konstantin Ustyuzhanin', # Optional
# python_requires='>=3',
classifiers=[ # Optional
'Development Status :: 3 - Alpha',
# Indicate who your project is intended for
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
# Pick your license as you wish
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'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',
],
project_urls={ # Optional
'Documentation': 'https://github.com/ustyuzhaninky/OSAR-keras',
'Bug Reports': 'https://github.com/ustyuzhaninky/OSAR-keras/issues',
'Source': 'https://github.com/ustyuzhaninky/OSAR-keras',
},
license='Apache 2.0',
keywords='keras tensorflow actor-critic-methods gym exploratory q-learning reinforcement learning python machine learning'
)
if __name__ == '__main__':
# Hide argparse help so `setuptools.setup` help prints. This pattern is an
# improvement over using `sys.argv` and then `sys.argv.remove`, which also
# did not provide help about custom arguments.
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'--release',
action='store_true',
help='Pass as true to do a release build')
parser.add_argument(
'--tf-version',
type=str,
default=None,
help='Overrides TF version required when OSAR is installed, e.g.'
'tensorflow>=2.4.1')
FLAGS, unparsed = parser.parse_known_args()
# Go forward with only non-custom flags.
sys.argv.clear()
# Downstream `setuptools.setup` expects args to start at the second element.
unparsed.insert(0, 'foo')
sys.argv.extend(unparsed)
setup_tools_helper = SetupToolsHelper(release=FLAGS.release,
tf_version_override=FLAGS.tf_version)
setup_tools_helper.run_setup()