spoc 0.2.2__tar.gz → 0.2.3__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.
spoc-0.2.3/PKG-INFO ADDED
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.1
2
+ Name: spoc
3
+ Version: 0.2.3
4
+ Summary: Elastic Framework Builder
5
+ Keywords: modular design,python framework,extensible framework,plugin management
6
+ Author-Email: hlop3z <23062270+hlop3z@users.noreply.github.com>
7
+ License: MIT
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Information Technology
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Internet
15
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Topic :: Software Development
19
+ Classifier: Typing :: Typed
20
+ Project-URL: Homepage, https://github.com/hlop3z/spoc/
21
+ Project-URL: Documentation, https://hlop3z.github.io/spoc/
22
+ Project-URL: Repository, https://github.com/hlop3z/spoc/
23
+ Requires-Python: >=3.12
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Welcome to **SPOC**
27
+
28
+ <img src="https://raw.githubusercontent.com/hlop3z/spoc/main/docs/docs/assets/images/title.png" alt="title-image" width="100%" />
29
+
30
+ ---
31
+
32
+ ![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)
33
+ ![Language](https://img.shields.io/github/languages/top/hlop3z/spoc)
34
+ ![GitHub](https://img.shields.io/github/v/tag/hlop3z/spoc?label=github)
35
+ ![PyPI](https://img.shields.io/pypi/v/spoc?color=blue)
36
+ ![Downloads](https://img.shields.io/pypi/dm/spoc?color=darkgreen)
37
+
38
+ ---
39
+
40
+ **SPOC** is a foundational framework designed to create dynamic and adaptable **`frameworks`**. It involves defining a schema for your **project**(s) and building upon that schema to create a flexible and powerful Application.
41
+
42
+ ---
43
+
44
+ ## Links
45
+
46
+ - [PyPi](https://pypi.org/project/spoc)
47
+ - [Github](https://github.com/hlop3z/spoc)
48
+ - [Read the Documents](https://hlop3z.github.io/spoc/)
49
+
50
+ ---
51
+
52
+ ## Example
53
+
54
+ ```python
55
+ from typing import Any
56
+ import spoc
57
+
58
+ MODULES = ["models", "views"]
59
+
60
+ class MyFramework(spoc.Base):
61
+ components: Any
62
+ plugins: Any
63
+
64
+ def init(self):
65
+ """__init__ Replacement"""
66
+ app = spoc.init(MODULES)
67
+
68
+ # Assign components and plugins from the initialized app
69
+ self.components = app.components
70
+ self.plugins = app.plugins
71
+
72
+ @staticmethod
73
+ def keys():
74
+ """Define a list of keys relevant to the framework"""
75
+ return ("components", "plugins")
76
+ ```
spoc-0.2.3/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Welcome to **SPOC**
2
+
3
+ <img src="https://raw.githubusercontent.com/hlop3z/spoc/main/docs/docs/assets/images/title.png" alt="title-image" width="100%" />
4
+
5
+ ---
6
+
7
+ ![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)
8
+ ![Language](https://img.shields.io/github/languages/top/hlop3z/spoc)
9
+ ![GitHub](https://img.shields.io/github/v/tag/hlop3z/spoc?label=github)
10
+ ![PyPI](https://img.shields.io/pypi/v/spoc?color=blue)
11
+ ![Downloads](https://img.shields.io/pypi/dm/spoc?color=darkgreen)
12
+
13
+ ---
14
+
15
+ **SPOC** is a foundational framework designed to create dynamic and adaptable **`frameworks`**. It involves defining a schema for your **project**(s) and building upon that schema to create a flexible and powerful Application.
16
+
17
+ ---
18
+
19
+ ## Links
20
+
21
+ - [PyPi](https://pypi.org/project/spoc)
22
+ - [Github](https://github.com/hlop3z/spoc)
23
+ - [Read the Documents](https://hlop3z.github.io/spoc/)
24
+
25
+ ---
26
+
27
+ ## Example
28
+
29
+ ```python
30
+ from typing import Any
31
+ import spoc
32
+
33
+ MODULES = ["models", "views"]
34
+
35
+ class MyFramework(spoc.Base):
36
+ components: Any
37
+ plugins: Any
38
+
39
+ def init(self):
40
+ """__init__ Replacement"""
41
+ app = spoc.init(MODULES)
42
+
43
+ # Assign components and plugins from the initialized app
44
+ self.components = app.components
45
+ self.plugins = app.plugins
46
+
47
+ @staticmethod
48
+ def keys():
49
+ """Define a list of keys relevant to the framework"""
50
+ return ("components", "plugins")
51
+ ```
@@ -34,7 +34,7 @@ keywords = [
34
34
  "plugin management",
35
35
  ]
36
36
  dependencies = []
37
- version = "0.2.2"
37
+ version = "0.2.3"
38
38
 
39
39
  [project.license]
40
40
  text = "MIT"
@@ -42,6 +42,7 @@ text = "MIT"
42
42
  [project.urls]
43
43
  Homepage = "https://github.com/hlop3z/spoc/"
44
44
  Documentation = "https://hlop3z.github.io/spoc/"
45
+ Repository = "https://github.com/hlop3z/spoc/"
45
46
 
46
47
  [project.scripts]
47
48
  spoc-init = "spoc:start_project"
@@ -79,6 +80,8 @@ docs = [
79
80
  ]
80
81
  test = [
81
82
  "pytest>=7.1.2",
82
- "pytest-asyncio>=0.19.0",
83
83
  "pytest-json-report>=1.5.0",
84
84
  ]
85
+
86
+ [tool.pdm.scripts]
87
+ test = "pytest -rA tests/test_main.py"
@@ -1,5 +1,5 @@
1
1
  """Project Info"""
2
2
 
3
- __version__ = "0.2.2"
3
+ __version__ = "0.2.3"
4
4
  __license__ = "MIT"
5
5
  __author__ = "hlop3z"
@@ -2,11 +2,18 @@
2
2
  """
3
3
  # Elastic Frameworks
4
4
 
5
- This example demonstrates how to create a custom framework by extending the `spoc.Base` class.
6
- The framework initializes via `spoc.init` with a list of `modules`,
7
- and it provides access to `components` and `plugins`.
5
+ SPOC is a foundational framework designed to create dynamic and adaptable frameworks.
6
+ It involves defining a schema for your project(s) and
7
+ building upon that schema to create a flexible and powerful Application.
8
8
 
9
- Example:
9
+ This module provides an example of how to create a framework by extending the `spoc.Base` class.
10
+ It demonstrates the initialization process using `spoc.init` with a list of modules,
11
+ and shows how to access and manage various components and plugins within the framework.
12
+
13
+ ## Example
14
+
15
+ To create a custom framework,
16
+ extend the `spoc.Base` class and initialize it using `spoc.init` with a list of desired modules:
10
17
 
11
18
  ```python
12
19
  from typing import Any
@@ -29,7 +36,7 @@ class MyFramework(spoc.Base):
29
36
  @staticmethod
30
37
  def keys():
31
38
  # Define a list of keys relevant to the framework
32
- return ("components", "plugins", "cli")
39
+ return ("components", "plugins")
33
40
  ```
34
41
  """
35
42
 
@@ -27,7 +27,7 @@ BASE_DIR = pathlib.Path(__file__).parents[1]
27
27
  # Installed Apps
28
28
  INSTALLED_APPS: list = []
29
29
 
30
- # Extra Methods
30
+ # Additional Components
31
31
  PLUGINS: dict = {}
32
32
  '''.strip()
33
33
 
@@ -70,44 +70,45 @@ class AbstractWorker(ABC):
70
70
 
71
71
  def run(self) -> None:
72
72
  """Run Worker"""
73
+ self.before()
73
74
  if inspect.iscoroutinefunction(self.server):
74
75
  # Async Server
75
- try:
76
- self.before_async()
77
- self.agent.run(self.run_async())
78
- except KeyboardInterrupt:
79
- pass
80
- except asyncio.CancelledError:
81
- pass
76
+ self.agent.run(self.run_async())
82
77
  else:
83
78
  # Sync Server
84
- try:
85
- self.before_sync()
86
- self.run_sync()
87
- except KeyboardInterrupt:
88
- pass
79
+ self.run_sync()
89
80
 
90
- def before_async(self) -> None:
91
- """Setup before running asynchronous server."""
92
-
93
- def before_sync(self) -> None:
94
- """Setup before running synchronous server."""
81
+ def before(self) -> None:
82
+ """Setup before running server."""
95
83
 
96
84
  def run_sync(self) -> None:
97
85
  """Run Synchronous Worker"""
98
86
  self.on_event("startup")
99
- try:
100
- self.server()
101
- finally:
102
- self.on_event("shutdown")
87
+ job = threading.Thread(target=self.server)
88
+ job.daemon = True
89
+ job.start()
90
+ # Dummy Loop
91
+ while self.active:
92
+ try:
93
+ time.sleep(1)
94
+ except KeyboardInterrupt:
95
+ pass
96
+ # After Stop
97
+ self.on_event("shutdown")
103
98
 
104
99
  async def run_async(self) -> None:
105
100
  """Run Asynchronous Worker"""
101
+ loop = asyncio.get_running_loop()
106
102
  await self.on_event("startup")
107
- try:
108
- await self.server()
109
- finally:
110
- await self.on_event("shutdown")
103
+ loop.create_task(self.server())
104
+ # Dummy Loop
105
+ while self.active:
106
+ try:
107
+ await asyncio.sleep(1)
108
+ except (KeyboardInterrupt, asyncio.CancelledError):
109
+ pass
110
+ # After Stop
111
+ await self.on_event("shutdown")
111
112
 
112
113
  def stop(self):
113
114
  """Stop Worker"""
@@ -134,8 +135,8 @@ class BaseProcess(AbstractWorker, multiprocessing.Process):
134
135
  class AsyncProcess(spoc.BaseProcess):
135
136
  agent: Any = asyncio # Example: `uvloop`
136
137
 
137
- def before_async(self) -> None:
138
- ... # For Async Only
138
+ def before(self) -> None:
139
+ ... # Set uvloop.EventLoopPolicy()
139
140
 
140
141
  async def on_event(self, event_type: str):
141
142
  ...
@@ -174,8 +175,8 @@ class BaseThread(AbstractWorker, threading.Thread):
174
175
  class AsyncThread(spoc.BaseThread):
175
176
  agent: Any = asyncio # Example: `uvloop`
176
177
 
177
- def before_async(self) -> None:
178
- ... # For Async Only
178
+ def before(self) -> None:
179
+ ... # Set uvloop.EventLoopPolicy()
179
180
 
180
181
  async def on_event(self, event_type: str):
181
182
  ...
@@ -256,8 +257,20 @@ class BaseServer(ABC):
256
257
  """
257
258
  cls.workers.extend(workers)
258
259
 
260
+ @staticmethod
261
+ def _disable_exit_signal() -> None:
262
+ """Wait for cleanup to complete."""
263
+
264
+ def handler(*_):
265
+ """Ctrl+C pressed."""
266
+
267
+ # Temporarily ignore Ctrl+C
268
+ signal.signal(signal.SIGINT, handler)
269
+
259
270
  @classmethod
260
- def start(cls, infinite_loop: bool = True) -> None:
271
+ def start(
272
+ cls, infinite_loop: bool = True, timeout: int = 5, forced_delay: int = 1
273
+ ) -> None:
261
274
  """
262
275
  Start all added workers and optionally keep a loop running until interrupted.
263
276
  """
@@ -292,13 +305,15 @@ class BaseServer(ABC):
292
305
  while True:
293
306
  time.sleep(1)
294
307
  except KeyboardInterrupt:
308
+ # Disable (Ctrl + C)
309
+ cls._disable_exit_signal()
295
310
  # Before Shutdown
296
311
  cls.on_event("before_shutdown")
297
- cls.stop(force_stop=True, forced_delay=5)
312
+ cls.stop(force_stop=True, timeout=timeout, forced_delay=forced_delay)
298
313
 
299
314
  @classmethod
300
315
  def stop(
301
- cls, timeout: int = 5, force_stop: bool = False, forced_delay: int = 10
316
+ cls, timeout: int = 5, force_stop: bool = False, forced_delay: int = 1
302
317
  ) -> None:
303
318
  """
304
319
  Stop all running workers.
spoc-0.2.2/PKG-INFO DELETED
@@ -1,31 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: spoc
3
- Version: 0.2.2
4
- Summary: Elastic Framework Builder
5
- Keywords: modular design,python framework,extensible framework,plugin management
6
- Author-Email: hlop3z <23062270+hlop3z@users.noreply.github.com>
7
- License: MIT
8
- Classifier: Development Status :: 4 - Beta
9
- Classifier: Intended Audience :: Developers
10
- Classifier: Intended Audience :: Information Technology
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Topic :: Internet
15
- Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
16
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Classifier: Topic :: Software Development :: Libraries
18
- Classifier: Topic :: Software Development
19
- Classifier: Typing :: Typed
20
- Project-URL: Homepage, https://github.com/hlop3z/spoc/
21
- Project-URL: Documentation, https://hlop3z.github.io/spoc/
22
- Requires-Python: >=3.12
23
- Description-Content-Type: text/markdown
24
-
25
- # Welcome to **Spoc**
26
-
27
- ## Links
28
-
29
- - ### [PyPi](https://pypi.org/project/spoc)
30
- - ### [Github](https://github.com/hlop3z/spoc)
31
- - ### [Read the Documents](https://hlop3z.github.io/spoc/)
spoc-0.2.2/README.md DELETED
@@ -1,7 +0,0 @@
1
- # Welcome to **Spoc**
2
-
3
- ## Links
4
-
5
- - ### [PyPi](https://pypi.org/project/spoc)
6
- - ### [Github](https://github.com/hlop3z/spoc)
7
- - ### [Read the Documents](https://hlop3z.github.io/spoc/)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes