fix: improve path handling for PyInstaller compatibility

This commit is contained in:
2026-03-06 19:31:50 +01:00
parent 1b6c7dcc01
commit 16abf010ab
2 changed files with 18 additions and 5 deletions

View File

@@ -1,7 +1,15 @@
import json
import os
import sys
CONFIG_FILE = "config.json"
def get_app_dir():
if getattr(sys, 'frozen', False):
return os.path.dirname(sys.executable)
else:
# If in git_monitor package, go up to the project root
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_FILE = os.path.join(get_app_dir(), "config.json")
class Config:
def __init__(self):

View File

@@ -3,9 +3,14 @@ import os
import sys
def setup_logger():
log_file = "git_monitor.log"
# Ensure log is in the application directory
log_path = os.path.abspath(log_file)
# Find application directory
if getattr(sys, 'frozen', False):
app_dir = os.path.dirname(sys.executable)
else:
# If in a package, go up one level to the root
app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
log_file = os.path.join(app_dir, "git_monitor.log")
logger = logging.getLogger("GitMonitor")
logger.setLevel(logging.INFO)
@@ -13,7 +18,7 @@ def setup_logger():
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
# File handler
file_handler = logging.FileHandler(log_path)
file_handler = logging.FileHandler(log_file)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)