setup.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env python
  2. import io
  3. import json
  4. import os
  5. import re
  6. import setuptools
  7. import setuptools.command.build_py
  8. import distutils.command.build
  9. node_dependencies = [
  10. ( 'netron', [
  11. 'node_modules/d3/dist/d3.js',
  12. 'node_modules/dagre/dist/dagre.js'
  13. ]
  14. )
  15. ]
  16. class build(distutils.command.build.build):
  17. user_options = distutils.command.build.build.user_options + [ ('version', None, 'version' ) ]
  18. def initialize_options(self):
  19. distutils.command.build.build.initialize_options(self)
  20. self.version = None
  21. def finalize_options(self):
  22. distutils.command.build.build.finalize_options(self)
  23. def run(self):
  24. build_py.version = bool(self.version)
  25. return distutils.command.build.build.run(self)
  26. class build_py(setuptools.command.build_py.build_py):
  27. user_options = setuptools.command.build_py.build_py.user_options + [ ('version', None, 'version' ) ]
  28. def initialize_options(self):
  29. setuptools.command.build_py.build_py.initialize_options(self)
  30. self.version = None
  31. def finalize_options(self):
  32. setuptools.command.build_py.build_py.finalize_options(self)
  33. def run(self):
  34. setuptools.command.build_py.build_py.run(self)
  35. for target, files in node_dependencies:
  36. target = os.path.join(self.build_lib, target)
  37. if not os.path.exists(target):
  38. os.makedirs(target)
  39. for file in files:
  40. self.copy_file(file, target)
  41. if build_py.version:
  42. for _, _, build_dir, filenames in self.data_files:
  43. for filename in filenames:
  44. if filename == 'index.html':
  45. filepath = os.path.join(build_dir, filename)
  46. with open(filepath, 'r') as reader:
  47. content = reader.read()
  48. content = re.sub(r'(<meta name="version" content=")\d+.\d+.\d+(">)', r'\g<1>' + package_version() + r'\g<2>', content)
  49. with open(filepath, 'w') as writer:
  50. writer.write(content)
  51. def build_module(self, module, module_file, package):
  52. setuptools.command.build_py.build_py.build_module(self, module, module_file, package)
  53. if build_py.version and module == '__version__':
  54. outfile = self.get_module_outfile(self.build_lib, package.split('.'), module)
  55. with open(outfile, 'w+') as writer:
  56. writer.write("__version__ = '" + package_version() + "'\n")
  57. def package_version():
  58. with open('./package.json') as reader:
  59. manifest = json.load(reader)
  60. return manifest['version']
  61. setuptools.setup(
  62. name="netron",
  63. version=package_version(),
  64. description="Viewer for neural network, deep learning, and machine learning models",
  65. long_description='Netron is a viewer for neural network, deep learning, and machine learning models.\n\n' +
  66. 'Netron supports **ONNX** (`.onnx`, `.pb`, `.pbtxt`), **TensorFlow Lite** (`.tflite`), **Caffe** (`.caffemodel`, `.prototxt`), **Darknet** (`.cfg`), **Core ML** (`.mlmodel`, `.mlpackage`), **Keras** (`.h5`, `.keras`), **MNN** (`.mnn`), **MXNet** (`.model`, `-symbol.json`), **ncnn** (`.param`), **PaddlePaddle** (`.zip`, `__model__`), **Caffe2** (`predict_net.pb`), **Barracuda** (`.nn`), **Tengine** (`.tmfile`), **TNN** (`.tnnproto`), **RKNN** (`.rknn`), **MindSpore Lite** (`.ms`) and **UFF** (`.uff`). Netron has experimental support for **PyTorch** (`.pt`, `.pth`), **TorchScript** (`.pt`, `.pth`), **TensorFlow.js** (`model.json`, `.pb`), **TensorFlow** (`.pb`, `.meta`, `.pbtxt`, `.ckpt`, `.index`), **Torch** (`.t7`), **OpenVINO** (`.xml`), **ArmNN** (`.armnn`), **BigDL** (`.bigdl`, `.model`), **Chainer** (`.npz`, `.h5`), **CNTK** (`.model`, `.cntk`), **Deeplearning4j** (`.zip`), **MediaPipe** (`.pbtxt`), **ML.NET** (`.zip`), and **scikit-learn** (`.pkl`)',
  67. keywords=[
  68. 'onnx', 'keras', 'tensorflow', 'tflite', 'coreml', 'mxnet', 'caffe', 'caffe2', 'torchscript', 'pytorch', 'ncnn', 'mnn', 'openvino', 'darknet', 'paddlepaddle', 'chainer',
  69. 'artificial intelligence', 'machine learning', 'deep learning', 'neural network',
  70. 'visualizer', 'viewer'
  71. ],
  72. license="MIT",
  73. cmdclass={
  74. 'build': build,
  75. 'build_py': build_py
  76. },
  77. package_dir={
  78. 'netron': 'source'
  79. },
  80. packages=[
  81. 'netron'
  82. ],
  83. package_data={ 'netron': [ '*.*' ] },
  84. exclude_package_data={ 'netron': [ 'app.js', 'electron.*' ] },
  85. install_requires=[],
  86. author='Lutz Roeder',
  87. author_email='[email protected]',
  88. url='https://github.com/lutzroeder/netron',
  89. entry_points={
  90. 'console_scripts': [ 'netron = netron:main' ]
  91. },
  92. classifiers=[
  93. 'Intended Audience :: Developers',
  94. 'Intended Audience :: Education',
  95. 'Intended Audience :: Science/Research',
  96. 'Programming Language :: Python :: 2',
  97. 'Programming Language :: Python :: 2.7',
  98. 'Programming Language :: Python :: 3',
  99. 'Programming Language :: Python :: 3.6',
  100. 'Topic :: Software Development',
  101. 'Topic :: Software Development :: Libraries',
  102. 'Topic :: Software Development :: Libraries :: Python Modules',
  103. 'Topic :: Scientific/Engineering',
  104. 'Topic :: Scientific/Engineering :: Mathematics',
  105. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  106. 'Topic :: Scientific/Engineering :: Visualization'
  107. ],
  108. options={
  109. 'build': {
  110. 'build_base': './dist',
  111. 'build_lib': './dist/lib'
  112. },
  113. 'bdist_wheel': {
  114. 'universal': 1,
  115. 'dist_dir': './dist/dist'
  116. },
  117. 'egg_info': {
  118. 'egg_base': './dist'
  119. }
  120. }
  121. )