diff --git a/.bumpversion.toml b/.bumpversion.toml deleted file mode 100644 index 0f4922f..0000000 --- a/.bumpversion.toml +++ /dev/null @@ -1,22 +0,0 @@ -[tool.bumpversion] -current_version = "0.2.1" -parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" -serialize = ["{major}.{minor}.{patch}"] -search = "{current_version}" -replace = "{new_version}" -regex = false -ignore_missing_version = false -ignore_missing_files = false -tag = true -sign_tags = false -tag_name = "v{new_version}" -tag_message = "Bump version: {current_version} → {new_version}" -allow_dirty = false -commit = true -message = "Bump version: {current_version} → {new_version}" -commit_args = "" -setup_hooks = [] -pre_commit_hooks = [] -post_commit_hooks = [] -[[tool.bumpversion.files]] -filename = "src/__init__.py" diff --git a/config/config.py b/config/config.py index d013607..4a4a550 100644 --- a/config/config.py +++ b/config/config.py @@ -149,7 +149,14 @@ class Config: FileNotFoundError: Configuration file not found """ if not os.path.exists(config_path): - raise FileNotFoundError(f"Configuration file not found: {config_path}") + # copy base config file to the given path + base = "config/base_config.yaml" + if not os.path.exists(base): + raise FileNotFoundError(f"Base configuration file not found: {base}") + with open(base, "r") as base_file: + base_config = base_file.read() + with open(config_path, "w") as config_file: + config_file.write(base_config) self._config = OmegaConf.load(config_path) self.config_path = config_path diff --git a/pyproject.toml b/pyproject.toml index 59b20d0..0ec7f41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,3 +35,29 @@ dev = [ "icecream>=2.1.4", "nuitka>=2.5.9", ] + +[tool.bumpversion] +current_version = "0.1.0" +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" +serialize = ["{major}.{minor}.{patch}"] +search = "{current_version}" +replace = "{new_version}" +regex = false +ignore_missing_version = false +ignore_missing_files = false +tag = false +sign_tags = false +tag_name = "v{new_version}" +tag_message = "Bump version: {current_version} → {new_version}" +allow_dirty = false +commit = false +message = "Bump version: {current_version} → {new_version}" +moveable_tags = [] +commit_args = "" +setup_hooks = [] +pre_commit_hooks = [] +post_commit_hooks = [] +[[tool.bumpversion.files]] +filename = "src/__init__.py" +[[tool.bumpversion.files]] +filename = ".version" \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py index 32f9353..bb7639a 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -15,7 +15,7 @@ if not os.path.exists(CONFIG_DIR): os.makedirs(CONFIG_DIR) -settings = Config("config/config.yaml") +settings = Config(f"{CONFIG_DIR}/config.yaml") if not os.path.exists(settings.database.temp.expanduser()): settings.database.temp.expanduser().mkdir(parents=True, exist_ok=True) from .utils.icon import Icon diff --git a/src/logic/openai.py b/src/logic/openai.py index 6ee11fe..4fda61d 100644 --- a/src/logic/openai.py +++ b/src/logic/openai.py @@ -1,28 +1,37 @@ from openai import OpenAI from src import settings import json -from src import LOG_DIR -model = settings.openAI.model -api_key = settings.openAI.api_key -client = OpenAI(api_key = api_key) + +def init_client(): + """Initialize the OpenAI client with the API key and model from settings.""" + global client, model, api_key + if not settings.openAI.api_key: + raise ValueError("OpenAI API key is not set in the configuration.") + if not settings.openAI.model: + raise ValueError("OpenAI model is not set in the configuration.") + + model = settings.openAI.model + api_key = settings.openAI.api_key + client = OpenAI(api_key=api_key) + return client def run_shortener(title:str, length:int): + client = init_client() response = client.responses.create( - model = model, - instructions = """you are a sentence shortener. The next message will contain the string to shorten and the length limit. + model=model, + instructions="""you are a sentence shortener. The next message will contain the string to shorten and the length limit. You need to shorten the string to be under the length limit, while keeping as much detail as possible. The result may NOT be longer than the length limit. based on that, please reply only the shortened string. Give me 5 choices. if the length is too long, discard the string and try another one.Return the data as a python list containing the result as {"shortened_string": shortened_string, "length": lengthasInt}. Do not return the answer in a codeblock, use a pure string. Before answering, check the results and if ANY is longer than the needed_length, discard all and try again""", - input = f'{{"string":"{title}", "needed_length":{length}}}' + input=f'{{"string":"{title}", "needed_length":{length}}}', ) - print(length) answers = response.output_text - print(answers) return eval(answers) # type: ignore #answers are strings in json format, so we need to convert them to a list of dicts def name_tester(name: str): + client = init_client() response = client.responses.create( model = model, instructions="""you are a name tester, You are given a name and will have to split the name into first name, last name, and if present the title. Return the name in a json format with the keys "title", "first_name", "last_name". If no title is present, set title to none. Do NOt return the answer in a codeblock, use a pure json string. Assume the names are in the usual german naming scheme""", @@ -33,6 +42,7 @@ def name_tester(name: str): return json.loads(answers) def semester_converter(semester:str): + client = init_client() response = client.responses.create( model = model, instructions="""you are a semester converter. You will be given a string. Convert this into a string like this: SoSe YY or WiSe YY/YY+1. Do not return the answer in a codeblock, use a pure string.""", diff --git a/src/logic/zotero.py b/src/logic/zotero.py index dfbe905..14860e0 100644 --- a/src/logic/zotero.py +++ b/src/logic/zotero.py @@ -160,6 +160,8 @@ class ZoteroController: zoterocfg = settings.zotero def __init__(self): + if self.zoterocfg.library_id is None: + return self.zot = zotero.Zotero( self.zoterocfg.library_id, self.zoterocfg.library_type, diff --git a/src/ui/widgets/MessageCalendar.py b/src/ui/widgets/MessageCalendar.py index 47b0a62..9a424cd 100644 --- a/src/ui/widgets/MessageCalendar.py +++ b/src/ui/widgets/MessageCalendar.py @@ -1,12 +1,14 @@ -from PyQt6 import QtWidgets, QtCore -from PyQt6.QtCore import QDate -from PyQt6.QtGui import QColor, QPen -from src.backend import Database +import sys from typing import Any + import darkdetect import loguru -import sys +from PyQt6 import QtCore, QtWidgets +from PyQt6.QtCore import QDate +from PyQt6.QtGui import QColor, QPen + from src import LOG_DIR +from src.backend import Database log = loguru.logger log.remove() diff --git a/src/ui/widgets/graph.py b/src/ui/widgets/graph.py index 93f2cde..d480cdb 100644 --- a/src/ui/widgets/graph.py +++ b/src/ui/widgets/graph.py @@ -1,10 +1,11 @@ import random -from typing import Union, Any +import sys +from typing import Any, Union +import loguru import pyqtgraph as pg from PyQt6 import QtWidgets -import loguru -import sys + from src import LOG_DIR log = loguru.logger diff --git a/src/ui/widgets/searchPage.py b/src/ui/widgets/searchPage.py index 3a298d9..448f319 100644 --- a/src/ui/widgets/searchPage.py +++ b/src/ui/widgets/searchPage.py @@ -1,16 +1,18 @@ -from .widget_sources.search_statistic_page_ui import Ui_Dialog -from PyQt6 import QtWidgets, QtGui, QtCore -from PyQt6.QtCore import pyqtSignal -from src.backend import Database, Semester - -from src.logic import custom_sort, Prof, sort_semesters_list -from src.ui.dialogs import Mail_Dialog, ApparatExtendDialog, ReminderDialog -from src.ui.widgets import DataGraph, StatusWidget -from src import LOG_DIR -from natsort import natsorted -import loguru import sys +import loguru +from natsort import natsorted +from PyQt6 import QtCore, QtGui, QtWidgets +from PyQt6.QtCore import pyqtSignal + +from src import LOG_DIR +from src.backend import Database, Semester +from src.logic import Prof, custom_sort, sort_semesters_list +from src.ui.dialogs import ApparatExtendDialog, Mail_Dialog, ReminderDialog +from src.ui.widgets import DataGraph, StatusWidget + +from .widget_sources.search_statistic_page_ui import Ui_Dialog + log = loguru.logger log.remove() log.add(sys.stdout, level="INFO")