1# lint as: python3
2# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License..
15# ==============================================================================
16"""TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile devices.
17
18This PyPI package includes the Python bindings for following features:
19
20 - Metadata schemas: wraps TFLite model schema and metadata schema in Python.
21 - Metadata populator and displayer: can be used to populate the metadata and
22 associated files into the model, as well as converting the populated metadata
23 into the json format.
24 - Android Codegen tool: generates the Java model interface used in Android for
25 a particular model.
26"""
27
28from __future__ import absolute_import
29from __future__ import division
30from __future__ import print_function
31
32import fnmatch
33import os
34import re
35import sys
36
37from setuptools import Command
38from setuptools import find_packages
39from setuptools import setup
40from setuptools.command.install import install as InstallCommandBase
41from setuptools.dist import Distribution
42
43# This version string is semver compatible, but incompatible with pip.
44# For pip, we will remove all '-' characters from this string, and use the
45# result for pip.
46_VERSION = '0.1.0'
47
48SETUP_PACKAGES = [
49    'pybind11 >= 2.6.0',
50]
51
52REQUIRED_PACKAGES = [
53    'absl-py >= 0.7.0',
54    'numpy >= 1.16.0',
55    'flatbuffers >= 1.12',
56] + SETUP_PACKAGES
57
58project_name = 'tflite-support'
59if '--project_name' in sys.argv:
60  project_name_idx = sys.argv.index('--project_name')
61  project_name = sys.argv[project_name_idx + 1]
62  sys.argv.remove('--project_name')
63  sys.argv.pop(project_name_idx)
64
65DOCLINES = __doc__.split('\n')
66
67CONSOLE_SCRIPTS = [
68    'tflite_codegen = tensorflow_lite_support.codegen.python.codegen:main',
69]
70
71
72class BinaryDistribution(Distribution):
73
74  def has_ext_modules(self):
75    return True
76
77
78class InstallCommand(InstallCommandBase):
79  """Override the dir where the headers go."""
80
81  def finalize_options(self):
82    ret = InstallCommandBase.finalize_options(self)
83    self.install_lib = self.install_platlib
84    return ret
85
86
87def find_files(pattern, root):
88  """Return all the files matching pattern below root dir."""
89  for dirpath, _, files in os.walk(root):
90    for filename in fnmatch.filter(files, pattern):
91      yield os.path.join(dirpath, filename)
92
93
94so_lib_paths = [
95    i for i in os.listdir('.')
96    if os.path.isdir(i) and fnmatch.fnmatch(i, '_solib_*')
97]
98
99matches = []
100for path in so_lib_paths:
101  matches.extend(['../' + x for x in find_files('*', path) if '.py' not in x])
102
103EXTENSIONS = ['codegen/_pywrap_codegen.so']
104
105headers = ()
106
107setup(
108    name=project_name,
109    version=_VERSION.replace('-', ''),
110    description=DOCLINES[0],
111    long_description='\n'.join(DOCLINES),
112    long_description_content_type='text/markdown',
113    url='https://www.tensorflow.org/',
114    download_url='https://github.com/tensorflow/tflite-support/tags',
115    author='Google, LLC.',
116    author_email='packages@tensorflow.org',
117    # Contained modules and scripts.
118    packages=find_packages(),
119    entry_points={
120        'console_scripts': CONSOLE_SCRIPTS,
121    },
122    headers=headers,
123    setup_requires=SETUP_PACKAGES,
124    install_requires=REQUIRED_PACKAGES,
125    tests_require=REQUIRED_PACKAGES,
126    # Add in any packaged data.
127    include_package_data=True,
128    package_data={
129        'tflite-support': EXTENSIONS + matches,
130    },
131    zip_safe=False,
132    distclass=BinaryDistribution,
133    cmdclass={
134        'install': InstallCommand,
135    },
136    # PyPI package information.
137    classifiers=sorted([
138        'Development Status :: 3 - Alpha',
139        'Intended Audience :: Developers',
140        'Intended Audience :: Education',
141        'Intended Audience :: Science/Research',
142        'License :: OSI Approved :: Apache Software License',
143        'Programming Language :: Python :: 2.7',
144        'Programming Language :: Python :: 3.6',
145        'Programming Language :: Python :: 3.7',
146        'Programming Language :: Python :: 3.8',
147        'Topic :: Scientific/Engineering',
148        'Topic :: Scientific/Engineering :: Artificial Intelligence',
149        'Topic :: Software Development',
150        'Topic :: Software Development :: Libraries',
151        'Topic :: Software Development :: Libraries :: Python Modules',
152    ]),
153    license='Apache 2.0',
154)
155