From 47389e7ca5368d37f3e9c6216126f5fbd77f039f Mon Sep 17 00:00:00 2001 From: redatman Date: Tue, 30 Jul 2024 23:02:30 +0800 Subject: [PATCH 1/2] Refactor: Improve import paths and file organization This commit refactors the import paths and file organization for improved clarity and maintainability. It moves the `api` module into a subdirectory and adjusts relative imports accordingly. This helps to better separate concerns and improve the overall structure of the codebase. --- _config.py | 4 ++-- models.py | 3 +-- operations.py | 5 ++--- simplenote.py | 5 ++--- simplenotecommands.py | 11 +++++------ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/_config.py b/_config.py index 3ea5f05..f04842f 100644 --- a/_config.py +++ b/_config.py @@ -31,8 +31,8 @@ def __init_subclass__(cls, **kwargs): DEBUG: bool = False TESTING: bool = False - # BASE_DIR = os.path.dirname(os.path.abspath(__file__)) - BASE_DIR: str = os.path.abspath(os.path.dirname(__file__)) + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + # BASE_DIR: str = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, BASE_DIR) LOG_DIR: str = os.path.join(BASE_DIR, "logs") os.makedirs(LOG_DIR, exist_ok=True) diff --git a/models.py b/models.py index 4579566..083a377 100644 --- a/models.py +++ b/models.py @@ -14,8 +14,7 @@ import sublime -from api import Simplenote - +from .api import Simplenote from .utils.decorator import class_property from .utils.tree.redblacktree import rbtree as RedBlackTree diff --git a/operations.py b/operations.py index 68ceb8c..b116437 100644 --- a/operations.py +++ b/operations.py @@ -6,9 +6,8 @@ import sublime -from gui import SIMPLENOTE_BASE_DIR, SIMPLENOTE_SETTINGS_FILE, _show_message, open_view, remove_status -from models import Note - +from .gui import SIMPLENOTE_BASE_DIR, SIMPLENOTE_SETTINGS_FILE, _show_message, open_view, remove_status +from .models import Note from .utils.patterns.singleton.base import Singleton diff --git a/simplenote.py b/simplenote.py index b98b1bf..7d8bb4a 100644 --- a/simplenote.py +++ b/simplenote.py @@ -8,9 +8,8 @@ # https://www.sublimetext.com/docs/api_reference.html import sublime -from gui import close_view, open_view -from models import SIMPLENOTE_NOTES_DIR, Note - +from .gui import close_view, open_view +from .models import SIMPLENOTE_NOTES_DIR, Note from .utils.patterns.singleton.base import Singleton diff --git a/simplenotecommands.py b/simplenotecommands.py index 4ff2402..5431a68 100644 --- a/simplenotecommands.py +++ b/simplenotecommands.py @@ -7,10 +7,10 @@ import sublime import sublime_plugin -from gui import SIMPLENOTE_PACKAGE_DIR, SIMPLENOTE_SETTINGS_FILE, close_view, open_view, remove_status, show_message -from models import Note -from operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager -from simplenote import clear_orphaned_filepaths, on_note_changed +from .gui import SIMPLENOTE_BASE_DIR, SIMPLENOTE_SETTINGS_FILE, close_view, open_view, remove_status, show_message +from .models import Note +from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager +from .simplenote import clear_orphaned_filepaths, on_note_changed __all__ = [ @@ -251,8 +251,7 @@ def start(): sync() SIMPLENOTE_STARTED = True else: - filepath = os.path.join(SIMPLENOTE_PACKAGE_DIR, SIMPLENOTE_SETTINGS_FILE) - sublime.active_window().open_file(filepath) + sublime.active_window().open_file(os.path.join(SIMPLENOTE_BASE_DIR, SIMPLENOTE_SETTINGS_FILE)) show_message("Simplenote: Please configure username/password") sublime.set_timeout(remove_status, 2000) SIMPLENOTE_STARTED = False From 52f8bf2f63c02e25ccf04e739f1dad2728f2c170 Mon Sep 17 00:00:00 2001 From: redatman Date: Tue, 30 Jul 2024 23:03:22 +0800 Subject: [PATCH 2/2] Fix: Remove unnecessary import and move import to proper location Moves the import of `importlib` to the proper location to avoid unnecessary imports and potential issues during runtime. This ensures clean and efficient code execution. --- models.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/models.py b/models.py index 083a377..837536f 100644 --- a/models.py +++ b/models.py @@ -1,6 +1,5 @@ from __future__ import annotations -from importlib import import_module import logging import os import re @@ -9,9 +8,6 @@ from typing import Any, ClassVar, Dict, List, Optional, TypedDict from uuid import uuid4 - -import_module("utils.logger.init") - import sublime from .api import Simplenote @@ -351,6 +347,7 @@ def get_note_from_filepath(view_absolute_filepath: str): if __name__ == "__main__": + from importlib import import_module from pprint import pprint import_module("_config")