Fix issues importing PySide in Docker container (#322)

* Rather than installing PyQT dependencies, remove codepaths that require pyqt files in no-gui mode
This commit is contained in:
sabaimran
2023-07-15 13:33:13 -07:00
committed by GitHub
parent ba47f2ab39
commit 49ab201c30
2 changed files with 21 additions and 21 deletions

View File

@@ -7,6 +7,19 @@ from PySide6.QtCore import Qt
# Internal Packages # Internal Packages
from khoj.utils import constants from khoj.utils import constants
from PySide6.QtCore import QThread
class ServerThread(QThread):
def __init__(self, start_server_func):
super(ServerThread, self).__init__()
self.start_server_func = start_server_func
def __del__(self):
self.wait()
def run(self):
self.start_server_func()
class MainWindow(QtWidgets.QMainWindow): class MainWindow(QtWidgets.QMainWindow):

View File

@@ -21,8 +21,6 @@ warnings.filterwarnings("ignore", message=r"legacy way to download files from th
# External Packages # External Packages
import uvicorn import uvicorn
from fastapi import FastAPI from fastapi import FastAPI
from PySide6 import QtWidgets
from PySide6.QtCore import QThread, QTimer
from rich.logging import RichHandler from rich.logging import RichHandler
import schedule import schedule
@@ -30,9 +28,6 @@ import schedule
from khoj.configure import configure_routes, configure_server from khoj.configure import configure_routes, configure_server
from khoj.utils import state from khoj.utils import state
from khoj.utils.cli import cli from khoj.utils.cli import cli
from khoj.interface.desktop.main_window import MainWindow
from khoj.interface.desktop.system_tray import create_system_tray
# Initialize the Application Server # Initialize the Application Server
app = FastAPI() app = FastAPI()
@@ -79,6 +74,11 @@ def run():
configure_routes(app) configure_routes(app)
start_server(app, host=args.host, port=args.port, socket=args.socket) start_server(app, host=args.host, port=args.port, socket=args.socket)
else: else:
from PySide6 import QtWidgets
from PySide6.QtCore import QThread, QTimer
from khoj.interface.desktop.main_window import MainWindow, ServerThread
from khoj.interface.desktop.system_tray import create_system_tray
# Setup GUI # Setup GUI
gui = QtWidgets.QApplication([]) gui = QtWidgets.QApplication([])
main_window = MainWindow(args.host, args.port) main_window = MainWindow(args.host, args.port)
@@ -95,7 +95,7 @@ def run():
# Setup Server # Setup Server
configure_server(args, required=False) configure_server(args, required=False)
configure_routes(app) configure_routes(app)
server = ServerThread(app, args.host, args.port, args.socket) server = ServerThread(start_server_func=lambda: start_server(app, host=args.host, port=args.port))
url = f"http://{args.host}:{args.port}" url = f"http://{args.host}:{args.port}"
logger.info(f"🌗 Khoj is running at {url}") logger.info(f"🌗 Khoj is running at {url}")
@@ -136,6 +136,8 @@ def run():
def sigint_handler(*args): def sigint_handler(*args):
from PySide6 import QtWidgets
QtWidgets.QApplication.quit() QtWidgets.QApplication.quit()
@@ -164,21 +166,6 @@ def poll_task_scheduler():
schedule.run_pending() schedule.run_pending()
class ServerThread(QThread):
def __init__(self, app, host=None, port=None, socket=None):
super(ServerThread, self).__init__()
self.app = app
self.host = host
self.port = port
self.socket = socket
def __del__(self):
self.wait()
def run(self):
start_server(self.app, self.host, self.port, self.socket)
def run_gui(): def run_gui():
sys.argv += ["--gui"] sys.argv += ["--gui"]
run() run()