From 1d4b4b4a102cd751be3fc2af38dccda74260d9f8 Mon Sep 17 00:00:00 2001 From: AivanF Date: Mon, 9 Aug 2021 16:56:55 +0300 Subject: [PATCH 1/4] PyInstaller config in template app --- smart_kit/template/app.pyinst.spec-tpl | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 smart_kit/template/app.pyinst.spec-tpl diff --git a/smart_kit/template/app.pyinst.spec-tpl b/smart_kit/template/app.pyinst.spec-tpl new file mode 100644 index 00000000..ef74a92e --- /dev/null +++ b/smart_kit/template/app.pyinst.spec-tpl @@ -0,0 +1,77 @@ +# -*- mode: python ; coding: utf-8 -*- + +import os +import importlib + + +def data_files_for_packages(package_files: dict) -> list: + datas = [] + for package, files in package_files.items(): + proot = os.path.dirname(importlib.import_module(package).__file__) if package != '' else '' + datas.extend( + ( + os.path.join(proot, f), # Source file pattern + os.path.join(package, os.path.dirname(f)) # Dest relative folder + ) for f in files) + return datas + + +# This is not necessarily actual files but path patters +datas = data_files_for_packages({ + # Our app + '': ['static/.'], + # 3rd-party libs + 'ics': ['grammar/contentline.ebnf'], + 'pymorphy2_dicts': ['data/*.json', 'data/*.array', 'data/*.dawg', 'data/*.intdawg'], + 'rnnmorph': ['models/.'], +}) + +print(f'\n - Data files: {datas}\n') + +block_cipher = None + +a = Analysis( + ['manage.py'], + pathex=[os.path.abspath(SPECPATH)], + binaries=[], + datas=datas, + hiddenimports=['app_config'], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False +) + +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='app', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None +) + +coll = COLLECT( + exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='manage' +) From 2f7b2a137277bf100efa0157e7ebf4b45a30ce64 Mon Sep 17 00:00:00 2001 From: AivanF Date: Mon, 9 Aug 2021 16:57:02 +0300 Subject: [PATCH 2/4] Fixes for PyInstaller --- setup.py | 2 +- smart_kit/start_points/main_loop_http.py | 3 ++- smart_kit/testing/local.py | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 354e782f..992fe652 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ "dill==0.3.3", "h5py<3.0.0", "ics==0.6", - "jaeger_client==4.3.0", + "jaeger_client==4.6.0", "Jinja2==2.10.1", "keras==2.3.1", "lazy", diff --git a/smart_kit/start_points/main_loop_http.py b/smart_kit/start_points/main_loop_http.py index ba00e0a5..d344e3c8 100644 --- a/smart_kit/start_points/main_loop_http.py +++ b/smart_kit/start_points/main_loop_http.py @@ -1,6 +1,7 @@ import json import typing from collections import defaultdict +import sys from wsgiref.simple_server import make_server import scenarios.logging.logger_constants as log_const @@ -152,4 +153,4 @@ def run(self): def stop(self, signum, frame): if self._server: self._server.server_close() - exit(0) + sys.exit(0) diff --git a/smart_kit/testing/local.py b/smart_kit/testing/local.py index 36e106d6..2f3c94ac 100644 --- a/smart_kit/testing/local.py +++ b/smart_kit/testing/local.py @@ -1,5 +1,6 @@ import cmd import json +import sys import os import pprint import typing @@ -133,7 +134,7 @@ def do_show_scenarios(self, _input: str): def preloop(self): if len(self.available_scenarios) == 0: print("Нет доступных сценариев.") - exit(0) + sys.exit(0) self.environment.intent = self.available_scenarios[0] print("Текущий сценарий: ", self.environment.intent) From 51098f025c5beb4e81c662f3688ca2b1e37f1142 Mon Sep 17 00:00:00 2001 From: AivanF Date: Tue, 10 Aug 2021 09:26:37 +0300 Subject: [PATCH 3/4] PyInst utils & dependency --- setup.py | 3 ++- smart_kit/template/app.pyinst.spec-tpl | 31 +++----------------------- smart_kit/utils/pyinst.py | 25 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 smart_kit/utils/pyinst.py diff --git a/setup.py b/setup.py index 992fe652..314b08fa 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,8 @@ "tensorflow==1.15", "timeout-decorator==0.4.1", "tqdm", - "Twisted" + "Twisted", + "pyinstaller=4.5", ], classifiers=[ "Programming Language :: Python :: 3.6", diff --git a/smart_kit/template/app.pyinst.spec-tpl b/smart_kit/template/app.pyinst.spec-tpl index ef74a92e..e5600ed7 100644 --- a/smart_kit/template/app.pyinst.spec-tpl +++ b/smart_kit/template/app.pyinst.spec-tpl @@ -1,32 +1,7 @@ # -*- mode: python ; coding: utf-8 -*- +from smart_kit.utils.pyinst import SAF_data_files -import os -import importlib - - -def data_files_for_packages(package_files: dict) -> list: - datas = [] - for package, files in package_files.items(): - proot = os.path.dirname(importlib.import_module(package).__file__) if package != '' else '' - datas.extend( - ( - os.path.join(proot, f), # Source file pattern - os.path.join(package, os.path.dirname(f)) # Dest relative folder - ) for f in files) - return datas - - -# This is not necessarily actual files but path patters -datas = data_files_for_packages({ - # Our app - '': ['static/.'], - # 3rd-party libs - 'ics': ['grammar/contentline.ebnf'], - 'pymorphy2_dicts': ['data/*.json', 'data/*.array', 'data/*.dawg', 'data/*.intdawg'], - 'rnnmorph': ['models/.'], -}) - -print(f'\n - Data files: {datas}\n') +datas = SAF_data_files block_cipher = None @@ -70,8 +45,8 @@ coll = COLLECT( a.binaries, a.zipfiles, a.datas, + name='app', strip=False, upx=True, upx_exclude=[], - name='manage' ) diff --git a/smart_kit/utils/pyinst.py b/smart_kit/utils/pyinst.py new file mode 100644 index 00000000..04694795 --- /dev/null +++ b/smart_kit/utils/pyinst.py @@ -0,0 +1,25 @@ +import os +import importlib + + +def data_files_for_packages(package_files: dict) -> list: + datas = [] + for package, files in package_files.items(): + proot = os.path.dirname(importlib.import_module(package).__file__) if package != '' else '' + datas.extend( + ( + os.path.join(proot, f), # Source file pattern + os.path.join(package, os.path.dirname(f)) # Dest relative folder + ) for f in files) + return datas + + +# This is not necessarily actual files but path patters +SAF_data_files = data_files_for_packages({ + # Our app + '': ['static/.'], + # 3rd-party libs + 'ics': ['grammar/contentline.ebnf'], + 'pymorphy2_dicts': ['data/*.json', 'data/*.array', 'data/*.dawg', 'data/*.intdawg'], + 'rnnmorph': ['models/.'], +}) From 74b8a2fba642c6f7e48da18f448a26d3d67591ac Mon Sep 17 00:00:00 2001 From: AivanF Date: Tue, 10 Aug 2021 09:46:23 +0300 Subject: [PATCH 4/4] Added SAF template folder to data files --- smart_kit/utils/pyinst.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/smart_kit/utils/pyinst.py b/smart_kit/utils/pyinst.py index 04694795..cdd35495 100644 --- a/smart_kit/utils/pyinst.py +++ b/smart_kit/utils/pyinst.py @@ -18,6 +18,8 @@ def data_files_for_packages(package_files: dict) -> list: SAF_data_files = data_files_for_packages({ # Our app '': ['static/.'], + # Our lib + 'smart_kit': ['template/.'], # 3rd-party libs 'ics': ['grammar/contentline.ebnf'], 'pymorphy2_dicts': ['data/*.json', 'data/*.array', 'data/*.dawg', 'data/*.intdawg'],