Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit 06649c4

Browse files
committed
allow tfma > 0.42 and < 0.45 (#289)
* allow tfma > 0.42 and < 0.45 * drop Python 3.7 support * bump CI Python version from 3.7 to 3.9 * updated python_requires in setup.py * updated deps * removed introduced line * CI with min version
1 parent 05474c8 commit 06649c4

File tree

3 files changed

+160
-37
lines changed

3 files changed

+160
-37
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020
- main
2121
- r*
2222

23-
concurrency:
23+
concurrency:
2424
group: ${{ github.workflow }}-${{ github.ref }}
2525
cancel-in-progress: true
2626

@@ -30,11 +30,11 @@ jobs:
3030
timeout-minutes: 60
3131

3232
steps:
33-
- uses: actions/checkout@v2
34-
- name: Set up Python 3.7
35-
uses: actions/setup-python@v2
33+
- uses: actions/checkout@v3
34+
- name: Set up Python 3.8
35+
uses: actions/setup-python@v4
3636
with:
37-
python-version: 3.7
37+
python-version: 3.8
3838
- name: Cache python environment
3939
uses: actions/cache@v2
4040
with:

model_card_toolkit/dependencies.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Copyright 2023 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Package dependencies for model-card-toolkit."""
16+
17+
import importlib
18+
from typing import Dict, List
19+
20+
_VERSIONS = {
21+
'absl': 'absl-py>=0.9,<1.1',
22+
'importlib_resources': 'importlib-resources>=1.3.0; python_version<"3.9"',
23+
'isort': 'isort',
24+
'jinja2': 'jinja2>=3.1,<3.2',
25+
'jsonschema': 'jsonschema>=3.2.0,<4',
26+
'matplotlib': 'matplotlib>=3.2.0,<4',
27+
'ml_metadata': 'ml-metadata>=1.5.0,<2.0.0',
28+
'pre-commit': 'pre-commit',
29+
'protobuf': 'protobuf>=3.19.0,<4',
30+
'pylint': 'pylint',
31+
'pytest': 'pytest',
32+
'tensorflow_data_validation': 'tensorflow-data-validation>=1.5.0,<2.0.0',
33+
'tensorflow_datasets': 'tensorflow-datasets>=4.8.2',
34+
'tensorflow_metadata': 'tensorflow-metadata>=1.5.0,<2.0.0',
35+
'tensorflow_model_analysis': 'tensorflow-model-analysis>=0.36.0,<0.45.0',
36+
'yapf': 'yapf',
37+
}
38+
39+
_REQUIRED_DEPS = [
40+
'importlib_resources', # reading resource files, e.g. model card templates
41+
'jinja2', # rendering model card templates
42+
'jsonschema', # validating JSON schema
43+
'matplotlib', # plotting
44+
'protobuf', # working with model card protos
45+
]
46+
47+
_EXAMPLES_EXTRA_DEPS = [
48+
# Required for model_card_toolkit.documentation.examples.cats_vs_dogs
49+
'tensorflow_datasets',
50+
]
51+
52+
_TENSORFLOW_EXTRA_DEPS = [
53+
'ml_metadata',
54+
'tensorflow_data_validation',
55+
'tensorflow_metadata',
56+
'tensorflow_model_analysis',
57+
]
58+
59+
_TEST_EXTRA_DEPS = ['absl', 'isort', 'pre-commit', 'pylint', 'pytest', 'yapf']
60+
61+
TENSORFLOW_EXTRA_IMPORT_ERROR_MSG = """
62+
This functionaliy requires `tensorflow` extra dependencies but they were not
63+
found in your environment. You can install them with:
64+
```
65+
pip install model-card-toolkit[tensorflow]
66+
```
67+
"""
68+
69+
70+
def _make_deps_list(package_names: List[str]) -> List[str]:
71+
"""Returns a list of dependencies with their constraints.
72+
73+
Raises: ValueError if a `package_name` is not in the list of known dependencies.
74+
"""
75+
deps = []
76+
for package_name in package_names:
77+
if package_name not in _VERSIONS:
78+
raise ValueError(
79+
f'Package {package_name} is not in the list of known dependencies: '
80+
f'{_VERSIONS.keys()}'
81+
)
82+
deps.append(_VERSIONS[package_name])
83+
return deps
84+
85+
86+
def make_required_install_packages() -> List[str]:
87+
"""Returns the list of required packages."""
88+
return _make_deps_list(_REQUIRED_DEPS)
89+
90+
91+
def make_extra_packages_examples() -> List[str]:
92+
"""Returns the list of packages needed for running examples."""
93+
return _make_deps_list(_EXAMPLES_EXTRA_DEPS)
94+
95+
96+
def make_extra_packages_tensorflow() -> List[str]:
97+
"""Returns the list of packages needed to use TensorFlow utils."""
98+
return _make_deps_list(_TENSORFLOW_EXTRA_DEPS)
99+
100+
101+
def has_tensorflow_extra_deps() -> bool:
102+
"""Returns True if all tensorflow extra dependencies are installed."""
103+
return all(importlib.util.find_spec(name) for name in _TENSORFLOW_EXTRA_DEPS)
104+
105+
106+
def ensure_tensorflow_extra_deps_installed():
107+
"""Raises ImportError if tensorflow extra dependencies are not installed.
108+
"""
109+
if not has_tensorflow_extra_deps():
110+
raise ImportError(TENSORFLOW_EXTRA_IMPORT_ERROR_MSG)
111+
112+
113+
def make_extra_packages_test() -> List[str]:
114+
"""Returns the list of packages needed for running tests."""
115+
return _make_deps_list(_TEST_EXTRA_DEPS)
116+
117+
118+
def make_extra_packages_all() -> List[str]:
119+
"""Returns the list of all optional packages."""
120+
return [
121+
*make_extra_packages_examples(),
122+
*make_extra_packages_tensorflow(),
123+
*make_extra_packages_test(),
124+
]
125+
126+
127+
def make_required_extra_packages() -> Dict[str, List[str]]:
128+
"""Returns the dict of required extra packages."""
129+
return {
130+
'examples': make_extra_packages_examples(),
131+
'tensorflow': make_extra_packages_tensorflow(),
132+
'test': make_extra_packages_test(),
133+
'all': make_extra_packages_all(),
134+
}

setup.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""Setup to install the Model Card Toolkit.
16-
17-
Run with `python3 setup.py sdist bdist_wheel`.
18-
"""
15+
"""Setup to install the Model Card Toolkit."""
1916

2017
import platform
2118
import shutil
@@ -25,30 +22,21 @@
2522

2623
from setuptools import Command, setup
2724

28-
REQUIRED_PACKAGES = [
29-
'absl-py>=0.9,<1.1',
30-
'jinja2>=3.1,<3.2',
31-
'matplotlib>=3.2.0,<4',
32-
'jsonschema>=3.2.0,<4',
33-
'tensorflow-data-validation>=1.5.0,<2.0.0',
34-
'tensorflow-model-analysis>=0.36.0,<0.42.0',
35-
'tensorflow-metadata>=1.5.0,<2.0.0',
36-
'ml-metadata>=1.5.0,<2.0.0',
37-
]
38-
39-
TESTS_REQUIRE = [
40-
'pytest',
41-
'tensorflow-datasets>=4.8.2',
42-
]
43-
44-
EXTRAS_REQUIRE = {'test': TESTS_REQUIRE}
25+
# Get dependency lists.
26+
with open('model_card_toolkit/dependencies.py') as fp:
27+
globals_dict = {}
28+
exec(fp.read(), globals_dict) # pylint: disable=exec-used
29+
make_required_install_packages = globals_dict['make_required_install_packages']
30+
make_required_extra_packages = globals_dict['make_required_extra_packages']
31+
make_extra_packages_test = globals_dict['make_extra_packages_test']
4532

4633
# Get version from version module.
4734
with open('model_card_toolkit/version.py') as fp:
4835
globals_dict = {}
4936
exec(fp.read(), globals_dict) # pylint: disable=exec-used
5037
__version__ = globals_dict['__version__']
5138

39+
# Get long description.
5240
with open('README.md', 'r', encoding='utf-8') as fh:
5341
_LONG_DESCRIPTION = fh.read()
5442

@@ -100,7 +88,7 @@ def run(self):
10088
[
10189
self._bazel_cmd, 'run', '--verbose_failures',
10290
*self._additional_build_options,
103-
'model_card_toolkit:move_generated_files'
91+
'//proto_build:move_generated_files'
10492
]
10593
)
10694

@@ -109,11 +97,14 @@ def run(self):
10997
name='model-card-toolkit',
11098
version=__version__,
11199
description='Model Card Toolkit',
100+
author='The TensorFlow Authors',
112101
long_description=_LONG_DESCRIPTION,
113102
long_description_content_type='text/markdown',
114103
url='https://github.com/tensorflow/model-card-toolkit',
115-
author='Google LLC',
116-
author_email='[email protected]',
104+
project_urls={
105+
'Bug Tracker': 'https://github.com/tensorflow/model-card-toolkit/issues',
106+
'Documentation': 'https://www.tensorflow.org/responsible_ai/model_card_toolkit/guide',
107+
},
117108
packages=[
118109
'model_card_toolkit',
119110
'model_card_toolkit.documentation',
@@ -125,11 +116,10 @@ def run(self):
125116
package_data={
126117
'model_card_toolkit': ['schema/**/*.json', 'template/**/*.jinja']
127118
},
128-
python_requires='>=3.7,<4',
129-
install_requires=REQUIRED_PACKAGES,
130-
tests_require=TESTS_REQUIRE,
131-
extras_require=EXTRAS_REQUIRE,
132-
# PyPI package information.
119+
python_requires='>=3.8,<4',
120+
install_requires=make_required_install_packages(),
121+
tests_require=make_extra_packages_test(),
122+
extras_require=make_required_extra_packages(),
133123
classifiers=[
134124
'Development Status :: 4 - Beta',
135125
'Intended Audience :: Developers',
@@ -138,7 +128,6 @@ def run(self):
138128
'License :: OSI Approved :: Apache Software License',
139129
'Operating System :: OS Independent',
140130
'Programming Language :: Python :: 3',
141-
'Programming Language :: Python :: 3.7',
142131
'Programming Language :: Python :: 3.8',
143132
'Programming Language :: Python :: 3.9',
144133
'Topic :: Scientific/Engineering',
@@ -149,9 +138,9 @@ def run(self):
149138
'Topic :: Software Development :: Libraries :: Python Modules',
150139
],
151140
license='Apache 2.0',
152-
keywords='model card toolkit ml metadata machine learning',
141+
keywords=['model card toolkit', 'ml metadata', 'machine learning'],
153142
cmdclass={
154143
'build': _BuildCommand,
155144
'bazel_build': _BazelBuildCommand,
156145
}
157-
)
146+
) # yapf: disable

0 commit comments

Comments
 (0)