forked from tensorflow/model-card-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
146 lines (127 loc) · 5.17 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
# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
#
# 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 to install the Model Card Toolkit.
Run with `python3 setup.py sdist bdist_wheel`.
"""
# TODO(b/188859752): deprecate distutils
from distutils.command import build
import platform
import shutil
import subprocess
from setuptools import Command
from setuptools import setup
# TODO(b/174880612): reduce dependency resolution search space
REQUIRED_PACKAGES = [
'absl-py>=0.9,<=1.1',
'jinja2>=3.1,<3.2',
'matplotlib>=3.2.0,<4',
'jsonschema>=3.2.0,<4',
'tensorflow-model-analysis>=0.36.0,<0.41.0',
'tensorflow-metadata>=1.5.0,<2.0.0',
'tfx>=1.5.0,<2.0.0',
'ml-metadata>=1.5.0,<2.0.0',
'dataclasses;python_version<"3.7"',
]
# Get version from version module.
with open('model_card_toolkit/version.py') as fp:
globals_dict = {}
exec(fp.read(), globals_dict) # pylint: disable=exec-used
__version__ = globals_dict['__version__']
with open('README.md', 'r', encoding='utf-8') as fh:
_LONG_DESCRIPTION = fh.read()
class _BuildCommand(build.build):
"""Build everything that is needed to install.
This overrides the original distutils "build" command to to run bazel_build
command before any sub_commands.
build command is also invoked from bdist_wheel and install command, therefore
this implementation covers the following commands:
- pip install . (which invokes bdist_wheel)
- python setup.py install (which invokes install command)
- python setup.py bdist_wheel (which invokes bdist_wheel command)
"""
# Add "bazel_build" command as the first sub_command of "build". Each
# sub_command of "build" (e.g. "build_py", "build_extbaz", etc.) is executed
# sequentially when running a "build" command, if the second item in the tuple
# (predicate method) is evaluated to true.
sub_commands = [
('bazel_build', lambda self: True),
] + build.build.sub_commands
class _BazelBuildCommand(Command):
"""Build Bazel artifacts and move generated files."""
def initialize_options(self):
pass
def finalize_options(self):
# verified with bazel 2.0.0, 3.0.0, and 4.0.0 via bazelisk
self._bazel_cmd = shutil.which('bazel')
if not self._bazel_cmd:
self._bazel_cmd = shutil.which('bazelisk')
if not self._bazel_cmd:
raise RuntimeError(
'Could not find "bazel" or "bazelisk" binary. Please visit '
'https://docs.bazel.build/versions/master/install.html for '
'installation instruction.')
self._additional_build_options = []
if platform.system() == 'Darwin': # see b/175182911 for context
self._additional_build_options = ['--macos_minimum_os=10.9']
def run(self):
subprocess.check_call([
self._bazel_cmd, 'run', '--verbose_failures',
*self._additional_build_options,
'model_card_toolkit:move_generated_files'
])
setup(
name='model-card-toolkit',
version=__version__,
description='Model Card Toolkit',
long_description=_LONG_DESCRIPTION,
long_description_content_type='text/markdown',
url='https://github.com/tensorflow/model-card-toolkit',
author='Google LLC',
author_email='[email protected]',
packages=[
'model_card_toolkit', 'model_card_toolkit.documentation',
'model_card_toolkit.documentation.examples', 'model_card_toolkit.proto',
'model_card_toolkit.tfx', 'model_card_toolkit.utils'
],
package_data={
'model_card_toolkit': ['schema/**/*.json', 'template/**/*.jinja']
},
python_requires='>=3.6,<4',
install_requires=REQUIRED_PACKAGES,
tests_require=REQUIRED_PACKAGES,
# PyPI package information.
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3 :: Only',
'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',
],
license='Apache 2.0',
keywords='model card toolkit ml metadata machine learning',
cmdclass={
'build': _BuildCommand,
'bazel_build': _BazelBuildCommand,
})