devsetgo-lib 0.13.2__tar.gz → 0.13.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.
Files changed (23) hide show
  1. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/PKG-INFO +1 -1
  2. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/__init__.py +1 -1
  3. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/email_validation.py +2 -1
  4. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/logging_config.py +25 -38
  5. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/pyproject.toml +1 -1
  6. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/.gitignore +0 -0
  7. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/LICENSE +0 -0
  8. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/README.md +0 -0
  9. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/__import_sqlalchemy.py +0 -0
  10. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/__init__.py +0 -0
  11. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/async_database.py +0 -0
  12. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/base_schema.py +0 -0
  13. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/database_config.py +0 -0
  14. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/async_database_functions/database_operations.py +0 -0
  15. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/__init__.py +0 -0
  16. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/calendar_functions.py +0 -0
  17. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/file_functions.py +0 -0
  18. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/folder_functions.py +0 -0
  19. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/common_functions/patterns.py +0 -0
  20. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/fastapi_functions/__init__.py +0 -0
  21. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/fastapi_functions/_all_codes.py +0 -0
  22. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/fastapi_functions/http_codes.py +0 -0
  23. {devsetgo_lib-0.13.2 → devsetgo_lib-0.13.3}/dsg_lib/fastapi_functions/system_health_endpoints.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: devsetgo_lib
3
- Version: 0.13.2
3
+ Version: 0.13.3
4
4
  Summary: DevSetGo Library is a Python library offering reusable functions for efficient coding. It includes file operations, calendar utilities, pattern matching, advanced logging with loguru, FastAPI endpoints, async database handling, and email validation. Designed for ease of use and versatility, it's a valuable tool for Python developers.
5
5
  Project-URL: Homepage, https://github.com/devsetgo/devsetgo_lib
6
6
  Project-URL: Documentation, https://devsetgo.github.io/devsetgo_lib/
@@ -1,3 +1,3 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- __version__ = '0.13.2'
3
+ __version__ = '0.13.3'
@@ -38,13 +38,14 @@ License: MIT
38
38
  """
39
39
  from enum import Enum
40
40
  from typing import Dict, List, Union
41
- from loguru import logger
41
+
42
42
  from email_validator import (
43
43
  EmailNotValidError,
44
44
  EmailUndeliverableError,
45
45
  caching_resolver,
46
46
  validate_email,
47
47
  )
48
+ from loguru import logger
48
49
 
49
50
 
50
51
  class DNSType(Enum):
@@ -30,8 +30,9 @@ DateUpdated: 2024/07/24
30
30
 
31
31
  License: MIT
32
32
  """
33
- import time
34
33
  import logging
34
+ import os
35
+ import time
35
36
  from pathlib import Path
36
37
  from uuid import uuid4
37
38
 
@@ -204,7 +205,7 @@ def config_log(
204
205
 
205
206
  if intercept_standard_logging:
206
207
  # Add interceptor handler to all existing loggers
207
- for name in logging.root.manager.loggerDict:
208
+ for name in logging.Logger.manager.loggerDict:
208
209
  logging.getLogger(name).addHandler(InterceptHandler())
209
210
 
210
211
  # Add interceptor handler to the root logger
@@ -215,56 +216,42 @@ def config_log(
215
216
 
216
217
 
217
218
  class ResilientFileSink:
218
- """
219
- A file sink designed for resilience, capable of retrying write operations.
220
-
221
- This class implements a resilient file writing mechanism that attempts to write messages to a file, retrying the operation a specified number of times if it fails. This is particularly useful in scenarios where write operations might intermittently fail due to temporary issues such as file system locks or networked file system delays.
222
-
223
- Attributes:
224
- path (str): The path to the file where messages will be written.
225
- max_retries (int): The maximum number of retry attempts for a failed write operation.
226
- retry_delay (float): The delay between retry attempts, in seconds.
227
-
228
- Methods:
229
- write(message): Attempts to write a message to the file, retrying on failure up to `max_retries` times.
230
- """
231
- def __init__(self, path, max_retries=3, retry_delay=1.0, formatter=None):
219
+ def __init__(self, path, retry_count=5, retry_delay=1):
232
220
  self.path = path
233
- self.max_retries = max_retries
221
+ self.retry_count = retry_count
234
222
  self.retry_delay = retry_delay
235
- self._formatter = formatter or logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
236
-
237
- @property
238
- def formatter(self):
239
- return self._formatter
240
-
241
- @formatter.setter
242
- def formatter(self, value):
243
- self._formatter = value
223
+ # Ensure the directory exists
224
+ os.makedirs(os.path.dirname(path), exist_ok=True)
244
225
 
245
- def write(self, message):
246
- for attempt in range(self.max_retries):
226
+ def __call__(self, message): # pragma: no cover
227
+ attempt = 0
228
+ while attempt < self.retry_count:
247
229
  try:
230
+ # Open the file in append mode and write the message
248
231
  with open(self.path, 'a') as file:
249
- formatted_message = self.formatter.format(message) if self._formatter else message
250
- file.write(formatted_message + '\n') # Ensure newline
251
- break # Successfully written, break the loop
252
- except FileNotFoundError:
253
- if attempt < self.max_retries - 1:
254
- time.sleep(self.retry_delay) # Wait before retrying
255
- else:
256
- raise # Reraise if max retries exceeded
232
+ file.write(message)
233
+ break # Exit the loop if write succeeds
234
+ except Exception as e:
235
+ attempt += 1
236
+ time.sleep(self.retry_delay)
237
+ if attempt == self.retry_count:
238
+ print(f"Failed to log message after {self.retry_count} attempts: {e}")
257
239
 
258
240
 
259
241
  if file_sink:
260
- # Create an instance of ResilientFileSink
242
+ # Create an instance of ResilientFileSink if file_sink is True
261
243
  resilient_sink = ResilientFileSink(str(log_path))
262
244
 
263
- # Configure the logger to use the ResilientFileSink
245
+ # Append the ResilientFileSink instance to the handlers list
264
246
  basic_config_handlers.append(resilient_sink)
265
247
 
266
248
  if intercept_standard_logging:
249
+ # Append an InterceptHandler instance to the handlers list if intercept_standard_logging is True
267
250
  basic_config_handlers.append(InterceptHandler())
268
251
 
252
+ if len(basic_config_handlers) > 0:
253
+ # Configure the root logger if there are any handlers specified
254
+ logging.basicConfig(handlers=basic_config_handlers, level=logging_level.upper())
255
+
269
256
  if len(basic_config_handlers) > 0:
270
257
  logging.basicConfig(handlers=basic_config_handlers, level=logging_level.upper())
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
8
 
9
9
  [project]
10
10
  name = "devsetgo_lib"
11
- version = "0.13.2"
11
+ version = "0.13.3"
12
12
  requires-python = ">=3.9"
13
13
  description = """
14
14
  DevSetGo Library is a Python library offering reusable functions for efficient coding. It includes file operations, calendar utilities, pattern matching, advanced logging with loguru, FastAPI endpoints, async database handling, and email validation. Designed for ease of use and versatility, it's a valuable tool for Python developers.
File without changes
File without changes
File without changes