setup.py 11.0 KB
Newer Older
1
# lint as: python3
2
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
3 4 5 6 7 8 9 10 11 12 13
#
# 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
14
# limitations under the License..
15
# ==============================================================================
16 17
"""TensorFlow is an open source machine learning framework for everyone.

18 19 20
[![Python](https://img.shields.io/pypi/pyversions/tensorflow.svg?style=plastic)](https://badge.fury.io/py/tensorflow)
[![PyPI](https://badge.fury.io/py/tensorflow.svg)](https://badge.fury.io/py/tensorflow)

21 22 23 24 25 26 27 28 29 30
TensorFlow is an open source software library for high performance numerical
computation. Its flexible architecture allows easy deployment of computation
across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters
of servers to mobile and edge devices.

Originally developed by researchers and engineers from the Google Brain team
within Google's AI organization, it comes with strong support for machine
learning and deep learning and the flexible numerical computation core is used
across many other scientific domains.
"""
31

32 33 34 35
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

36 37
import fnmatch
import os
38
import re
39 40
import sys

41 42 43
from setuptools import Command
from setuptools import find_packages
from setuptools import setup
44
from setuptools.command.install import install as InstallCommandBase
45 46
from setuptools.dist import Distribution

A
Andrew Harp 已提交
47 48 49
# This version string is semver compatible, but incompatible with pip.
# For pip, we will remove all '-' characters from this string, and use the
# result for pip.
J
Jason Zaman 已提交
50 51
# Also update tensorflow/tensorflow.bzl and
# tensorflow/core/public/version.h
52
_VERSION = '2.3.0'
E
Eugene Brevdo 已提交
53

54
REQUIRED_PACKAGES = [
Z
zjjott 已提交
55
    'absl-py >= 0.7.0',
56
    'astunparse == 1.6.3',
57
    'gast == 0.3.3',
58
    'google_pasta >= 0.1.8',
M
Mihai Maruseac 已提交
59
    'h5py >= 2.10.0, < 2.11.0',
M
Mihai Maruseac 已提交
60
    'keras_preprocessing >= 1.1.1, < 1.2',
61 62 63
    # TODO(mihaimaruseac): numpy 1.19.0 has ABI breakage
    # https://github.com/numpy/numpy/pull/15355
    'numpy >= 1.16.0, < 1.19.0',
64
    'opt_einsum >= 2.3.2',
T
Taehee Jeong 已提交
65
    'protobuf >= 3.9.2',
66
    'tensorboard >= 2.3.0, < 3',
67
    'tensorflow_estimator >= 2.3.0, < 2.4.0',
68
    'termcolor >= 1.1.0',
69
    'wrapt >= 1.11.1',
M
Mihai Maruseac 已提交
70
    'wheel >= 0.26',
71
    'six >= 1.12.0',
M
Mihai Maruseac 已提交
72
    # scipy < 1.4.1 causes segfaults due to pybind11
M
Mihai Maruseac 已提交
73
    'scipy == 1.4.1',
74 75
]

76 77 78 79 80 81
if sys.byteorder == 'little':
  # grpcio does not build correctly on big-endian machines due to lack of
  # BoringSSL support.
  # See https://github.com/tensorflow/tensorflow/issues/17882.
  REQUIRED_PACKAGES.append('grpcio >= 1.8.6')

82 83 84 85 86 87 88
project_name = 'tensorflow'
if '--project_name' in sys.argv:
  project_name_idx = sys.argv.index('--project_name')
  project_name = sys.argv[project_name_idx + 1]
  sys.argv.remove('--project_name')
  sys.argv.pop(project_name_idx)

S
Sourabh Bajaj 已提交
89
# tf-nightly should depend on tb-nightly
A
Andrew Harp 已提交
90
if 'tf_nightly' in project_name:
S
Sourabh Bajaj 已提交
91 92
  for i, pkg in enumerate(REQUIRED_PACKAGES):
    if 'tensorboard' in pkg:
93
      REQUIRED_PACKAGES[i] = 'tb-nightly >= 2.3.0a0, < 2.4.0a0'
94
    elif 'tensorflow_estimator' in pkg:
95
      REQUIRED_PACKAGES[i] = 'tf-estimator-nightly'
A
Andrew Harp 已提交
96

Y
Yifei Feng 已提交
97 98 99 100 101 102 103 104 105 106
DOCLINES = __doc__.split('\n')
if project_name.endswith('-gpu'):
  project_name_no_gpu = project_name[:-len('-gpu')]
  _GPU_PACKAGE_NOTE = 'Note that %s package by default supports both CPU and '\
      'GPU. %s has the same content and exists solely for backward '\
      'compatiblity. Please migrate to %s for GPU support.'\
      % (project_name_no_gpu, project_name, project_name_no_gpu)
  DOCLINES.append(_GPU_PACKAGE_NOTE)


107 108
# pylint: disable=line-too-long
CONSOLE_SCRIPTS = [
109 110 111
    'toco_from_protos = tensorflow.lite.toco.python.toco_from_protos:main',
    'tflite_convert = tensorflow.lite.python.tflite_convert:main',
    'toco = tensorflow.lite.python.tflite_convert:main',
112
    'saved_model_cli = tensorflow.python.tools.saved_model_cli:main',
B
Benoit Steiner 已提交
113 114 115 116
    # We need to keep the TensorBoard command, even though the console script
    # is now declared by the tensorboard pip package. If we remove the
    # TensorBoard command, pip will inappropriately remove it during install,
    # even though the command is not removed, just moved to a different wheel.
117
    'tensorboard = tensorboard.main:run_main',
118
    'tf_upgrade_v2 = tensorflow.tools.compatibility.tf_upgrade_v2_main:main',
119 120
    'estimator_ckpt_converter = '
    'tensorflow_estimator.python.estimator.tools.checkpoint_converter:main',
121 122 123
]
# pylint: enable=line-too-long

A
Andrew Harp 已提交
124 125
# remove the tensorboard console script if building tf_nightly
if 'tf_nightly' in project_name:
126
  CONSOLE_SCRIPTS.remove('tensorboard = tensorboard.main:run_main')
A
Andrew Harp 已提交
127

128 129 130 131
TEST_PACKAGES = [
    'scipy >= 0.15.1',
]

132

133
class BinaryDistribution(Distribution):
134

135 136
  def has_ext_modules(self):
    return True
137 138


139 140 141 142 143
class InstallCommand(InstallCommandBase):
  """Override the dir where the headers go."""

  def finalize_options(self):
    ret = InstallCommandBase.finalize_options(self)
144
    self.install_headers = os.path.join(self.install_platlib, 'tensorflow',
M
Mihai Maruseac 已提交
145
                                        'include')
146
    self.install_lib = self.install_platlib
147 148 149 150 151 152 153 154 155 156 157 158
    return ret


class InstallHeaders(Command):
  """Override how headers are copied.

  The install_headers that comes with setuptools copies all files to
  the same directory. But we need the files to be in a specific directory
  hierarchy for -I <include_dir> to work correctly.
  """
  description = 'install C/C++ header files'

159 160 161 162
  user_options = [
      ('install-dir=', 'd', 'directory to install header files to'),
      ('force', 'f', 'force installation (overwrite existing files)'),
  ]
163 164 165 166 167 168 169 170 171

  boolean_options = ['force']

  def initialize_options(self):
    self.install_dir = None
    self.force = 0
    self.outfiles = []

  def finalize_options(self):
172
    self.set_undefined_options('install', ('install_headers', 'install_dir'),
173 174 175 176 177 178
                               ('force', 'force'))

  def mkdir_and_copy_file(self, header):
    install_dir = os.path.join(self.install_dir, os.path.dirname(header))
    # Get rid of some extra intervening directories so we can have fewer
    # directories for -I
V
Vijay Vasudevan 已提交
179
    install_dir = re.sub('/google/protobuf_archive/src', '', install_dir)
180

181
    # Copy external code headers into tensorflow/include.
182 183 184 185
    # A symlink would do, but the wheel file that gets created ignores
    # symlink within the directory hierarchy.
    # NOTE(keveman): Figure out how to customize bdist_wheel package so
    # we can do the symlink.
186
    external_header_locations = [
187 188
        'tensorflow/include/external/eigen_archive/',
        'tensorflow/include/external/com_google_absl/',
189 190 191 192 193 194 195
    ]
    for location in external_header_locations:
      if location in install_dir:
        extra_dir = install_dir.replace(location, '')
        if not os.path.exists(extra_dir):
          self.mkpath(extra_dir)
        self.copy_file(header, extra_dir)
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    if not os.path.exists(install_dir):
      self.mkpath(install_dir)
    return self.copy_file(header, install_dir)

  def run(self):
    hdrs = self.distribution.headers
    if not hdrs:
      return

    self.mkpath(self.install_dir)
    for header in hdrs:
      (out, _) = self.mkdir_and_copy_file(header)
      self.outfiles.append(out)

  def get_inputs(self):
    return self.distribution.headers or []

  def get_outputs(self):
    return self.outfiles


def find_files(pattern, root):
  """Return all the files matching pattern below root dir."""
220
  for dirpath, _, files in os.walk(root):
221
    for filename in fnmatch.filter(files, pattern):
222
      yield os.path.join(dirpath, filename)
223 224


M
Michael Case 已提交
225 226 227 228
so_lib_paths = [
    i for i in os.listdir('.')
    if os.path.isdir(i) and fnmatch.fnmatch(i, '_solib_*')
]
229

230
matches = []
231
for path in so_lib_paths:
232
  matches.extend(['../' + x for x in find_files('*', path) if '.py' not in x])
233

P
Patrick Nguyen 已提交
234
if os.name == 'nt':
235
  EXTENSION_NAME = 'python/_pywrap_tensorflow_internal.pyd'
P
Patrick Nguyen 已提交
236
else:
237
  EXTENSION_NAME = 'python/_pywrap_tensorflow_internal.so'
238

239
headers = (
240 241 242
    list(find_files('*.proto', 'tensorflow/compiler')) +
    list(find_files('*.proto', 'tensorflow/core')) +
    list(find_files('*.proto', 'tensorflow/python')) +
243
    list(find_files('*.def', 'tensorflow/compiler')) +
244
    list(find_files('*.h', 'tensorflow/c')) +
245
    list(find_files('*.h', 'tensorflow/cc')) +
246
    list(find_files('*.h', 'tensorflow/compiler')) +
247
    list(find_files('*.h.inc', 'tensorflow/compiler')) +
248 249 250
    list(find_files('*.h', 'tensorflow/core')) +
    list(find_files('*.h', 'tensorflow/python')) +
    list(find_files('*.h', 'tensorflow/stream_executor')) +
251 252
    list(find_files('*.h', 'google/com_google_protobuf/src')) +
    list(find_files('*.inc', 'google/com_google_protobuf/src')) +
253 254 255 256
    list(find_files('*', 'third_party/eigen3')) +
    list(find_files('*.h', 'tensorflow/include/external/com_google_absl')) +
    list(find_files('*.inc', 'tensorflow/include/external/com_google_absl')) +
    list(find_files('*', 'tensorflow/include/external/eigen_archive')))
257

258
setup(
259
    name=project_name,
A
Andrew Harp 已提交
260
    version=_VERSION.replace('-', ''),
261
    description=DOCLINES[0],
262
    long_description='\n'.join(DOCLINES[2:]),
P
Patrick Nguyen 已提交
263
    url='https://www.tensorflow.org/',
264
    download_url='https://github.com/tensorflow/tensorflow/tags',
265
    author='Google Inc.',
266
    author_email='packages@tensorflow.org',
267 268 269 270 271
    # Contained modules and scripts.
    packages=find_packages(),
    entry_points={
        'console_scripts': CONSOLE_SCRIPTS,
    },
272
    headers=headers,
273 274 275 276 277
    install_requires=REQUIRED_PACKAGES,
    tests_require=REQUIRED_PACKAGES + TEST_PACKAGES,
    # Add in any packaged data.
    include_package_data=True,
    package_data={
278 279 280
        'tensorflow': [
            EXTENSION_NAME,
        ] + matches,
281 282 283
    },
    zip_safe=False,
    distclass=BinaryDistribution,
284 285 286 287
    cmdclass={
        'install_headers': InstallHeaders,
        'install': InstallCommand,
    },
288
    # PyPI package information.
289
    classifiers=sorted([
290
        'Development Status :: 5 - Production/Stable',
291 292 293 294
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: Apache Software License',
J
Jonathan Hseu 已提交
295 296 297
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
M
Michael Käufl 已提交
298
        'Programming Language :: Python :: 3.7',
299 300
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3 :: Only',
J
Jonathan Hseu 已提交
301
        'Topic :: Scientific/Engineering',
302
        'Topic :: Scientific/Engineering :: Mathematics',
J
Jonathan Hseu 已提交
303 304
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
        'Topic :: Software Development',
P
Patrick Nguyen 已提交
305 306
        'Topic :: Software Development :: Libraries',
        'Topic :: Software Development :: Libraries :: Python Modules',
307
    ]),
308
    license='Apache 2.0',
309 310
    keywords='tensorflow tensor machine learning',
)