|
| 1 | +# Copyright 2019 Google LLC. 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 | +"""Setup for pip package.""" |
| 16 | + |
| 17 | +from __future__ import absolute_import |
| 18 | +from __future__ import division |
| 19 | +from __future__ import print_function |
| 20 | + |
| 21 | +import atexit |
| 22 | +import glob |
| 23 | +import os |
| 24 | +import shutil |
| 25 | +import sys |
| 26 | +import tempfile |
| 27 | + |
| 28 | +import setuptools |
| 29 | + |
| 30 | +# Version string is intentionally set to non-numeric value, so that non-release |
| 31 | +# built packages are different from release packages. During builds for formal |
| 32 | +# releases, we should temporarily change this value to pip release version. |
| 33 | +__version__ = 'custom-build-from-source' |
| 34 | + |
| 35 | + |
| 36 | +class BinaryDistribution(setuptools.Distribution): |
| 37 | + """This class is needed in order to create OS specific wheels.""" |
| 38 | + |
| 39 | + def has_ext_modules(self): |
| 40 | + return True |
| 41 | + |
| 42 | + |
| 43 | +def main(srcdir): |
| 44 | + tempdir = tempfile.mkdtemp() |
| 45 | + atexit.register(shutil.rmtree, tempdir) |
| 46 | + |
| 47 | + pkgdir = os.path.join(tempdir, 'tensorflow_compression') |
| 48 | + shutil.copytree(os.path.join(srcdir, 'tensorflow_compression'), pkgdir) |
| 49 | + shutil.copy2(os.path.join(srcdir, 'MANIFEST.in'), tempdir) |
| 50 | + shutil.copy2(os.path.join(srcdir, 'LICENSE'), pkgdir) |
| 51 | + shutil.copy2(os.path.join(srcdir, 'README.md'), pkgdir) |
| 52 | + |
| 53 | + if not os.path.exists( |
| 54 | + os.path.join(pkgdir, 'cc/libtensorflow_compression.so')): |
| 55 | + raise RuntimeError('libtensorflow_compression.so not found. ' |
| 56 | + 'Did you \'bazel run?\'') |
| 57 | + |
| 58 | + print('=== Building wheel') |
| 59 | + atexit.register(os.chdir, os.getcwd()) |
| 60 | + os.chdir(tempdir) |
| 61 | + setuptools.setup( |
| 62 | + name='tensorflow-compression', |
| 63 | + version=__version__, |
| 64 | + description='Data compression in TensorFlow', |
| 65 | + url='https://tensorflow.github.io/compression/', |
| 66 | + author='Google LLC', |
| 67 | + # Contained modules and scripts. |
| 68 | + packages=setuptools.find_packages(), |
| 69 | + install_requires=[ |
| 70 | + 'scipy >= 1.0.0', |
| 71 | + 'tensorflow >= 1.14.0', |
| 72 | + ], |
| 73 | + script_args=['sdist', 'bdist_wheel'], |
| 74 | + # Add in any packaged data. |
| 75 | + include_package_data=True, |
| 76 | + zip_safe=False, |
| 77 | + distclass=BinaryDistribution, |
| 78 | + # PyPI package information. |
| 79 | + classifiers=[ |
| 80 | + 'Development Status :: 4 - Beta', |
| 81 | + 'Intended Audience :: Developers', |
| 82 | + 'Intended Audience :: Education', |
| 83 | + 'Intended Audience :: Science/Research', |
| 84 | + 'License :: OSI Approved :: Apache Software License', |
| 85 | + 'Programming Language :: Python :: 2.7', |
| 86 | + 'Programming Language :: Python :: 3.4', |
| 87 | + 'Topic :: Scientific/Engineering :: Mathematics', |
| 88 | + 'Topic :: Software Development :: Libraries :: Python Modules', |
| 89 | + 'Topic :: Software Development :: Libraries', |
| 90 | + ], |
| 91 | + project_urls={ |
| 92 | + 'Documentation': |
| 93 | + 'https://tensorflow.github.io/compression/docs/api_docs/python/tfc.html', |
| 94 | + 'Discussion': |
| 95 | + 'https://groups.google.com/forum/#!forum/tensorflow-compression', |
| 96 | + 'Source': 'https://github.com/tensorflow/compression', |
| 97 | + 'Tracker': 'https://github.com/tensorflow/compression/issues', |
| 98 | + }, |
| 99 | + license='Apache 2.0', |
| 100 | + keywords=('compression data-compression tensorflow machine-learning ' |
| 101 | + 'python deep-learning deep-neural-networks neural-network ml') |
| 102 | + ) |
| 103 | + |
| 104 | + destdir = '/tmp/tensorflow_compression' |
| 105 | + print('=== Copying wheel to ' + destdir) |
| 106 | + if not os.path.exists(destdir): os.mkdir(destdir) |
| 107 | + for path in glob.glob(os.path.join(tempdir, 'dist', '*.whl')): |
| 108 | + print('Copying into ' + os.path.join(destdir, os.path.basename(path))) |
| 109 | + shutil.copy(path, destdir) |
| 110 | + |
| 111 | + |
| 112 | +if __name__ == '__main__': |
| 113 | + main(sys.argv[1] if len(sys.argv) > 1 else '') |
0 commit comments