liuyuqi-cnb 2 months ago
parent
commit
ca210acb93
4 changed files with 83 additions and 10 deletions
  1. 13 0
      build.bat
  2. 13 0
      build.sh
  3. 17 8
      main_gui.py
  4. 40 2
      setup.py

+ 13 - 0
build.bat

@@ -0,0 +1,13 @@
+@echo off
+echo Building repo_sync GUI executable...
+
+REM Install required packages
+pip install pyinstaller
+pip install -e .
+
+REM Build the executable
+pyinstaller --onefile --windowed --name "RepoSync" --icon=icon.ico --add-data "repo_sync/config.yml;repo_sync" main_gui.py
+
+echo.
+echo Build completed! The executable is in the dist folder.
+echo. 

+ 13 - 0
build.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+echo "Building repo_sync GUI executable..."
+
+# Install required packages
+pip install pyinstaller
+pip install -e .
+
+# Build the executable
+pyinstaller --onefile --windowed --name "RepoSync" --add-data "repo_sync/config.yml:repo_sync" main_gui.py
+
+echo ""
+echo "Build completed! The executable is in the dist folder."
+echo "" 

+ 17 - 8
main_gui.py

@@ -8,10 +8,17 @@
 
 打包说明:
 使用PyInstaller可以将此应用打包为单个可执行文件:
-1. 安装PyInstaller: pip install pyinstaller
-2. 打包命令: pyinstaller --onefile --windowed --icon=icon.ico main_gui.py
+1. 安装必要的包: 
+   pip install pyinstaller
+   pip install -e .  # 以开发模式安装当前包
+
+2. 打包命令: 
+   pyinstaller --onefile --windowed --icon=icon.ico --add-data "repo_sync/config.yml;repo_sync" main_gui.py
    (如果有图标文件,可以通过--icon参数指定)
+
 3. 打包后的可执行文件将位于dist目录中
+
+注意:确保在打包前先安装repo_sync包,这样PyInstaller才能正确找到所有依赖。
 '''
 import sys
 import os
@@ -32,7 +39,7 @@ except ImportError:
     print("PyQt5 not installed, GUI mode not available")
 
 # 直接导入repo_sync模块
-sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 try:
     from repo_sync.repo_sync import RepoSync
     from repo_sync.version import __version__
@@ -41,8 +48,8 @@ except ImportError:
     print("无法导入repo_sync模块,尝试直接导入...")
     try:
         from repo_sync import RepoSync
-        from repo_sync.version import __version__
-        from repo_sync.utils.config_reader import ConfigReader
+        from version import __version__
+        from utils.config_reader import ConfigReader
     except ImportError:
         print("导入repo_sync模块失败,请确保repo_sync已正确安装")
         __version__ = "未知"
@@ -609,12 +616,14 @@ class MainTab(QWidget):
 
     def run_module(self, args):
         try:
-            from repo_sync import main
+            # 正确导入repo_sync模块的main函数
+            from repo_sync.repo_sync import RepoSync
             self.running = True
             return_code = 0
             try:
-                # 调用 repo_sync 的 main 函数
-                main(args)
+                # 直接创建RepoSync实例并运行
+                rs = RepoSync(args)
+                rs.run()
             except SystemExit as e:
                 return_code = e.code if isinstance(e.code, int) else 1
             except Exception as e:

+ 40 - 2
setup.py

@@ -1,6 +1,44 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
 from setuptools import setup, find_packages
+import os
+
+# 获取版本号
+version = {}
+with open(os.path.join("repo_sync", "version.py")) as f:
+    exec(f.read(), version)
 
 setup(
-    name='repo_sync',
-    enter_points={'console_scripts': ['repo_sync = repo_sync:main']},
+    name="repo_sync",
+    version=version.get("__version__", "0.0.1"),
+    description="Repository synchronization tool",
+    author="liuyuqi",
+    author_email="liuyuqi.gov@msn.cn",
+    url="https://github.com/jianboy/repo_sync",
+    packages=find_packages(),
+    install_requires=[
+        "PyYAML",
+        "PyQt5",
+        "pywin32;platform_system=='Windows'",
+    ],
+    entry_points={
+        "console_scripts": [
+            "repo_sync=repo_sync:main",
+        ],
+        "gui_scripts": [
+            "repo_sync_gui=main_gui:main",
+        ],
+    },
+    classifiers=[
+        "Development Status :: 4 - Beta",
+        "Intended Audience :: Developers",
+        "License :: OSI Approved :: MIT License",
+        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
+    ],
+    python_requires=">=3.6",
 )