Browse Source

refactor: rename check_mac_env to check_sys_env and add Windows environment detection

myhloli 3 weeks ago
parent
commit
c32ff88400
4 changed files with 18 additions and 14 deletions
  1. 1 1
      mineru/cli/client.py
  2. 12 12
      mineru/cli/common.py
  3. 1 1
      mineru/cli/gradio_app.py
  4. 4 0
      mineru/utils/check_sys_env.py

+ 1 - 1
mineru/cli/client.py

@@ -4,7 +4,7 @@ import click
 from pathlib import Path
 from pathlib import Path
 from loguru import logger
 from loguru import logger
 
 
-from mineru.utils.check_mac_env import is_mac_os_version_supported
+from mineru.utils.check_sys_env import is_mac_os_version_supported
 from mineru.utils.cli_parser import arg_parse
 from mineru.utils.cli_parser import arg_parse
 from mineru.utils.config_reader import get_device
 from mineru.utils.config_reader import get_device
 from mineru.utils.guess_suffix_or_lang import guess_suffix_by_path
 from mineru.utils.guess_suffix_or_lang import guess_suffix_by_path

+ 12 - 12
mineru/cli/common.py

@@ -11,6 +11,7 @@ import pypdfium2 as pdfium
 from loguru import logger
 from loguru import logger
 
 
 from mineru.data.data_reader_writer import FileBasedDataWriter
 from mineru.data.data_reader_writer import FileBasedDataWriter
+from mineru.utils.check_sys_env import is_windows_environment
 from mineru.utils.draw_bbox import draw_layout_bbox, draw_span_bbox, draw_line_sort_bbox
 from mineru.utils.draw_bbox import draw_layout_bbox, draw_span_bbox, draw_line_sort_bbox
 from mineru.utils.enum_class import MakeMode
 from mineru.utils.enum_class import MakeMode
 from mineru.utils.guess_suffix_or_lang import guess_suffix_by_bytes
 from mineru.utils.guess_suffix_or_lang import guess_suffix_by_bytes
@@ -83,20 +84,19 @@ def _convert_pdf_in_process(args):
 def _prepare_pdf_bytes(pdf_bytes_list, start_page_id, end_page_id):
 def _prepare_pdf_bytes(pdf_bytes_list, start_page_id, end_page_id):
     """准备处理PDF字节数据"""
     """准备处理PDF字节数据"""
     start_time = time.time()
     start_time = time.time()
-    # 准备参数列表
-    args_list = [(pdf_bytes, start_page_id, end_page_id) for pdf_bytes in pdf_bytes_list]
-
-    # 使用进程池执行转换
-    with Pool(processes=min(len(pdf_bytes_list), min(os.cpu_count() or 1, 4))) as pool:
-        result = pool.map(_convert_pdf_in_process, args_list)
+    result = []
+    if is_windows_environment():
+        for pdf_bytes in pdf_bytes_list:
+            new_pdf_bytes = convert_pdf_bytes_to_bytes_by_pypdfium2(pdf_bytes, start_page_id, end_page_id)
+            result.append(new_pdf_bytes)
+    else:
+        # 准备参数列表
+        args_list = [(pdf_bytes, start_page_id, end_page_id) for pdf_bytes in pdf_bytes_list]
 
 
-    logger.debug(f"Prepare PDF bytes cost: {round(time.time() - start_time, 2)}s")
+        # 使用进程池执行转换
+        with Pool(processes=min(len(pdf_bytes_list), min(os.cpu_count() or 1, 4))) as pool:
+            result = pool.map(_convert_pdf_in_process, args_list)
 
 
-    start_time = time.time()
-    result = []
-    for pdf_bytes in pdf_bytes_list:
-        new_pdf_bytes = convert_pdf_bytes_to_bytes_by_pypdfium2(pdf_bytes, start_page_id, end_page_id)
-        result.append(new_pdf_bytes)
     logger.debug(f"Prepare PDF bytes cost: {round(time.time() - start_time, 2)}s")
     logger.debug(f"Prepare PDF bytes cost: {round(time.time() - start_time, 2)}s")
 
 
     return result
     return result

+ 1 - 1
mineru/cli/gradio_app.py

@@ -13,7 +13,7 @@ from gradio_pdf import PDF
 from loguru import logger
 from loguru import logger
 
 
 from mineru.cli.common import prepare_env, read_fn, aio_do_parse, pdf_suffixes, image_suffixes
 from mineru.cli.common import prepare_env, read_fn, aio_do_parse, pdf_suffixes, image_suffixes
-from mineru.utils.check_mac_env import is_mac_os_version_supported
+from mineru.utils.check_sys_env import is_mac_os_version_supported
 from mineru.utils.cli_parser import arg_parse
 from mineru.utils.cli_parser import arg_parse
 from mineru.utils.hash_utils import str_sha256
 from mineru.utils.hash_utils import str_sha256
 
 

+ 4 - 0
mineru/utils/check_mac_env.py → mineru/utils/check_sys_env.py

@@ -4,6 +4,10 @@ import platform
 from packaging import version
 from packaging import version
 
 
 
 
+def is_windows_environment() -> bool:
+    return platform.system() == "Windows"
+
+
 # Detect if the current environment is a Mac computer
 # Detect if the current environment is a Mac computer
 def is_mac_environment() -> bool:
 def is_mac_environment() -> bool:
     return platform.system() == "Darwin"
     return platform.system() == "Darwin"