memoryframes 0.1.6__tar.gz → 0.3.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.1.6
3
+ Version: 0.3.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.1.6"
3
+ version = "0.3.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,25 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from uuid import UUID
6
+
7
+ from MemoryFrames.PluginInfra.NoteSource import NoteSource
8
+
9
+
10
+ # ----------------------------------------------------------------------
11
+ @dataclass
12
+ class Note:
13
+ """A note."""
14
+
15
+ id: UUID
16
+
17
+ source: NoteSource
18
+ source_data: object
19
+ """Opaque data provided by the NoteSource that created the note."""
20
+
21
+ metadata: dict[str, object] = field(repr=False)
22
+ content: str = field(repr=False)
23
+
24
+ metadata_hash: bytes = field(repr=False)
25
+ content_hash: bytes = field(repr=False)
@@ -0,0 +1,36 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ from MemoryFrames.PluginInfra.Note import Note
6
+
7
+
8
+ # ----------------------------------------------------------------------
9
+ class NoteSource:
10
+ """Base class for a plugin component that provides notes to MemoryFrames."""
11
+
12
+ # ----------------------------------------------------------------------
13
+ def __init__(self, observer: NoteSourceObserver) -> None:
14
+ self.observer = observer
15
+
16
+
17
+ # ----------------------------------------------------------------------
18
+ class NoteSourceObserver(ABC):
19
+ """Base class for an observer that receives event notifications from a NoteSource."""
20
+
21
+ # ----------------------------------------------------------------------
22
+ @abstractmethod
23
+ def OnNewNote(
24
+ self,
25
+ note: Note,
26
+ *,
27
+ is_initializing: bool,
28
+ ) -> None:
29
+ """Indicate that a note has been discovered."""
30
+ raise NotImplementedError() # pragma: no cover
31
+
32
+ # ----------------------------------------------------------------------
33
+ @abstractmethod
34
+ def OnInitializationComplete(self, note_source: NoteSource) -> None:
35
+ """Indicate that the NoteSource has completed its initialization."""
36
+ raise NotImplementedError() # pragma: no cover
@@ -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,22 @@
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
+ pass
19
+ # TODO: # Avoid circular import issues by importing here
20
+ # TODO: from MemoryFrames.PluginInfra.TextualUserExperienceInfo import TextualUserExperienceInfo
21
+
22
+ # TODO: assert isinstance(self, (TextualUserExperienceInfo,)), self
File without changes
File without changes