2
0
Lutz Roeder 3 жил өмнө
parent
commit
c5a113037e
4 өөрчлөгдсөн 45 нэмэгдсэн , 94 устгасан
  1. 10 4
      Makefile
  2. 13 4
      publish/server.js
  3. 5 86
      publish/setup.py
  4. 17 0
      publish/version.py

+ 10 - 4
Makefile

@@ -39,11 +39,17 @@ update: install
 	@./tools/xmodel sync schema
 
 build_python: install
-	python -m pip install --user wheel
-	python ./publish/setup.py build --version bdist_wheel
+	python -m pip install --user build wheel --quiet
+	rm -rf ./dist/pypi
+	mkdir -p ./dist/pypi/netron
+	cp -R ./source/* ./dist/pypi/netron
+	cp ./publish/setup.py ./dist/pypi
+	rm ./dist/pypi/netron/electron.* ./dist/pypi/netron/app.js
+	python publish/version.py
+	python -m build --no-isolation --wheel --outdir ./dist/pypi dist/pypi
 
 install_python: build_python
-	pip install --force-reinstall --quiet dist/dist/*.whl
+	pip install --force-reinstall dist/pypi/*.whl
 
 build_electron: install
 	npx electron-builder --mac --universal --publish never -c.mac.identity=null
@@ -70,7 +76,7 @@ coverage:
 
 publish_python: build_python
 	python -m pip install --user twine
-	python -m twine upload --non-interactive --skip-existing --verbose dist/dist/*
+	python -m twine upload --non-interactive --skip-existing --verbose dist/pypi/*.whl
 
 publish_electron: install
 	npx electron-builder --mac --universal --publish always

+ 13 - 4
publish/server.js

@@ -1,15 +1,24 @@
 
 const child_process = require('child_process');
+const fs = require('fs');
 const path = require('path');
 
-const options = { stdio: 'inherit' };
+const source = path.join('source');
+const target = path.join('dist', 'pypi', 'netron');
+
+if (fs.existsSync(target)) {
+    fs.rmdirSync(target, { recursive: true });
+}
 
-const setupPath = path.join('publish', 'setup.py');
+fs.mkdirSync(target, { recursive: true });
 
-child_process.spawnSync('python', [ setupPath, '--quiet', 'build' ], options);
+for (const file of fs.readdirSync(source)) {
+    fs.copyFileSync(path.join(source, file), path.join(target, file));
+}
 
+const options = { stdio: 'inherit' };
 options.env = Object.assign({}, process.env);
-options.env.PYTHONPATH = path.join('dist', 'lib');
+options.env.PYTHONPATH = path.join('dist', 'pypi');
 
 const args = [ '-c', 'import netron; netron.main()' ].concat(process.argv.slice(2));
 child_process.spawnSync('python', args, options);

+ 5 - 86
publish/setup.py

@@ -1,66 +1,10 @@
 #!/usr/bin/env python
 
-import io
-import json
-import os
-import re
 import setuptools
-import setuptools.command.build_py
-import distutils.command.build
-
-node_dependencies = [ ( 'netron', [] ) ]
-
-class build(distutils.command.build.build):
-    user_options = distutils.command.build.build.user_options + [ ('version', None, 'version' ) ]
-    def initialize_options(self):
-        distutils.command.build.build.initialize_options(self)
-        self.version = None
-    def finalize_options(self):
-        distutils.command.build.build.finalize_options(self)
-    def run(self):
-        build_py.version = bool(self.version)
-        return distutils.command.build.build.run(self)
-
-class build_py(setuptools.command.build_py.build_py):
-    user_options = setuptools.command.build_py.build_py.user_options + [ ('version', None, 'version' ) ]
-    def initialize_options(self):
-        setuptools.command.build_py.build_py.initialize_options(self)
-        self.version = None
-    def finalize_options(self):
-        setuptools.command.build_py.build_py.finalize_options(self)
-    def run(self):
-        setuptools.command.build_py.build_py.run(self)
-        for target, files in node_dependencies:
-            target = os.path.join(self.build_lib, target)
-            if not os.path.exists(target):
-                os.makedirs(target)
-            for file in files:
-                self.copy_file(file, target)
-        if build_py.version:
-            for _, _, build_dir, filenames in self.data_files:
-                for filename in filenames:
-                    if filename == 'index.html':
-                        filepath = os.path.join(build_dir, filename)
-                        with open(filepath, 'r') as reader:
-                            content = reader.read()
-                        content = re.sub(r'(<meta name="version" content=")\d+.\d+.\d+(">)', r'\g<1>' + package_version() + r'\g<2>', content)
-                        with open(filepath, 'w') as writer:
-                            writer.write(content)
-    def build_module(self, module, module_file, package):
-        setuptools.command.build_py.build_py.build_module(self, module, module_file, package)
-        if build_py.version and module == '__version__':
-            outfile = self.get_module_outfile(self.build_lib, package.split('.'), module)
-            with open(outfile, 'w+') as writer:
-                writer.write("__version__ = '" + package_version() + "'\n")
-
-def package_version():
-    with open('./package.json') as reader:
-        manifest = json.load(reader)
-        return manifest['version']
 
 setuptools.setup(
     name="netron",
-    version=package_version(),
+    version="0.0.0",
     description="Viewer for neural network, deep learning, and machine learning models",
     long_description='Netron is a viewer for neural network, deep learning, and machine learning models.\n\n' +
                      'Netron supports ONNX, TensorFlow Lite, Keras, Caffe, Darknet, ncnn, MNN, PaddlePaddle, Core ML, MXNet, RKNN, MindSpore Lite, TNN, Barracuda, Tengine, TensorFlow.js, Caffe2 and UFF. Netron has experimental support for PyTorch, TensorFlow, TorchScript, OpenVINO, Torch, Vitis AI, Arm NN, BigDL, Chainer, CNTK, Deeplearning4j, MediaPipe, ML.NET and scikit-learn.',
@@ -70,31 +14,19 @@ setuptools.setup(
         'visualizer', 'viewer'
     ],
     license="MIT",
-    cmdclass={
-        'build': build,
-        'build_py': build_py
-    },
-    package_dir={
-        'netron': 'source'
-    },
-    packages=[
-        'netron'
-    ],
+    package_dir={ 'netron': 'netron' },
+    packages=[ 'netron' ],
     package_data={ 'netron': [ '*.*' ] },
     exclude_package_data={ 'netron': [ 'app.js', 'electron.*' ] },
     install_requires=[],
     author='Lutz Roeder',
     author_email='[email protected]',
     url='https://github.com/lutzroeder/netron',
-    entry_points={
-        'console_scripts': [ 'netron = netron:main' ]
-    },
+    entry_points={ 'console_scripts': [ 'netron = netron:main' ] },
     classifiers=[
         'Intended Audience :: Developers',
         'Intended Audience :: Education',
         'Intended Audience :: Science/Research',
-        'Programming Language :: Python :: 2',
-        'Programming Language :: Python :: 2.7',
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.6',
         'Topic :: Software Development',
@@ -104,18 +36,5 @@ setuptools.setup(
         'Topic :: Scientific/Engineering :: Mathematics',
         'Topic :: Scientific/Engineering :: Artificial Intelligence',
         'Topic :: Scientific/Engineering :: Visualization'
-    ],
-    options={
-        'build': {
-            'build_base': './dist',
-            'build_lib': './dist/lib'
-        },
-        'bdist_wheel': {
-            'universal': 1,
-            'dist_dir': './dist/dist'
-        },
-        'egg_info': {
-            'egg_base': './dist'
-        }
-    }
+    ]
 )

+ 17 - 0
publish/version.py

@@ -0,0 +1,17 @@
+
+import json
+
+with open('./package.json') as file:
+    package = json.load(file)
+    version = package['version']
+
+def replace(path, old, new):
+    with open(path, 'r') as file:
+        content = file.read()
+    content = content.replace(old, new)
+    with open(path, 'w') as file:
+        file.write(content)
+
+replace('./dist/pypi/setup.py', '0.0.0', version)
+replace('./dist/pypi/netron/__version__.py', '0.0.0', version)
+replace('./dist/pypi/netron/index.html', '0.0.0', version)