Files
openvino/tools/mo/setup.py

119 lines
3.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Copyright (C) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
"""
Use this script to create a wheel with Model Optimizer code:
$ python setup.py sdist bdist_wheel
"""
import os
import re
import sys
from pathlib import Path
from shutil import copyfile, copy
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
from setuptools import setup, find_namespace_packages
from setuptools.command.build_py import build_py
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
from setuptools.command.install import install
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
prefix = 'openvino/tools/mo/'
SETUP_DIR = Path(__file__).resolve().parent / Path(prefix)
def read_text(path):
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
return (Path(__file__).resolve().parent / path).read_text()
# Detect all the framework specific requirements_*.txt files.
requirements_txt = []
py_modules = []
for item in os.listdir():
if re.match(r'requirements(.*)\.txt', item):
requirements_txt.append(item)
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
for item in os.listdir(prefix):
if re.match(r'mo(.*)\.py|main(.*)\.py', item):
py_modules.append(prefix.replace('/', '.') + item.split('.')[0])
py_modules.append(prefix.replace('/', '.') + 'subprocess_main')
py_modules.append(prefix.replace('/', '.') + '__main__')
# Minimal set of dependencies
deps_whitelist = ['networkx', 'defusedxml', 'numpy', 'openvino-telemetry']
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
# for py37 and less on Windows need importlib-metadata in order to use entry_point *.exe files
if sys.platform == 'win32' and sys.version_info[1] < 8:
deps_whitelist.append('importlib-metadata')
deps = []
with open('requirements.txt', 'rt') as req_file:
for line in req_file.read().split('\n'):
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
if line.startswith(tuple(deps_whitelist)):
deps.append(line)
class InstallCmd(install):
def run(self):
install.run(self)
# copy requirements.txt files for all the frameworks
for name in requirements_txt:
copy(name, os.path.join(self.install_purelib, prefix))
2021-03-30 10:46:35 +03:00
version_txt = 'version.txt'
if os.path.exists(version_txt):
copyfile(os.path.join(version_txt),
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
os.path.join(self.install_purelib, prefix, version_txt))
class BuildCmd(build_py):
def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
return [
(pkg, module, filename)
for (pkg, module, filename) in modules
]
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
packages = find_namespace_packages(prefix[:-1])
packages = [prefix.replace('/', '.') + p for p in packages]
setup(
name='openvino-mo',
version='0.0.0',
author='Intel Corporation',
author_email='openvino_pushbot@intel.com',
url='https://github.com/openvinotoolkit/openvino',
packages=packages,
py_modules=py_modules,
cmdclass={
'install': InstallCmd,
'build_py': BuildCmd,
},
entry_points={
'console_scripts': [
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
'mo = openvino.tools.mo.__main__:main',
],
},
package_data={
[MO] Align MO namespaces (#7708) * Moved and merged mo/ and extensions/ into openvino/tools/mo * edited imports * edited docs to use mo script from entry_point * edited MO transformations list loading and setup.py * changed full path -> 'mo' entry point in docs (leftovers) * corrected package_BOM * updated resolving --transformation_config in cli_parser.py * pkgutil-style __init__.py, added summarize_graph into entry points * updated DOCs for the new --transformations_config * fix select * updated install instructions, fixed setup.py for windows and python_version < 3.8 * fixed typo in requirements.txt * resolved conflicts * removed creating custom __init__.py from setup.py * corrected folder with caffe proto * corrected loading user defined extensions * fix openvino.tools.mo import in serialize.py * corrected layer tests for new namespace * fix in get_testdata.py * moved model-optimizer into tools/ * renamed import in POT * corrected mo.yml * correct CMakeLists.txt for the newest tools/mo * corrected find_ie_version.py * docs and openvino-dev setup.py update for the newest tools/mo * miscellaneous leftovers and fixes * corrected CI files, pybind11_add_module in CMakeLists.txt and use of tools/mo path instead of tools/model_optimizer * add_subdirectory pybind11 for tools/mo * POT path fix * updated setupvars.sh setupvars.bat * Revert "updated setupvars.sh setupvars.bat" This reverts commit c01114234062df6df7ca9619050f4227af5a43c8. * removed model-optimizer env variables from setupvars * updated CMakeLists.txt to pack MO properly with tests component * corrected left imports, corrected loading requirements for layer tests * mo doc typo correction * minor corrections in docs; removed summarize_graph from entry_points * get_started_windows.md, MonoDepth_how_to.md corrections, mo path corrections
2021-12-08 08:53:53 +03:00
'openvino.tools.mo.front.caffe.proto': ['*.proto'],
'openvino.tools.mo.front.mxnet': ['*.json'],
'openvino.tools.mo.front.onnx': ['*.json'],
'openvino.tools.mo.front.tf': ['*.json'],
},
extras_require={
'caffe': read_text('requirements_caffe.txt'),
'kaldi': read_text('requirements_kaldi.txt'),
'mxnet': read_text('requirements_mxnet.txt'),
'onnx': read_text('requirements_onnx.txt'),
'tensorflow': read_text('requirements_tf.txt'),
'tensorflow2': read_text('requirements_tf2.txt'),
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
install_requires=deps,
)