setup.py 10.1 KB
Newer Older
1
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14
#
# 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.
# ==============================================================================
15 16 17 18 19 20 21 22 23 24 25 26
"""TensorFlow is an open source machine learning framework for everyone.

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.
"""
27

28 29 30 31
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

32 33
import fnmatch
import os
34
import re
35 36
import sys

37 38 39
from setuptools import Command
from setuptools import find_packages
from setuptools import setup
40
from setuptools.command.install import install as InstallCommandBase
41 42
from setuptools.dist import Distribution

43 44
DOCLINES = __doc__.split('\n')

A
Andrew Harp 已提交
45 46 47
# 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.
48
_VERSION = '1.12.0'
E
Eugene Brevdo 已提交
49

50
REQUIRED_PACKAGES = [
51
    'absl-py >= 0.1.6',
52
    'astor >= 0.6.0',
A
A. Unique TensorFlower 已提交
53
    'gast >= 0.2.0',
54 55
    'keras_applications >= 1.0.6',
    'keras_preprocessing >= 1.0.5',
56
    'numpy >= 1.13.3',
57
    'six >= 1.10.0',
58
    'protobuf >= 3.6.1',
59
    'tensorboard >= 1.12.0, < 1.13.0',
60
    'tensorflow_estimator >= 1.10.0',
61
    'termcolor >= 1.1.0',
62 63
]

64 65 66 67 68 69
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')

70 71 72 73 74 75 76
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)

77 78 79 80 81
# python3 requires wheel 0.26
if sys.version_info.major == 3:
  REQUIRED_PACKAGES.append('wheel >= 0.26')
else:
  REQUIRED_PACKAGES.append('wheel')
S
Shanqing Cai 已提交
82 83
  # mock comes with unittest.mock for python3, need to install for python2
  REQUIRED_PACKAGES.append('mock >= 2.0.0')
84

S
Sourabh Bajaj 已提交
85
# tf-nightly should depend on tb-nightly
A
Andrew Harp 已提交
86
if 'tf_nightly' in project_name:
S
Sourabh Bajaj 已提交
87 88
  for i, pkg in enumerate(REQUIRED_PACKAGES):
    if 'tensorboard' in pkg:
89
      REQUIRED_PACKAGES[i] = 'tb-nightly >= 1.13.0a0, < 1.14.0a0'
90 91
    if 'tensorflow_estimator' in pkg:
      REQUIRED_PACKAGES[i] = 'tf-estimator-nightly'
92 93
    if 'tensorflow_estimator' in pkg and '2.0' in project_name:
      REQUIRED_PACKAGES[i] = 'tensorflow-estimator-2.0-preview'
A
Andrew Harp 已提交
94

S
Shanqing Cai 已提交
95 96 97 98 99
# weakref.finalize and enum were introduced in Python 3.4
if sys.version_info < (3, 4):
  REQUIRED_PACKAGES.append('backports.weakref >= 1.0rc1')
  REQUIRED_PACKAGES.append('enum34 >= 1.1.6')

100 101
# pylint: disable=line-too-long
CONSOLE_SCRIPTS = [
J
Jacques Pienaar 已提交
102
    'freeze_graph = tensorflow.python.tools.freeze_graph:run_main',
103 104 105
    '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',
106
    'saved_model_cli = tensorflow.python.tools.saved_model_cli:main',
B
Benoit Steiner 已提交
107 108 109 110
    # 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.
111
    'tensorboard = tensorboard.main:run_main',
112
    'tf_upgrade_v2 = tensorflow.tools.compatibility.tf_upgrade_v2_main:main',
113 114 115
]
# pylint: enable=line-too-long

A
Andrew Harp 已提交
116 117
# remove the tensorboard console script if building tf_nightly
if 'tf_nightly' in project_name:
118
  CONSOLE_SCRIPTS.remove('tensorboard = tensorboard.main:run_main')
A
Andrew Harp 已提交
119

120 121 122 123
TEST_PACKAGES = [
    'scipy >= 0.15.1',
]

124

125
class BinaryDistribution(Distribution):
126

127 128
  def has_ext_modules(self):
    return True
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
class InstallCommand(InstallCommandBase):
  """Override the dir where the headers go."""

  def finalize_options(self):
    ret = InstallCommandBase.finalize_options(self)
    self.install_headers = os.path.join(self.install_purelib,
                                        'tensorflow', 'include')
    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'

  user_options = [('install-dir=', 'd',
                   'directory to install header files to'),
                  ('force', 'f',
                   'force installation (overwrite existing files)'),
                 ]

  boolean_options = ['force']

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

  def finalize_options(self):
    self.set_undefined_options('install',
                               ('install_headers', 'install_dir'),
                               ('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 已提交
172
    install_dir = re.sub('/google/protobuf_archive/src', '', install_dir)
173

174
    # Copy external code headers into tensorflow/include.
175 176 177 178
    # 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.
179 180 181 182 183 184 185 186 187 188
    external_header_locations = [
        'tensorflow/include/external/eigen_archive/',
        'tensorflow/include/external/com_google_absl/',
    ]
    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)
189

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    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."""
213
  for dirpath, _, files in os.walk(root):
214
    for filename in fnmatch.filter(files, pattern):
215
      yield os.path.join(dirpath, filename)
216 217


M
Michael Case 已提交
218 219 220 221
so_lib_paths = [
    i for i in os.listdir('.')
    if os.path.isdir(i) and fnmatch.fnmatch(i, '_solib_*')
]
222

223
matches = []
224 225 226 227
for path in so_lib_paths:
  matches.extend(
      ['../' + x for x in find_files('*', path) if '.py' not in x]
  )
228

P
Patrick Nguyen 已提交
229
if os.name == 'nt':
230
  EXTENSION_NAME = 'python/_pywrap_tensorflow_internal.pyd'
P
Patrick Nguyen 已提交
231
else:
232
  EXTENSION_NAME = 'python/_pywrap_tensorflow_internal.so'
233

234 235 236 237 238 239 240 241
headers = (
    list(find_files('*.h', 'tensorflow/core')) + list(
        find_files('*.h', 'tensorflow/stream_executor')) +
    list(find_files('*.h', 'google/protobuf_archive/src')) + 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')))
242

243
setup(
244
    name=project_name,
A
Andrew Harp 已提交
245
    version=_VERSION.replace('-', ''),
246 247
    description=DOCLINES[0],
    long_description='\n'.join(DOCLINES[2:]),
P
Patrick Nguyen 已提交
248
    url='https://www.tensorflow.org/',
249
    download_url='https://github.com/tensorflow/tensorflow/tags',
250 251 252 253 254 255 256
    author='Google Inc.',
    author_email='opensource@google.com',
    # Contained modules and scripts.
    packages=find_packages(),
    entry_points={
        'console_scripts': CONSOLE_SCRIPTS,
    },
257
    headers=headers,
258 259 260 261 262
    install_requires=REQUIRED_PACKAGES,
    tests_require=REQUIRED_PACKAGES + TEST_PACKAGES,
    # Add in any packaged data.
    include_package_data=True,
    package_data={
263 264 265
        'tensorflow': [
            EXTENSION_NAME,
        ] + matches,
266 267 268
    },
    zip_safe=False,
    distclass=BinaryDistribution,
269 270 271 272
    cmdclass={
        'install_headers': InstallHeaders,
        'install': InstallCommand,
    },
273 274
    # PyPI package information.
    classifiers=[
275
        'Development Status :: 5 - Production/Stable',
276 277 278 279
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: Apache Software License',
J
Jonathan Hseu 已提交
280
        'Programming Language :: Python :: 2',
281
        'Programming Language :: Python :: 2.7',
J
Jonathan Hseu 已提交
282 283 284 285 286
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Topic :: Scientific/Engineering',
287
        'Topic :: Scientific/Engineering :: Mathematics',
J
Jonathan Hseu 已提交
288 289
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
        'Topic :: Software Development',
P
Patrick Nguyen 已提交
290 291
        'Topic :: Software Development :: Libraries',
        'Topic :: Software Development :: Libraries :: Python Modules',
292
    ],
293
    license='Apache 2.0',
294 295
    keywords='tensorflow tensor machine learning',
)