16
16
17
17
from __future__ import print_function
18
18
19
+ import logging
19
20
import os
20
21
import subprocess
21
22
import sys
22
23
23
24
import setuptools
24
- from setuptools import find_packages
25
+ from setuptools import find_namespace_packages
25
26
from setuptools import setup
26
27
from setuptools .command import develop
27
28
# pylint: disable=g-bad-import-order
37
38
from tfx .tools import resolve_deps
38
39
from wheel import bdist_wheel
39
40
41
+ # Prefer to import `package_config` from the setup.py script's directory. The
42
+ # `package_config.py` file is used to configure which package to build (see
43
+ # the logic below switching on `package_config.PACKAGE_NAME`) and the overall
44
+ # package build README at `package_build/README.md`.
45
+ sys .path .insert (0 , os .path .dirname (__file__ ))
46
+ # pylint: disable=g-bad-import-order,g-import-not-at-top
47
+ import package_config
48
+ # pylint: enable=g-bad-import-order,g-import-not-at-top
49
+
40
50
41
51
class _BdistWheelCommand (bdist_wheel .bdist_wheel ):
42
52
"""Overrided bdist_wheel command.
@@ -160,13 +170,67 @@ def run(self):
160
170
env = os .environ )
161
171
162
172
163
- # Get the long description from the README file .
173
+ # Get the long descriptions from README files .
164
174
with open ('README.md' ) as fp :
165
- _LONG_DESCRIPTION = fp .read ()
175
+ _TFX_LONG_DESCRIPTION = fp .read ()
176
+ with open ('README.ml-pipelines-sdk.md' ) as fp :
177
+ _PIPELINES_SDK_LONG_DESCRIPTION = fp .read ()
178
+
179
+ package_name = package_config .PACKAGE_NAME
180
+ tfx_extras_requires = {
181
+ # In order to use 'docker-image' or 'all', system libraries specified
182
+ # under 'tfx/tools/docker/Dockerfile' are required
183
+ 'docker-image' : dependencies .make_extra_packages_docker_image (),
184
+ 'tfjs' : dependencies .make_extra_packages_tfjs (),
185
+ 'examples' : dependencies .make_extra_packages_examples (),
186
+ 'test' : dependencies .make_extra_packages_test (),
187
+ 'all' : dependencies .make_extra_packages_all (),
188
+ }
189
+ ml_pipelines_sdk_packages = ['tfx.dsl' , 'tfx.dsl.*' ]
166
190
191
+ # This `setup.py` file can be used to build packages in 3 configurations. See
192
+ # the discussion in `package_build/README.md` for an overview. The `tfx` and
193
+ # `ml-pipelines-sdk` pip packages can be built for distribution using the
194
+ # selectable `package_config.PACKAGE_NAME` specifier. Additionally, for
195
+ # development convenience, the `tfx-dev` package containing the union of the
196
+ # the `tfx` and `ml-pipelines-sdk` package can be installed as an editable
197
+ # package using `pip install -e .`, but should not be built for distribution.
198
+ if package_config .PACKAGE_NAME == 'tfx-dev' :
199
+ # Monolithic development package with the entirety of `tfx.*` and the full
200
+ # set of dependencies. Functionally equivalent to the union of the "tfx" and
201
+ # "tfx-pipeline-sdk" packages.
202
+ install_requires = dependencies .make_required_install_packages ()
203
+ extras_require = tfx_extras_requires
204
+ long_description = _TFX_LONG_DESCRIPTION
205
+ packages = find_namespace_packages (include = ['tfx' , 'tfx.*' ])
206
+ # TODO(b/174503231): Remove the override on the following line and prevent
207
+ # build of wheels from a monolithic "tfx" package.
208
+ package_name = 'tfx'
209
+ elif package_config .PACKAGE_NAME == 'ml-pipelines-sdk' :
210
+ # Core TFX pipeline authoring SDK, without dependency on component-specific
211
+ # packages like "tensorflow" and "apache-beam".
212
+ install_requires = dependencies .make_pipeline_sdk_required_install_packages ()
213
+ extras_require = {}
214
+ long_description = _PIPELINES_SDK_LONG_DESCRIPTION
215
+ packages = find_namespace_packages (include = ml_pipelines_sdk_packages )
216
+ elif package_config .PACKAGE_NAME == 'tfx' :
217
+ # Recommended installation package for TFX. This package builds on top of
218
+ # the "ml-pipelines-sdk" pipeline authoring SDK package and adds first-party
219
+ # TFX components and additional functionality.
220
+ install_requires = (
221
+ ['ml-pipelines-sdk==%s' % version .__version__ ] +
222
+ dependencies .make_required_install_packages ())
223
+ extras_require = tfx_extras_requires
224
+ long_description = _TFX_LONG_DESCRIPTION
225
+ packages = find_namespace_packages (
226
+ include = ['tfx' , 'tfx.*' ], exclude = ml_pipelines_sdk_packages )
227
+ else :
228
+ raise ValueError ('Invalid package config: %r.' % package_config .PACKAGE_NAME )
229
+
230
+ logging .info ('Executing build for package %r.' , package_name )
167
231
168
232
setup (
169
- name = 'tfx' ,
233
+ name = package_name ,
170
234
version = version .__version__ ,
171
235
author = 'Google LLC' ,
172
236
@@ -192,16 +256,8 @@ def run(self):
192
256
'Topic :: Software Development :: Libraries :: Python Modules' ,
193
257
],
194
258
namespace_packages = [],
195
- install_requires = dependencies .make_required_install_packages (),
196
- extras_require = {
197
- # In order to use 'docker-image' or 'all', system libraries specified
198
- # under 'tfx/tools/docker/Dockerfile' are required
199
- 'docker-image' : dependencies .make_extra_packages_docker_image (),
200
- 'tfjs' : dependencies .make_extra_packages_tfjs (),
201
- 'examples' : dependencies .make_extra_packages_examples (),
202
- 'test' : dependencies .make_extra_packages_test (),
203
- 'all' : dependencies .make_extra_packages_all (),
204
- },
259
+ install_requires = install_requires ,
260
+ extras_require = extras_require ,
205
261
# TODO(b/158761800): Move to [build-system] requires in pyproject.toml.
206
262
setup_requires = [
207
263
'pytest-runner' ,
@@ -219,10 +275,10 @@ def run(self):
219
275
'resolve_deps' : resolve_deps .ResolveDepsCommand ,
220
276
},
221
277
python_requires = '>=3.6,<3.9' ,
222
- packages = find_packages () ,
278
+ packages = packages ,
223
279
include_package_data = True ,
224
280
description = 'TensorFlow Extended (TFX) is a TensorFlow-based general-purpose machine learning platform implemented at Google' ,
225
- long_description = _LONG_DESCRIPTION ,
281
+ long_description = long_description ,
226
282
long_description_content_type = 'text/markdown' ,
227
283
keywords = 'tensorflow tfx' ,
228
284
url = 'https://www.tensorflow.org/tfx' ,
0 commit comments