pkg-40400 0.1.0__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.
pkg_40400/__init__.py ADDED
@@ -0,0 +1,15 @@
1
+ from pkg_40400.core.config import ClsSettings
2
+ from pkg_40400.core.decorator import ClsFalseError, raise_on_false
3
+ from pkg_40400.core.logger import get_logger, initialize_logger
4
+
5
+ __version__ = "0.1.0"
6
+ version = __version__
7
+
8
+ __all__ = (
9
+ "ClsSettings",
10
+ "ClsFalseError",
11
+ "get_logger",
12
+ "initialize_logger",
13
+ "raise_on_false",
14
+ "version",
15
+ )
pkg_40400/cli.py ADDED
@@ -0,0 +1,25 @@
1
+ """
2
+ Calculator CLI - pkg-40400
3
+
4
+ A command-line interface for basic arithmetic operations using click.
5
+ """
6
+
7
+ import sys
8
+
9
+ from pkg_40400 import get_logger, initialize_logger, version
10
+
11
+
12
+ def main():
13
+ """Main entry point for the CLI."""
14
+ initialize_logger()
15
+ logger = get_logger()
16
+ try:
17
+ logger.info(version)
18
+ except Exception as e:
19
+ logger = get_logger()
20
+ logger.error(str(e))
21
+ sys.exit(1)
22
+
23
+
24
+ if __name__ == "__main__": # pragma: no cover
25
+ main()
File without changes
@@ -0,0 +1,93 @@
1
+ import os
2
+ import pathlib
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class ClsSettings:
8
+ """
9
+ Centralized configuration settings.
10
+
11
+ This dataclass reads environment variables on instantiation and computes
12
+ derived values. It is designed to be instantiated once at application
13
+ startup and passed to components that need configuration.
14
+
15
+ Note: This dataclass is immutable (frozen). All fields are set during
16
+ initialization and cannot be modified afterward.
17
+ """
18
+
19
+ # Environment-dependent configuration
20
+ ENV: str
21
+ DEBUG: bool
22
+ LOGGERS_NAME: str
23
+
24
+ # Logging file configuration (read from environment)
25
+ LOG_CFG_FILE: str = "logging.yaml"
26
+ LOG_DST_FILE: str = "app.log"
27
+
28
+ # File paths (computed from environment variables)
29
+ PROJECT_ROOT: pathlib.Path = None # type: ignore
30
+ LOG_CFG_PATH: pathlib.Path = None # type: ignore
31
+ LOG_LEVEL: int = None # type: ignore
32
+
33
+ def __init__(
34
+ self,
35
+ env: str | None = None,
36
+ debug: bool | None = None,
37
+ loggers_name: str | None = None,
38
+ ) -> None:
39
+ """
40
+ Initialize configuration from environment variables.
41
+
42
+ Args:
43
+ env: Override ENV value. If None, reads from ENV env var.
44
+ debug: Override DEBUG value. If None, reads from DEBUG env var.
45
+ loggers_name: Override LOGGERS_NAME value. If None, reads from LOGGERS_NAME env var.
46
+ """
47
+ # Set defaults at initialization time
48
+ object.__setattr__(self, "ENV", self._validate_env(env))
49
+ object.__setattr__(self, "DEBUG", self._validate_debug(debug))
50
+ object.__setattr__(self, "LOGGERS_NAME", self._validate_loggers_name(loggers_name))
51
+ object.__setattr__(self, "LOG_CFG_FILE", os.getenv("LOG_CFG_FILE", "logging.yaml"))
52
+ object.__setattr__(self, "LOG_DST_FILE", os.getenv("LOG_DST_FILE", "app.log"))
53
+
54
+ # Compute derived values once
55
+ object.__setattr__(self, "PROJECT_ROOT", self._compute_project_root())
56
+ object.__setattr__(self, "LOG_CFG_PATH", self._compute_log_cfg_path())
57
+ object.__setattr__(self, "LOG_LEVEL", self._compute_log_level())
58
+
59
+ def _validate_env(self, env: str | None = None) -> str:
60
+ """Validate and normalize ENV value."""
61
+ value = env if env is not None else os.getenv("ENV", "development")
62
+ value = value.lower()
63
+ valid_values = ("development", "production", "local")
64
+ return value if value in valid_values else "development"
65
+
66
+ def _validate_debug(self, debug: bool | None = None) -> bool:
67
+ """Validate and normalize DEBUG value."""
68
+ if debug is not None:
69
+ return bool(debug)
70
+
71
+ debug_str = os.getenv("DEBUG", "true")
72
+ return debug_str.lower() in ("true", "1", "t", "yes")
73
+
74
+ def _validate_loggers_name(self, loggers_name: str | None = None) -> str:
75
+ """Validate and normalize LOGGERS_NAME value."""
76
+ value = loggers_name if loggers_name is not None else os.getenv("LOGGERS_NAME", "default")
77
+ value = value.lower()
78
+ valid_values = ("default", "docker", "local", "lambda", "library")
79
+ return value if value in valid_values else "default"
80
+
81
+ def _compute_project_root(self) -> pathlib.Path:
82
+ """Compute the project root directory."""
83
+ # The config module is at src/pkg_40400/core/config.py
84
+ # So we need to go up 3 levels to get to src/, then up 1 more to get to project root
85
+ return pathlib.Path(__file__).parent.parent.parent.parent
86
+
87
+ def _compute_log_cfg_path(self) -> pathlib.Path:
88
+ """Compute the path to the logging configuration file."""
89
+ return self.PROJECT_ROOT / "config" / self.LOG_CFG_FILE
90
+
91
+ def _compute_log_level(self) -> int:
92
+ """Compute the log level based on DEBUG setting."""
93
+ return 10 if self.DEBUG else 20 # 10: DEBUG, 20: INFO
@@ -0,0 +1,77 @@
1
+ from functools import wraps
2
+ from typing import Callable, Optional, TypeVar
3
+
4
+ from pkg_40400.core.logger import get_logger
5
+
6
+ F = TypeVar("F", bound=Callable[..., bool])
7
+
8
+
9
+ class ClsFalseError(ValueError):
10
+ """Exception raised when a function decorated with @raise_on_false returns False."""
11
+
12
+ def __init__(self, func_name: str, custom_message: Optional[str] = None) -> None:
13
+ """
14
+ Initialize the exception.
15
+
16
+ Args:
17
+ func_name: Name of the function that returned False.
18
+ custom_message: Optional custom message to include in the error.
19
+ """
20
+ self.func_name = func_name
21
+ self.custom_message = custom_message
22
+
23
+ if custom_message is not None:
24
+ message = f"{func_name} returned '{custom_message}'"
25
+ else:
26
+ message = f"{func_name} returned 'False'"
27
+ super().__init__(message)
28
+
29
+
30
+ def raise_on_false(
31
+ exception_type: type[ValueError] = ClsFalseError,
32
+ custom_message: Optional[str] = None,
33
+ log_error: bool = True,
34
+ ):
35
+ """
36
+ Decorator that raises an exception if the decorated function returns False.
37
+
38
+ Args:
39
+ exception_type: The exception type to raise. Must be a subclass of ValueError.
40
+ custom_message: Optional custom message to include in the exception.
41
+ log_error: If True, log the error using the configured logger before raising.
42
+
43
+ Returns:
44
+ A decorator function.
45
+
46
+ Usage:
47
+ @raise_on_false()
48
+ def validate_input(data: dict) -> bool:
49
+ return "required_key" in data
50
+
51
+ @raise_on_false(custom_message="Data validation failed", log_error=False)
52
+ def process_data(data: dict) -> bool:
53
+ return validate_required_fields(data)
54
+ """
55
+ if not issubclass(exception_type, ValueError):
56
+ raise TypeError(f"exception_type must be a subclass of ValueError, got {exception_type}")
57
+
58
+ def decorator(func: F) -> F:
59
+ @wraps(func)
60
+ def wrapper(*args, **kwargs):
61
+ result = func(*args, **kwargs)
62
+
63
+ if not result:
64
+ exception = exception_type(func.__name__, custom_message)
65
+
66
+ if log_error:
67
+ logger = get_logger()
68
+ # Use stacklevel=2 to point to the caller (wrapper's caller), not the decorator
69
+ logger.error(str(exception), stacklevel=2)
70
+
71
+ raise exception
72
+
73
+ return result
74
+
75
+ return wrapper # type: ignore[return-value]
76
+
77
+ return decorator
@@ -0,0 +1,84 @@
1
+ """Logging module with YAML configuration support."""
2
+
3
+ import logging
4
+ from logging import config
5
+
6
+ import yaml
7
+
8
+ from pkg_40400.core.config import ClsSettings
9
+
10
+ # Placeholder logger - will be replaced on first initialization
11
+
12
+ Logger: logging.Logger = logging.getLogger("default")
13
+ _initialized: bool = False
14
+
15
+
16
+ def initialize_logger() -> logging.Logger:
17
+ """Initialize the package logger with YAML configuration.
18
+
19
+ This function configures logging using the YAML file specified in
20
+ config/constants.yaml or environment variables. It should only be called
21
+ once during application startup.
22
+
23
+ Returns:
24
+ The configured Logger instance.
25
+
26
+ Notes:
27
+ - Environment variables can override logging settings
28
+ - Falls back to basicConfig if YAML file cannot be loaded
29
+ """
30
+ global Logger, _initialized
31
+
32
+ if _initialized:
33
+ # On subsequent calls, update the level if needed
34
+ settings = ClsSettings()
35
+ Logger.setLevel(settings.LOG_LEVEL)
36
+ return Logger
37
+
38
+ settings = ClsSettings()
39
+ log_level = settings.LOG_LEVEL
40
+ log_config_path = settings.LOG_CFG_PATH
41
+ logger_name = settings.LOGGERS_NAME
42
+
43
+ Logger = logging.getLogger(logger_name)
44
+
45
+ # If the logger already has handlers attached, assume configuration has
46
+ # already been performed and skip reconfiguration.
47
+ if Logger.handlers:
48
+ Logger.setLevel(log_level)
49
+ _initialized = True
50
+ return Logger
51
+
52
+ try:
53
+ with open(log_config_path, "r") as f:
54
+ config_dict = yaml.safe_load(f)
55
+ config.dictConfig(config_dict)
56
+ except Exception as e:
57
+ LOG_FORMAT = "%(asctime)s.%(msecs)03d::%(levelname)s::%(funcName)s::%(filename)s:%(lineno)s::%(message)s"
58
+ logging.basicConfig(level=log_level, format=LOG_FORMAT)
59
+ Logger.warning(e)
60
+
61
+ Logger.setLevel(log_level)
62
+ _initialized = True
63
+ return Logger
64
+
65
+
66
+ def get_logger(name: str | None = None) -> logging.Logger:
67
+ """Get a logger instance by name.
68
+
69
+ This function provides flexibility to get named loggers throughout the
70
+ application without reinitializing the logging system.
71
+
72
+ Args:
73
+ name: The name of the logger to retrieve. If None, uses the configured
74
+ logger name from the global Logger. Defaults to None.
75
+
76
+ Returns:
77
+ A Logger instance with the specified name.
78
+ """
79
+ if name is None:
80
+ return Logger
81
+ return logging.getLogger(name)
82
+
83
+
84
+ setup_logging = initialize_logger
File without changes
File without changes
File without changes
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.5
2
+ Name: pkg-40400
3
+ Version: 0.1.0
4
+ Project-URL: Changelog, https://github.com/tagdots-dev/bobo-test/blob/main/CHANGELOG.md
5
+ Project-URL: Documentation, https://github.com/tagdots-dev/bobo-test/blob/main/README.md
6
+ Project-URL: Homepage, https://github.com/tagdots-dev
7
+ Project-URL: Issues, https://github.com/tagdots-dev/bobo-test/issues
8
+ Project-URL: Repository, https://github.com/tagdots-dev/bobo-test
9
+ Author-email: developers <developers@tagdots.com>
10
+ License-File: LICENSE
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Software Development :: Build Tools
17
+ Requires-Python: >=3.12.10
18
+ Requires-Dist: pyyaml~=6.0.3
19
+ Description-Content-Type: text/markdown
20
+
21
+ # bobo-test
22
+
23
+ repo test
@@ -0,0 +1,14 @@
1
+ pkg_40400/__init__.py,sha256=wDvtIjXO5TdNBav5ry-bNIB7HY0C_idNJZhS7Yl7PWY,357
2
+ pkg_40400/cli.py,sha256=I6z4ccZNjbCdJOwAeivIqgesiL9X5bdBB3zVT9Dk2mI,488
3
+ pkg_40400/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ pkg_40400/core/config.py,sha256=mufT5KGeWiaCWQKTpYpqoyxZeHl_KoezAcd7XWTaHqs,3861
5
+ pkg_40400/core/decorator.py,sha256=SijhkVAlL-7nDLR4K0WbHfs-vH9s94XwL9xhRC3Invk,2495
6
+ pkg_40400/core/logger.py,sha256=bfgXOor_mCxJm-EggkHWwHQJb-mDQlCHtcerzHmep8Y,2465
7
+ pkg_40400/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ pkg_40400/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ pkg_40400/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ pkg_40400-0.1.0.dist-info/METADATA,sha256=aCV8cLMFB8FRduDaG5Pn2cdbEjuIENSv4MSt9dhC1L4,921
11
+ pkg_40400-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
12
+ pkg_40400-0.1.0.dist-info/entry_points.txt,sha256=ptbWAIgF7fAkDySVI8N8JmfkY_cmFrkvjUGer1KTN0Q,49
13
+ pkg_40400-0.1.0.dist-info/licenses/LICENSE,sha256=wAf7nWZg78po80uuZfneGnerTtGFxdVSv8uFSMfj2iA,1070
14
+ pkg_40400-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pkg-40400 = pkg_40400.cli:main
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TagDots, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6
+ and associated documentation files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
+ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.