diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a58e64..801ead3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,10 @@ jobs: - name: Run tests run: | - python -m ok.test.RunTests + Get-ChildItem -Path ".\tests\*.py" | ForEach-Object { + Write-Host "Running tests in $($_.FullName)" + python -m unittest $_.FullName + } - name: Build Executable run: | diff --git a/main.py b/main.py index b0c8b1b..80fef6d 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ -from config import config -from ok import OK +if __name__ == '__main__': + from config import config + from ok import OK -config = config -ok = OK(config) -ok.start() + config = config + ok = OK(config) + ok.start() diff --git a/main.spec b/main.spec deleted file mode 100644 index b9c5657..0000000 --- a/main.spec +++ /dev/null @@ -1,155 +0,0 @@ -# -*- mode: pythzon ; coding: utf-8 -*- -from pathlib import Path -import importlib.util -block_cipher = None - -def check_package_exists(package_name): - package_spec = importlib.util.find_spec(package_name) - return package_spec is not None - -# Example usage: -if check_package_exists('rapidocr_openvino'): - print("rapidocr_openvino exists") - - import rapidocr_openvino - - - - - package_name = 'rapidocr_openvino' - install_dir = Path(rapidocr_openvino.__file__).resolve().parent - - onnx_paths = list(install_dir.rglob('*.onnx')) + list(install_dir.rglob('*.txt')) - yaml_paths = list(install_dir.rglob('*.yaml')) - - onnx_add_data = [(str(v.parent), f'{package_name}/{v.parent.name}') - for v in onnx_paths] - - yaml_add_data = [] - for v in yaml_paths: - if package_name == v.parent.name: - yaml_add_data.append((str(v.parent / '*.yaml'), package_name)) - else: - yaml_add_data.append( - (str(v.parent / '*.yaml'), f'{package_name}/{v.parent.name}')) - - import openvino - - - package_name = 'openvino' - install_dir = Path(openvino.__file__).resolve().parent - - openvino_dll_path = list(install_dir.rglob('openvino_intel_cpu_plugin.dll')) + list(install_dir.rglob('openvino_onnx_frontend.dll')) - - - # Modified list comprehension with a condition check - openvino_add_data = [(str(v), f'{package_name}/{v.parent.name}') - for v in openvino_dll_path] - - print(f'openvino_add_data {openvino_add_data}') - add_data = list(set(yaml_add_data + onnx_add_data + openvino_add_data)) -else: - add_data = [] - -excludes = ['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter', 'resources', 'matplotlib','numpy.lib'] -add_data.append(('icon.png', '.')) - -import ok -ok_dir = Path(ok.__file__).resolve().parent -binaries = os.path.join(ok_dir, 'binaries', '*') -print(f'ok_dir {ok_dir}') -add_data.append((binaries, 'ok/binaries')) - -def list_files(directory, prefix='', extensions=[]): - file_list = [] - for root, dirs, files in os.walk(directory): - for filename in files: - # Check the file extension - _, ext = os.path.splitext(filename) - if extensions and ext not in extensions: - continue - - # Create the full filepath by joining root with the filename - filepath = os.path.join(root, filename) - - # Create the relative path for the file to be used in the spec datas - relative_path = os.path.relpath(filepath, prefix) - folder_path = os.path.dirname(relative_path) - - # Append the tuple (full filepath, relative path) to the file list - file_list.append((filepath, folder_path)) - return file_list - -if os.path.exists('assets'): - root_folder = os.getcwd() # Get the current working directory - assets = list_files(os.path.join(root_folder, 'assets'), root_folder) - add_data += assets - -if os.path.exists('i18n'): - root_folder = os.getcwd() # Get the current working directory - assets = list_files(os.path.join(root_folder, 'i18n'), root_folder, ['.mo']) - add_data += assets - -print(f"add_data {add_data}") - -a = Analysis( - ['main.py'], - pathex=[], - binaries=[], - datas=add_data, - hiddenimports=[], - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - cipher=block_cipher, - noarchive=False, - noconsole=True, -) - - -# List of patterns to exclude -exclude_patterns = ['opencv_videoio_ffmpeg', 'opengl32sw.dll', 'Qt6Quick.dll','Qt6Pdf.dll','Qt6Qml.dll','Qt6OpenGL.dll','Qt6Network.dll','Qt6QmlModels.dll','Qt6VirtualKeyboard.dll','QtNetwork.pyd' -,'openvino_pytorch_frontend.dll','openvino_tensorflow_frontend.dll','py_tensorflow_frontend.cp311-win_amd64.pyd','py_pytorch_frontend.cp311-win_amd64.pyd', -] - - -# Optimized list comprehension using any() with a generator expression -a.binaries = [x for x in a.binaries if not any(pattern in x[0] for pattern in exclude_patterns)] - -print(f'a.binaries {a.binaries}') - -pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) - -from config import config - -exe = EXE( - pyz, - a.scripts, - [], - exclude_binaries=True, - name='ok-ww', - icon='icon.png', - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - console=False, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, - uac_admin=True, -) - -coll = COLLECT( - exe, - a.binaries, - a.datas, - strip=False, - upx=True, - upx_exclude=[], - name='bundle', -) - diff --git a/main_debug.py b/main_debug.py index 4b59311..fb3fcde 100644 --- a/main_debug.py +++ b/main_debug.py @@ -1,8 +1,9 @@ -from config import config -from ok.OK import OK +if __name__ == '__main__': + from config import config + from ok.OK import OK -config = config -config['debug'] = True -# config['click_screenshots_folder'] = "click_screenshots" # debug用 点击后截图文件夹] -ok = OK(config) -ok.start() + config = config + config['debug'] = True + # config['click_screenshots_folder'] = "click_screenshots" # debug用 点击后截图文件夹] + ok = OK(config) + ok.start() diff --git a/main_debug.spec b/main_debug.spec deleted file mode 100644 index 7132e51..0000000 --- a/main_debug.spec +++ /dev/null @@ -1,128 +0,0 @@ -# -*- mode: python ; coding: utf-8 -*- -from pathlib import Path -import rapidocr_openvino - - -block_cipher = None - -package_name = 'rapidocr_openvino' -install_dir = Path(rapidocr_openvino.__file__).resolve().parent - -onnx_paths = list(install_dir.rglob('*.onnx')) + list(install_dir.rglob('*.txt')) -yaml_paths = list(install_dir.rglob('*.yaml')) - -onnx_add_data = [(str(v.parent), f'{package_name}/{v.parent.name}') - for v in onnx_paths] - -yaml_add_data = [] -for v in yaml_paths: - if package_name == v.parent.name: - yaml_add_data.append((str(v.parent / '*.yaml'), package_name)) - else: - yaml_add_data.append( - (str(v.parent / '*.yaml'), f'{package_name}/{v.parent.name}')) - -import openvino - -block_cipher = None - -package_name = 'openvino' -install_dir = Path(openvino.__file__).resolve().parent - -openvino_dll_path = list(install_dir.rglob('openvino_intel_cpu_plugin.dll')) + list(install_dir.rglob('openvino_onnx_frontend.dll')) - - -# Modified list comprehension with a condition check -openvino_add_data = [(str(v), f'{package_name}/{v.parent.name}') - for v in openvino_dll_path] - -print(f'openvino_add_data {openvino_add_data}') -add_data = list(set(yaml_add_data + onnx_add_data + openvino_add_data)) - -excludes = ['FixTk', 'tcl', 'tk', '_tkinter', 'tkinter', 'Tkinter', 'resources', 'matplotlib','numpy.lib'] -add_data.append(('icon.ico', '.')) - -import ok -ok_dir = Path(ok.__file__).resolve().parent -binaries = os.path.join(ok_dir, 'binaries', '*') -print(f'ok_dir {ok_dir}') -add_data.append((binaries, 'ok/binaries')) - -def list_files(directory, prefix=''): - file_list = [] - for root, dirs, files in os.walk(directory): - for filename in files: - # Create the full filepath by joining root with the filename - filepath = os.path.join(root, filename) - # Create the relative path for the file to be used in the spec datas - relative_path = os.path.relpath(filepath, prefix) - folder_path = os.path.dirname(relative_path) - # Append the tuple (full filepath, relative path) to the file list - file_list.append((filepath, folder_path)) - return file_list - -if os.path.exists('assets'): - root_folder = os.getcwd() # Get the current working directory - assets = list_files(os.path.join(root_folder, 'assets'), root_folder) - add_data += assets - -print(f"add_data {add_data}") - -a = Analysis( - ['main_debug.py'], - pathex=[], - binaries=[], - datas=add_data, - hiddenimports=[], - hookspath=[], - hooksconfig={}, - runtime_hooks=[], - excludes=[], - cipher=block_cipher, - noarchive=False, - noconsole=True, -) - - -# List of patterns to exclude -exclude_patterns = ['opencv_videoio_ffmpeg', 'opengl32sw.dll', 'Qt6Quick.dll','Qt6Pdf.dll','Qt6Qml.dll','Qt6OpenGL.dll','Qt6Network.dll','Qt6QmlModels.dll','Qt6VirtualKeyboard.dll','QtNetwork.pyd' -,'openvino_pytorch_frontend.dll','openvino_tensorflow_frontend.dll','py_tensorflow_frontend.cp311-win_amd64.pyd','py_pytorch_frontend.cp311-win_amd64.pyd', -] - - -# Optimized list comprehension using any() with a generator expression -a.binaries = [x for x in a.binaries if not any(pattern in x[0] for pattern in exclude_patterns)] - -print(f'a.binaries {a.binaries}') - -pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) - -exe = EXE( - pyz, - a.scripts, - [], - exclude_binaries=True, - name='ok-baijing', - icon='icon.ico', - debug=False, - bootloader_ignore_signals=False, - strip=False, - upx=True, - console=True, - disable_windowed_traceback=False, - argv_emulation=False, - target_arch=None, - codesign_identity=None, - entitlements_file=None, -) - -coll = COLLECT( - exe, - a.binaries, - a.datas, - strip=False, - upx=True, - upx_exclude=[], - name='bundle', -) - diff --git a/main_gpu.py b/main_gpu.py index 73582e8..14836c0 100644 --- a/main_gpu.py +++ b/main_gpu.py @@ -1,7 +1,8 @@ -from config import config -from ok.OK import OK +if __name__ == '__main__': + from config import config + from ok.OK import OK -config = config -config['ocr']['lib'] = 'paddleocr' -ok = OK(config) -ok.start() + config = config + config['ocr']['lib'] = 'paddleocr' + ok = OK(config) + ok.start() diff --git a/main_gpu_debug.py b/main_gpu_debug.py index a90af07..b1eef3b 100644 --- a/main_gpu_debug.py +++ b/main_gpu_debug.py @@ -1,8 +1,9 @@ -from config import config -from ok.OK import OK +if __name__ == '__main__': + from config import config + from ok.OK import OK -config = config -config['debug'] = True -config['ocr']['lib'] = 'paddleocr' -ok = OK(config) -ok.start() + config = config + config['debug'] = True + config['ocr']['lib'] = 'paddleocr' + ok = OK(config) + ok.start() diff --git a/requirements.txt b/requirements.txt index a18b2cd..a1a11b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -ok-script==0.0.395 +ok-script==0.0.396 #rapidocr_onnxruntime rapidocr_openvino pySide6-Fluent-Widgets>=1.5.5 @@ -8,4 +8,5 @@ psutil WMI>=1.5.1 typing-extensions>=4.11.0 numpy>=1.26.4 -opencv-contrib-python>=4.10.0.84 \ No newline at end of file +opencv-contrib-python>=4.10.0.84 +requests \ No newline at end of file