haraka 0.2.52__py3-none-any.whl → 0.2.54__py3-none-any.whl

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.
haraka/PyFast/Runtime.py CHANGED
@@ -1,47 +1,49 @@
1
+ from enum import Enum, auto
1
2
  from fastapi import FastAPI
2
3
  import socket
3
4
  from haraka.utils import Logger
4
5
 
6
+
7
+ class LifecycleState(Enum):
8
+ UNINITIALIZED = auto()
9
+ STARTED = auto()
10
+ DESTROYED = auto()
11
+
12
+
5
13
  class Lifecycle:
6
14
  """
7
15
  A helper class to handle initialization and shutdown messaging for a FastAPI application.
16
+ Tracks internal state to guard against invalid transitions.
8
17
  """
9
18
  def __init__(self, variant: str = "PyFast"):
10
- """
11
- Initializes the PyFast instance with a logger.
12
-
13
- Args:
14
- variant (str): A string identifier for the application. Default is 'PyFast'.
15
- """
16
19
  self.variant = variant
17
20
  self.logger = Logger(self.variant).start_logger()
21
+ self.state = LifecycleState.UNINITIALIZED
18
22
 
19
- def start(self, settings, app: FastAPI):
20
- """
21
- Initializes the application and logs Swagger UI availability.
23
+ async def start(self, settings, app: FastAPI):
24
+ if self.state != LifecycleState.UNINITIALIZED:
25
+ self.logger.warn(f"🟡 Attempted to start, but state is already {self.state.name}")
26
+ return
22
27
 
23
- Args:
24
- settings: A settings object containing application configuration (e.g., port).
25
- app (FastAPI): The FastAPI application instance.
26
- """
27
28
  try:
28
29
  port = settings.port
29
- docs_path = app.docs_url or "/docs" # Default to '/docs' if not set
30
+ docs_path = app.docs_url or "/docs"
30
31
  local_url = f"http://localhost:{port}{docs_path}"
31
32
 
32
- # Resolve the network-accessible hostname
33
33
  host = socket.gethostbyname(socket.gethostname())
34
34
  network_url = f"http://{host}:{port}{docs_path}"
35
35
 
36
- # Log the Swagger UI URLs
37
- self.logger.info(f"Swagger UI available at: {local_url}")
38
- self.logger.info(f"Network Swagger UI available at: {network_url}")
36
+ self.logger.info(f"✅ Swagger UI available at: {local_url}")
37
+ self.logger.info(f"🌐 Network Swagger UI available at: {network_url}")
38
+ self.state = LifecycleState.STARTED
39
39
 
40
40
  except Exception as e:
41
- self.logger.warn(f"Failed to determine network URL: {e}")
41
+ self.logger.warn(f"⚠️ Failed to determine network URL: {e}")
42
+
43
+ async def destroy(self):
44
+ if self.state == LifecycleState.DESTROYED:
45
+ self.logger.warn("🟡 destroy() called, but app is already shut down.")
46
+ return
42
47
 
43
- def destroy(self):
44
- """
45
- Logs a shutdown message when the application is shutting down.
46
- """
47
48
  self.logger.info("🛑 Application is shutting down!")
49
+ self.state = LifecycleState.DESTROYED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haraka
3
- Version: 0.2.52
3
+ Version: 0.2.54
4
4
  Summary: Reusable post-generation helper for Cookiecutter micro-service templates
5
5
  Author-email: Will Burks <will@example.com>
6
6
  License: MIT
@@ -12,3 +12,13 @@ Classifier: Intended Audience :: Developers
12
12
  Classifier: Topic :: Software Development :: Build Tools
13
13
  Requires-Python: >=3.9
14
14
  Description-Content-Type: text/markdown
15
+ Requires-Dist: pathspec==0.10.3
16
+ Requires-Dist: PyYAML==6.0.1
17
+ Requires-Dist: wcwidth==0.2.5
18
+ Requires-Dist: fastapi==0.115.14
19
+ Provides-Extra: gen
20
+ Requires-Dist: pathspec==0.10.3; extra == "gen"
21
+ Requires-Dist: PyYAML==6.0.1; extra == "gen"
22
+ Requires-Dist: wcwidth==0.2.5; extra == "gen"
23
+ Provides-Extra: pyfast
24
+ Requires-Dist: fastapi==0.115.14; extra == "pyfast"
@@ -1,5 +1,5 @@
1
1
  haraka/__init__.py,sha256=b8t9TwJ3drfLFkYAsiXvKuyat7ppKnhRkAtMlb1kt_A,221
2
- haraka/PyFast/Runtime.py,sha256=uRkz-kGbQxxeC1NgZtEtiM_v9sZPRBQF45WlbbrB_80,1670
2
+ haraka/PyFast/Runtime.py,sha256=eZXLdL2gw3pQd6gX2l8ydeWXsEN6-WdOprk49h2LwC0,1700
3
3
  haraka/PyFast/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  haraka/art/__init__.py,sha256=-b1KHQiLkaI2sXaHS05XDaE27tZfXvVLitILjJfSiKs,112
5
5
  haraka/art/create.py,sha256=D2VPJtuwI0Ed7CcreHRHhxSN1VzV7PQfC1q-NW8l0DY,631
@@ -31,7 +31,7 @@ haraka/utils/manifests/GoUltraFast.yml,sha256=LBSlT2QyOi_reUfZ7AAvs0U6Ju47K94eG_
31
31
  haraka/utils/manifests/JavaFein.yml,sha256=TSTo45Q-NMMqaDS4ogYwU0PpxW-sl0MCYj-RG-Hc_M0,989
32
32
  haraka/utils/manifests/PyFast.yml,sha256=dfUXDsxWj-Ex_DQX9sNNezIjfAW_ipjHEh1g8sEs8eQ,924
33
33
  haraka/utils/manifests/go-grpc-gateway-buf.yml,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- haraka-0.2.52.dist-info/METADATA,sha256=vNCewvL4ofzzptj1q0sUaH5zQgi5zkC1R5k2eY9Qyqg,579
35
- haraka-0.2.52.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
- haraka-0.2.52.dist-info/top_level.txt,sha256=1khpwypLKWoklVd_CgFiwAfcctVSXRoRPc3BI9lyIXo,7
37
- haraka-0.2.52.dist-info/RECORD,,
34
+ haraka-0.2.54.dist-info/METADATA,sha256=_c-5V5xUhcAJZgoeTNfWuRcF32SwhXsdnflESOl_V5o,937
35
+ haraka-0.2.54.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
36
+ haraka-0.2.54.dist-info/top_level.txt,sha256=1khpwypLKWoklVd_CgFiwAfcctVSXRoRPc3BI9lyIXo,7
37
+ haraka-0.2.54.dist-info/RECORD,,