diff --git a/setup.py b/setup.py index d69a2526..b5fa28d2 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ "dawg==0.8.0", "dill==0.3.3", "ics==0.6", - "jaeger_client==4.3.0", + "jaeger_client==4.6.0", "Jinja2==2.10.1", "keras==2.6.0", "lazy", @@ -53,7 +53,8 @@ "tensorflow==2.6.0", "timeout-decorator==0.4.1", "tqdm", - "Twisted" + "Twisted", + "pyinstaller=4.5", ], classifiers=[ "Programming Language :: Python :: 3.6", diff --git a/smart_kit/start_points/main_loop_http.py b/smart_kit/start_points/main_loop_http.py index 40adeccd..ff98fe38 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 @@ -153,4 +154,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/template/app.pyinst.spec-tpl b/smart_kit/template/app.pyinst.spec-tpl new file mode 100644 index 00000000..e5600ed7 --- /dev/null +++ b/smart_kit/template/app.pyinst.spec-tpl @@ -0,0 +1,52 @@ +# -*- mode: python ; coding: utf-8 -*- +from smart_kit.utils.pyinst import SAF_data_files + +datas = SAF_data_files + +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, + name='app', + strip=False, + upx=True, + upx_exclude=[], +) 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) diff --git a/smart_kit/utils/pyinst.py b/smart_kit/utils/pyinst.py new file mode 100644 index 00000000..cdd35495 --- /dev/null +++ b/smart_kit/utils/pyinst.py @@ -0,0 +1,27 @@ +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/.'], + # Our lib + 'smart_kit': ['template/.'], + # 3rd-party libs + 'ics': ['grammar/contentline.ebnf'], + 'pymorphy2_dicts': ['data/*.json', 'data/*.array', 'data/*.dawg', 'data/*.intdawg'], + 'rnnmorph': ['models/.'], +})