From 33dbb082a533542eacd1dff376574e8ad8cf4ece Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Nov 2025 18:56:45 -0800 Subject: [PATCH] ... --- app.py | 10 ---------- lib/utils.py | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app.py b/app.py index 60e15f72..3aa0039d 100644 --- a/app.py +++ b/app.py @@ -187,16 +187,6 @@ Tip: to add of silence (1.4 seconds) into your text just use "###" or "[pause]". print(f"v{prog_version} {args['script_mode']} mode") - #if args['script_mode'] == NATIVE: - # check_pkg = check_and_install_requirements(requirements_file) - # if check_pkg: - # if not check_dictionary(): - # sys.exit(1) - # else: - # error = 'Some packages could not be installed' - # print(error) - # sys.exit(1) - import lib.functions as f f.context = f.SessionContext() if f.context is None else f.context f.context_tracker = f.SessionTracker() if f.context_tracker is None else f.context_tracker diff --git a/lib/utils.py b/lib/utils.py index 0c3fa942..7a0c5f5f 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,9 +1,6 @@ import os, re, sys, platform, shutil, importlib -from packaging.version import Version, InvalidVersion -from importlib.metadata import version, PackageNotFoundError -from packaging.specifiers import SpecifierSet -from packaging.markers import Marker +from lib.conf import * def detect_platform_tag()->str: if sys.platform.startswith('win'): @@ -292,27 +289,31 @@ def check_torch()->bool: except subprocess.CalledProcessError as e: error = f'Failed to install torch package: {e}' print(error) - return False - return True + sys.exit(1) + sys.exit(0) except ImportError: error = f'check_torch(): torch not yet installed...' print(error) - return False + sys.exit(1) except InvalidVersion: error = f'check_torch(): Torch or Numpy error Version.' print(error) - return False + sys.exit(1) except Exception as e: error = f'check_torch() error: {e}' print(error) - return False + sys.exit(1) def check_and_install_requirements(file_path:str)->bool: if not os.path.exists(file_path): error = f'Warning: File {file_path} not found. Skipping package check.' print(error) - return False + sys.exit(1) try: + from packaging.version import Version, InvalidVersion + from importlib.metadata import version, PackageNotFoundError + from packaging.specifiers import SpecifierSet + from packaging.markers import Marker try: from tqdm import tqdm except ImportError: @@ -424,14 +425,18 @@ def check_and_install_requirements(file_path:str)->bool: continue error = f'Failed to install {package}: {e}' print(error) - return False + sys.exit(1) msg = '\nAll required packages are installed.' print(msg) + if not check_dictionary(): + error = 'Could not load unidic dictionary' + print(error) + sys.exit(1) return check_torch() except Exception as e: error = f'check_and_install_requirements() error: {e}' - raise SystemExit(error) - return False + print(error) + sys.exit(1) def check_dictionary()->bool: import unidic @@ -444,6 +449,12 @@ def check_dictionary()->bool: subprocess.run(['python', '-m', 'unidic', 'download'], check=True) except (subprocess.CalledProcessError, ConnectionError, OSError) as e: error = f'Failed to download UniDic dictionary. Error: {e}. Unable to continue without UniDic. Exiting...' - raise SystemExit(error) + print(error) return False - return True \ No newline at end of file + return True + +def main(): + check_and_install_requirements(requirements_file) + +if __name__ == "__main__": + main() \ No newline at end of file