mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Fix or ignore MyPy issues in PyQt desktop GUI code
- Remove unneeded type ignore for mps with the latest mypy - Stop excluding PyQT desktop GUI code from MyPy checks - Do not warn about unused ignores. Some issue with mypy giving different errors in different environments (venv, system and pre-commit)
This commit is contained in:
parent
fd0a2f55f8
commit
36be3c4b8f
5 changed files with 18 additions and 23 deletions
|
@ -87,12 +87,7 @@ install_types = true
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
non_interactive = true
|
non_interactive = true
|
||||||
show_error_codes = true
|
show_error_codes = true
|
||||||
warn_unused_ignores = true
|
warn_unused_ignores = false
|
||||||
exclude = [
|
|
||||||
"src/khoj/interface/desktop/main_window.py",
|
|
||||||
"src/khoj/interface/desktop/file_browser.py",
|
|
||||||
"src/khoj/interface/desktop/system_tray.py",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
|
@ -27,11 +27,11 @@ class FileBrowser(QtWidgets.QWidget):
|
||||||
self.lineEdit.setFixedWidth(330)
|
self.lineEdit.setFixedWidth(330)
|
||||||
self.setFiles(default_files)
|
self.setFiles(default_files)
|
||||||
self.lineEdit.setFixedHeight(min(7 + 20 * len(self.lineEdit.toPlainText().split("\n")), 90))
|
self.lineEdit.setFixedHeight(min(7 + 20 * len(self.lineEdit.toPlainText().split("\n")), 90))
|
||||||
self.lineEdit.textChanged.connect(self.updateFieldHeight)
|
self.lineEdit.textChanged.connect(self.updateFieldHeight) # type: ignore[attr-defined]
|
||||||
layout.addWidget(self.lineEdit)
|
layout.addWidget(self.lineEdit)
|
||||||
|
|
||||||
self.button = QtWidgets.QPushButton("Add")
|
self.button = QtWidgets.QPushButton("Add")
|
||||||
self.button.clicked.connect(self.storeFilesSelectedInFileDialog)
|
self.button.clicked.connect(self.storeFilesSelectedInFileDialog) # type: ignore[attr-defined]
|
||||||
layout.addWidget(self.button)
|
layout.addWidget(self.button)
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self.setWindowIcon(QtGui.QIcon(f"{icon_path.absolute()}"))
|
self.setWindowIcon(QtGui.QIcon(f"{icon_path.absolute()}"))
|
||||||
|
|
||||||
# Initialize Configure Window Layout
|
# Initialize Configure Window Layout
|
||||||
self.layout = QtWidgets.QVBoxLayout()
|
self.wlayout = QtWidgets.QVBoxLayout()
|
||||||
|
|
||||||
# Add Settings Panels for each Search Type to Configure Window Layout
|
# Add Settings Panels for each Search Type to Configure Window Layout
|
||||||
self.search_settings_panels = []
|
self.search_settings_panels = []
|
||||||
|
@ -73,7 +73,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
# Set the central widget of the Window. Widget will expand
|
# Set the central widget of the Window. Widget will expand
|
||||||
# to take up all the space in the window by default.
|
# to take up all the space in the window by default.
|
||||||
self.config_window = QtWidgets.QWidget()
|
self.config_window = QtWidgets.QWidget()
|
||||||
self.config_window.setLayout(self.layout)
|
self.config_window.setLayout(self.wlayout)
|
||||||
self.setCentralWidget(self.config_window)
|
self.setCentralWidget(self.config_window)
|
||||||
self.position_window()
|
self.position_window()
|
||||||
|
|
||||||
|
@ -97,12 +97,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
# Set enabled/disabled based on checkbox state
|
# Set enabled/disabled based on checkbox state
|
||||||
enable_search_type.setChecked(current_content_files is not None and len(current_content_files) > 0)
|
enable_search_type.setChecked(current_content_files is not None and len(current_content_files) > 0)
|
||||||
input_files.setEnabled(enable_search_type.isChecked())
|
input_files.setEnabled(enable_search_type.isChecked())
|
||||||
enable_search_type.stateChanged.connect(lambda _: input_files.setEnabled(enable_search_type.isChecked()))
|
enable_search_type.stateChanged.connect(lambda _: input_files.setEnabled(enable_search_type.isChecked())) # type: ignore[attr-defined]
|
||||||
|
|
||||||
# Add setting widgets for given search type to panel
|
# Add setting widgets for given search type to panel
|
||||||
search_type_layout.addWidget(enable_search_type)
|
search_type_layout.addWidget(enable_search_type)
|
||||||
search_type_layout.addWidget(input_files)
|
search_type_layout.addWidget(input_files)
|
||||||
self.layout.addWidget(search_type_settings)
|
self.wlayout.addWidget(search_type_settings)
|
||||||
|
|
||||||
return search_type_settings
|
return search_type_settings
|
||||||
|
|
||||||
|
@ -121,12 +121,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
# Set enabled/disabled based on checkbox state
|
# Set enabled/disabled based on checkbox state
|
||||||
enable_conversation.setChecked(current_openai_api_key is not None)
|
enable_conversation.setChecked(current_openai_api_key is not None)
|
||||||
input_field.setEnabled(enable_conversation.isChecked())
|
input_field.setEnabled(enable_conversation.isChecked())
|
||||||
enable_conversation.stateChanged.connect(lambda _: input_field.setEnabled(enable_conversation.isChecked()))
|
enable_conversation.stateChanged.connect(lambda _: input_field.setEnabled(enable_conversation.isChecked())) # type: ignore[attr-defined]
|
||||||
|
|
||||||
# Add setting widgets for given processor type to panel
|
# Add setting widgets for given processor type to panel
|
||||||
processor_type_layout.addWidget(enable_conversation)
|
processor_type_layout.addWidget(enable_conversation)
|
||||||
processor_type_layout.addWidget(input_field)
|
processor_type_layout.addWidget(input_field)
|
||||||
self.layout.addWidget(processor_type_settings)
|
self.wlayout.addWidget(processor_type_settings)
|
||||||
|
|
||||||
return processor_type_settings
|
return processor_type_settings
|
||||||
|
|
||||||
|
@ -144,15 +144,15 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
action_bar_layout.addWidget(self.configure_button)
|
action_bar_layout.addWidget(self.configure_button)
|
||||||
action_bar_layout.addWidget(self.search_button)
|
action_bar_layout.addWidget(self.search_button)
|
||||||
self.layout.addWidget(action_bar)
|
self.wlayout.addWidget(action_bar)
|
||||||
|
|
||||||
def get_default_config(self, search_type: SearchType = None, processor_type: ProcessorType = None):
|
def get_default_config(self, search_type: SearchType = None, processor_type: ProcessorType = None):
|
||||||
"Get default config"
|
"Get default config"
|
||||||
config = constants.default_config
|
config = constants.default_config
|
||||||
if search_type:
|
if search_type:
|
||||||
return config["content-type"][search_type]
|
return config["content-type"][search_type] # type: ignore
|
||||||
elif processor_type:
|
elif processor_type:
|
||||||
return config["processor"][processor_type]
|
return config["processor"][processor_type] # type: ignore
|
||||||
else:
|
else:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -160,12 +160,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
"Add Error Message to Configure Screen"
|
"Add Error Message to Configure Screen"
|
||||||
# Remove any existing error messages
|
# Remove any existing error messages
|
||||||
for message_prefix in ErrorType:
|
for message_prefix in ErrorType:
|
||||||
for i in reversed(range(self.layout.count())):
|
for i in reversed(range(self.wlayout.count())):
|
||||||
current_widget = self.layout.itemAt(i).widget()
|
current_widget = self.wlayout.itemAt(i).widget()
|
||||||
if isinstance(current_widget, QtWidgets.QLabel) and current_widget.text().startswith(
|
if isinstance(current_widget, QtWidgets.QLabel) and current_widget.text().startswith(
|
||||||
message_prefix.value
|
message_prefix.value
|
||||||
):
|
):
|
||||||
self.layout.removeWidget(current_widget)
|
self.wlayout.removeWidget(current_widget)
|
||||||
current_widget.deleteLater()
|
current_widget.deleteLater()
|
||||||
|
|
||||||
# Add new error message
|
# Add new error message
|
||||||
|
@ -174,7 +174,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
error_message.setWordWrap(True)
|
error_message.setWordWrap(True)
|
||||||
error_message.setText(message)
|
error_message.setText(message)
|
||||||
error_message.setStyleSheet("color: red")
|
error_message.setStyleSheet("color: red")
|
||||||
self.layout.addWidget(error_message)
|
self.wlayout.addWidget(error_message)
|
||||||
|
|
||||||
def update_search_settings(self):
|
def update_search_settings(self):
|
||||||
"Update config with search settings from UI"
|
"Update config with search settings from UI"
|
||||||
|
|
|
@ -33,7 +33,7 @@ def create_system_tray(gui: QtWidgets.QApplication, main_window: MainWindow):
|
||||||
# Add the menu actions to the menu
|
# Add the menu actions to the menu
|
||||||
for action_text, action_function in menu_actions:
|
for action_text, action_function in menu_actions:
|
||||||
menu_action = QtGui.QAction(action_text, menu)
|
menu_action = QtGui.QAction(action_text, menu)
|
||||||
menu_action.triggered.connect(action_function)
|
menu_action.triggered.connect(action_function) # type: ignore[attr-defined]
|
||||||
menu.addAction(menu_action)
|
menu.addAction(menu_action)
|
||||||
|
|
||||||
# Add the menu to the system tray
|
# Add the menu to the system tray
|
||||||
|
|
|
@ -27,7 +27,7 @@ search_index_lock = threading.Lock()
|
||||||
if torch.cuda.is_available():
|
if torch.cuda.is_available():
|
||||||
# Use CUDA GPU
|
# Use CUDA GPU
|
||||||
device = torch.device("cuda:0")
|
device = torch.device("cuda:0")
|
||||||
elif version.parse(torch.__version__) >= version.parse("1.13.0.dev") and torch.backends.mps.is_available(): # type: ignore[attr-defined]
|
elif version.parse(torch.__version__) >= version.parse("1.13.0.dev") and torch.backends.mps.is_available():
|
||||||
# Use Apple M1 Metal Acceleration
|
# Use Apple M1 Metal Acceleration
|
||||||
device = torch.device("mps")
|
device = torch.device("mps")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue