memoryframes 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: memoryframes
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Add your description here
5
5
  Author: David Brownell
6
6
  Author-email: David Brownell <github@DavidBrownell.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "MemoryFrames"
3
- version = "0.2.0"
3
+ version = "0.4.0"
4
4
  # ^^^^^
5
5
  # Wheel names will be generated according to this value. Do not manually modify this value; instead
6
6
  # update it according to committed changes by running this command from the root of the repository:
@@ -0,0 +1,97 @@
1
+ from abc import ABC, abstractmethod
2
+ from dataclasses import dataclass
3
+ from functools import cached_property
4
+ from typing import TYPE_CHECKING
5
+
6
+ import pluggy
7
+
8
+ from MemoryFrames import APP_NAME
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import Callable
12
+ from threading import Event
13
+ from pathlib import Path
14
+
15
+ from MemoryFrames.PluginInfra.NoteSource import NoteSource, NoteSourceObserver
16
+ from MemoryFrames.PluginInfra.UserExperienceInfo import UserExperienceInfo
17
+
18
+
19
+ # ----------------------------------------------------------------------
20
+ @dataclass(frozen=True)
21
+ class ThreadInfo:
22
+ """Information about a thread that is defined by a Plugin but created and managed by the application."""
23
+
24
+ description: str
25
+ thread_func: Callable[
26
+ [
27
+ Event # Event set when the application is quitting
28
+ ],
29
+ None,
30
+ ]
31
+
32
+
33
+ # ----------------------------------------------------------------------
34
+ class Plugin(ABC):
35
+ """Base class for all MemoryFrames plugins."""
36
+
37
+ # ----------------------------------------------------------------------
38
+ def __init__(
39
+ self,
40
+ root_data_dir: Path,
41
+ ) -> None:
42
+ scrubbed_unique_name = self.unique_name
43
+
44
+ for invalid_char in ["<", ">", ":", '"', "/", "\\", "|", "?", "*", "."]:
45
+ scrubbed_unique_name = scrubbed_unique_name.replace(invalid_char, "_")
46
+
47
+ self.working_dir = root_data_dir / scrubbed_unique_name
48
+
49
+ # ----------------------------------------------------------------------
50
+ @property
51
+ @abstractmethod
52
+ def name(self) -> str:
53
+ """The name of the plugin."""
54
+ raise NotImplementedError() # pragma: no cover
55
+
56
+ @property
57
+ @abstractmethod
58
+ def author(self) -> str:
59
+ """The author of the plugin. This value will be used in the plugin's unique name."""
60
+ raise NotImplementedError() # pragma: no cover
61
+
62
+ @property
63
+ @abstractmethod
64
+ def description(self) -> str:
65
+ """The description of the plugin."""
66
+ raise NotImplementedError() # pragma: no cover
67
+
68
+ @property
69
+ @abstractmethod
70
+ def plugin_priority(self) -> int:
71
+ """The priority of the plugin. Higher values indicate higher priority, which will cause the plugin to appear before other lower priority plugins."""
72
+ raise NotImplementedError() # pragma: no cover
73
+
74
+ @cached_property
75
+ def unique_name(self) -> str:
76
+ """The unique name of the plugin."""
77
+ return f"{self.author}_{self.name}"
78
+
79
+ # ----------------------------------------------------------------------
80
+ def GetNoteSource(
81
+ self,
82
+ observer: NoteSourceObserver, # noqa: ARG002
83
+ enqueue_thread_info_func: Callable[[ThreadInfo], None], # noqa: ARG002
84
+ ) -> NoteSource | None:
85
+ """Return a NoteSource implemented by this plugin."""
86
+ return None
87
+
88
+
89
+ # ----------------------------------------------------------------------
90
+ @pluggy.HookspecMarker(APP_NAME)
91
+ def GetPlugin(
92
+ root_data_dir: Path,
93
+ all_plugins_settings: dict[str, object],
94
+ user_experience_info: UserExperienceInfo,
95
+ ) -> Plugin:
96
+ """Return a Plugin instance."""
97
+ raise NotImplementedError() # pragma: no cover
@@ -0,0 +1 @@
1
+ This directory contains all information, base classes, helper classes, etc. used when creating Plugins that customize MemoryFrames behavior.
@@ -0,0 +1,23 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from MemoryFrames.PluginInfra.UserExperienceInfo import UserExperienceInfo
4
+
5
+ if TYPE_CHECKING:
6
+ from textual.app import App
7
+ from textual.containers import Vertical
8
+
9
+
10
+ # ----------------------------------------------------------------------
11
+ class TextualUserExperienceInfo(UserExperienceInfo):
12
+ """User experience that leverages Textual for TUI capabilities."""
13
+
14
+ # ----------------------------------------------------------------------
15
+ def __init__(
16
+ self,
17
+ app: App,
18
+ hierarchy_container: Vertical,
19
+ ) -> None:
20
+ super().__init__()
21
+
22
+ self.app = app
23
+ self.hierarchy_container = hierarchy_container
@@ -0,0 +1,24 @@
1
+ import sys
2
+
3
+
4
+ # ----------------------------------------------------------------------
5
+ class UserExperienceInfo:
6
+ """Abstract base class for information associated with user experiences.
7
+
8
+ This information is passed to a Plugin on creation, where it uses the info to adjust its behavior
9
+ based on the information's derived type and associated data.
10
+ """
11
+
12
+ # ----------------------------------------------------------------------
13
+ def __init__(self) -> None:
14
+ # Ensure that only known classes inherit from this base class, as it is not a small thing
15
+ # to introduce a new user experience type (as all plugins, across the world, must be
16
+ # updated to support it.
17
+ if not sys.flags.optimize:
18
+ # Avoid circular import issues by importing here
19
+ from MemoryFrames.PluginInfra.TextualUserExperienceInfo import TextualUserExperienceInfo # noqa: PLC0415
20
+
21
+ assert isinstance(
22
+ self,
23
+ (TextualUserExperienceInfo,),
24
+ ), self
File without changes