Browse Source

Flatten build folder

Lutz Roeder 6 years ago
parent
commit
ae68144c97
21 changed files with 61 additions and 58 deletions
  1. 4 3
      DEVELOPMENT.md
  2. 11 11
      Makefile
  3. 1 1
      electron-builder.yml
  4. 1 1
      package.json
  5. 4 4
      setup.cfg
  6. 2 6
      setup.py
  7. 7 3
      src/__init__.py
  8. 9 9
      src/server.py
  9. 1 1
      tools/caffe
  10. 1 1
      tools/cntk
  11. 2 2
      tools/coreml
  12. 1 1
      tools/darknet
  13. 2 2
      tools/keras
  14. 1 1
      tools/mxnet
  15. 1 1
      tools/onnx
  16. 2 2
      tools/paddle
  17. 2 2
      tools/pytorch
  18. 4 2
      tools/sklearn
  19. 2 2
      tools/tf
  20. 2 2
      tools/tflite
  21. 1 1
      tools/torch

+ 4 - 3
DEVELOPMENT.md

@@ -15,7 +15,7 @@ npx electron ./
 
 To debug the Electron app use [Visual Studio Code](https://code.visualstudio.com) and install the [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) extension. Open the `./netron` root folder and press `F5`. To attach the debugger to a render process select the `Debug` tab and `Debug Renderer Process` before launching.
 
-To build Electron release binaries to the `./build/electron` folder run:
+To build Electron release binaries to the `./build` folder run:
 
 ```bash
 npx electron-builder --mac --linux --win
@@ -29,6 +29,7 @@ To build and launch the Python server run:
 git clone https://github.com/lutzroeder/netron.git
 cd netron
 npm install
-python setup.py build
-PYTHONPATH=build/python/lib python -c "import netron; netron.main()"
+python3 setup.py build
+export PYTHONPATH=build/lib:${PYTHONPATH}
+python3 -c "import netron; netron.main()"
 ```

+ 11 - 11
Makefile

@@ -3,7 +3,7 @@
 
 build: clean lint build_python build_electron
 
-publish: clean lint publish_github_electron publish_pip publish_github_pages publish_cask
+publish: clean lint publish_github_electron publish_python publish_github_pages publish_cask
 
 pull:
 	git pull --rebase --prune
@@ -28,8 +28,8 @@ update:
 
 build_python:
 	@[ -d node_modules ] || npm install
-	rm -rf ./build/python
-	python ./setup.py build --version
+	rm -rf ./build
+	python3 ./setup.py build --version
 
 build_electron:
 	@[ -d node_modules ] || npm install
@@ -48,13 +48,13 @@ start:
 	@[ -d node_modules ] || npm install
 	npx electron .
 
-publish_pip:
+publish_python:
 	@[ -d node_modules ] || npm install
-	rm -rf ./build/python
-	python ./setup.py build --version bdist_wheel
-	python -m pip install --user keyring
-	python -m pip install --user twine
-	twine upload build/python/dist/*
+	rm -rf ./build
+	python3 ./setup.py build --version bdist_wheel
+	python3 -m pip install --user keyring
+	python3 -m pip install --user twine
+	# twine upload build/dist/*
 
 publish_github_electron:
 	@[ -d node_modules ] || npm install
@@ -63,11 +63,11 @@ publish_github_electron:
 
 publish_github_pages:
 	@[ -d node_modules ] || npm install
-	python ./setup.py build --version
+	python3 ./setup.py build --version
 	rm -rf ./build/gh-pages
 	git clone [email protected]:lutzroeder/netron.git ./build/gh-pages --branch gh-pages
 	rm -rf ./build/gh-pages/*
-	cp -R ./build/python/lib/netron/* ./build/gh-pages/
+	cp -R ./build/lib/netron/* ./build/gh-pages/
 	rm -rf ./build/gh-pages/*.py
 	rm -rf ./build/gh-pages/*.pyc
 	rm -rf ./build/gh-pages/netron

+ 1 - 1
electron-builder.yml

@@ -4,7 +4,7 @@ files:
   - 'src/**/*'
 directories:
   buildResources: setup
-  output: ./build/electron
+  output: ./build
 fileAssociations:
   - name: "ONNX Model"
     ext: onnx

+ 1 - 1
package.json

@@ -12,7 +12,7 @@
     "main": "src/app.js",
     "scripts": {
         "start": "[ -d node_modules ] || npm install && npx electron .",
-        "start_server": "[ -d node_modules ] || npm install && rm -rf build/python && python setup.py --quiet build && PYTHONPATH=build/python/lib python -c 'import netron; netron.main()' $@"
+        "start_server": "[ -d node_modules ] || npm install && python3 setup.py --quiet build && PYTHONPATH=build/lib python3 -c 'import netron; netron.main()' $@"
     },
     "dependencies": {
         "d3": "5.9.2",

+ 4 - 4
setup.cfg

@@ -1,10 +1,10 @@
 [build]
-build-base = ./build/python
-build-lib = ./build/python/lib
+build-base = ./build
+build-lib = ./build/lib
 
 [bdist_wheel]
 universal=1
-dist-dir = ./build/python/dist
+dist-dir = ./build/dist
 
 [egg_info]
-egg_base = ./build/python
+egg_base = ./build

+ 2 - 6
setup.py

@@ -28,10 +28,7 @@ class build(distutils.command.build.build):
     def finalize_options(self):
         distutils.command.build.build.finalize_options(self)
     def run(self):
-        if self.version:
-            build_py.version = True;
-        else:
-            build_py.version = False;
+        build_py.version = bool(self.version)
         return distutils.command.build.build.run(self)
 
 class build_py(setuptools.command.build_py.build_py):
@@ -42,14 +39,13 @@ class build_py(setuptools.command.build_py.build_py):
     def finalize_options(self):
         setuptools.command.build_py.build_py.finalize_options(self)
     def run(self):
-        result = setuptools.command.build_py.build_py.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)
-        return result
     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__':

+ 7 - 3
src/__init__.py

@@ -12,15 +12,19 @@ import os
 def main():
     parser = argparse.ArgumentParser(description='Viewer for neural network, deep learning and machine learning models.')
     parser.add_argument('file', metavar='MODEL_FILE', help='model file to serve', nargs='?', default=None)
-    parser.add_argument('-v', '--verbose', help='log details to console', action='store_true')
+    parser.add_argument('-v', '--version', help="print version", action='store_true')
     parser.add_argument('-b', '--browse', help='launch web browser', action='store_true')
-    parser.add_argument('--port', help='port to serve (default: 8080)', type=int, default=8080)
+    parser.add_argument('-p', '--port', help='port to serve (default: 8080)', type=int, default=8080)
     parser.add_argument('--host', help="host to serve (default: '')", default='')
+    parser.add_argument('--log', help='log details to console', action='store_true')
     args = parser.parse_args()
     if args.file and not os.path.exists(args.file):
         print("Model file '" + args.file + "' does not exist.")
         sys.exit(2)
-    serve(args.file, None, verbose=args.verbose, browse=args.browse, port=args.port, host=args.host)
+    if args.version:
+        print(__version__)
+        sys.exit(0)
+    serve(args.file, None, log=args.log, browse=args.browse, port=args.port, host=args.host)
     wait()
     sys.exit(0)
 

+ 9 - 9
src/server.py

@@ -112,7 +112,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler):
 class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): pass
 
 class HTTPServerThread(threading.Thread):
-    def __init__(self, data, file, verbose, browse, port, host):
+    def __init__(self, data, file, log, browse, port, host):
         threading.Thread.__init__(self)
         self.port = port
         self.host = host
@@ -128,7 +128,7 @@ class HTTPServerThread(threading.Thread):
             self.server.RequestHandlerClass.folder = ''
             self.server.RequestHandlerClass.file = ''
         self.server.RequestHandlerClass.data = data
-        self.server.RequestHandlerClass.verbose = verbose
+        self.server.RequestHandlerClass.log = log
         self.terminate_event = threading.Event()
         self.terminate_event.set()
         self.stop_event = threading.Event()
@@ -147,7 +147,7 @@ class HTTPServerThread(threading.Thread):
                     threading.Timer(1, webbrowser.open, args=(self.url,)).start()
                 sys.stdout.flush()
                 self.server.handle_request()
-        except Exception as e:
+        except Exception:
             pass
         self.terminate_event.set()
         self.stop_event.clear()
@@ -189,13 +189,13 @@ def wait():
             thread.stop()
         thread_list = [ thread for thread in thread_list if thread.alive() ]
 
-def serve(file, data, verbose=False, browse=False, port=8080, host=''):
+def serve(file, data, log=False, browse=False, port=8080, host=''):
     '''Start serving model from file or data buffer at host:port and open in web browser.
     
     Args:
         file (string): Model file to serve. Required to detect format.
         data (bytes): Model data to serve. None will load data from file.
-        verbose (bool, optional): Log details to console. Default: False
+        log (bool, optional): Log details to console. Default: False
         browse (bool, optional): Launch web browser, Default: True
         port (int, optional): Port to serve. Default: 8080
         host (string, optional): Host to serve. Default: ''
@@ -204,19 +204,19 @@ def serve(file, data, verbose=False, browse=False, port=8080, host=''):
     if not data and file and not os.path.exists(file):
         raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file)
     stop(port, host)
-    thread = HTTPServerThread(data, file, verbose, browse, port, host)
+    thread = HTTPServerThread(data, file, log, browse, port, host)
     thread.start()
     thread_list.append(thread)
     thread_list = [ thread for thread in thread_list if thread.alive() ]
 
-def start(file, verbose=False, browse=True, port=8080, host=''):
+def start(file, log=False, browse=True, port=8080, host=''):
     '''Start serving model file at host:port and open in web browser
     
     Args:
         file (string): Model file to serve.
-        verbose (bool, optional): Log details to console. Default: False
+        log (bool, optional): Log details to console. Default: False
         browse (bool, optional): Launch web browser, Default: True
         port (int, optional): Port to serve. Default: 8080
         host (string, optional): Host to serve. Default: ''
     '''
-    serve(file, None, verbose=verbose, browse=browse, port=port, host=host)
+    serve(file, None, log=log, browse=browse, port=port, host=host)

+ 1 - 1
tools/caffe

@@ -5,8 +5,8 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=caffe
 

+ 1 - 1
tools/cntk

@@ -5,8 +5,8 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=cntk
 

+ 2 - 2
tools/coreml

@@ -5,11 +5,11 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=coremltools
-virtualenv=${root}/build/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 1 - 1
tools/darknet

@@ -5,8 +5,8 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=darknet
 

+ 2 - 2
tools/keras

@@ -5,8 +5,8 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 build=${root}/build
 test=${root}/test
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 if [ $(which python3) ]; then
     python="python3"
@@ -15,7 +15,7 @@ else
 fi
 
 identifier=keras
-virtualenv=${build}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 

+ 1 - 1
tools/mxnet

@@ -4,8 +4,8 @@ set -e
 
 root=$(cd $(dirname ${0})/..; pwd)
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 if [ $(which python3) ] && [ $(which pip3) ]; then
     python="python3"

+ 1 - 1
tools/onnx

@@ -10,7 +10,7 @@ third_party=${root}/third_party
 tools=${root}/tools
 
 identifier=onnx
-virtualenv=${build}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 2 - 2
tools/paddle

@@ -5,11 +5,11 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=paddle
-virtualenv=${root}/build/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 

+ 2 - 2
tools/pytorch

@@ -7,11 +7,11 @@ build=${root}/build
 node_modules=${root}/node_modules
 src=${root}/src
 test=${root}/test
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=pytorch
-virtualenv=${build}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 4 - 2
tools/sklearn

@@ -3,9 +3,11 @@
 set -e
 
 root=$(cd $(dirname ${0})/..; pwd)
-virtualenv=${root}/build/virtualenv/scikit-learn
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
+
+identifier=scikit-learn
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 2 - 2
tools/tf

@@ -6,11 +6,11 @@ root=$(cd $(dirname ${0})/..; pwd)
 build=${root}/build
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=tensorflow
-virtualenv=${build}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 2 - 2
tools/tflite

@@ -5,11 +5,11 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 build=${root}/build
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=tflite
-virtualenv=${build}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/${identifier}
 
 if [ $(which python3) ]; then
     python="python3"

+ 1 - 1
tools/torch

@@ -5,8 +5,8 @@ set -e
 root=$(cd $(dirname ${0})/..; pwd)
 node_modules=${root}/node_modules
 src=${root}/src
-tools=${root}/tools
 third_party=${root}/third_party
+tools=${root}/tools
 
 identifier=torch