Python: package setup with logger (#125)

* package setup with logger

* set config once

* add unit test workflow

* updated naming of workflows

* add mypy check

* renamed job

* smaller name

* ignore certain files for ruff

* remove assignment

* fix ruff config

* removed pyright from pre-commit

* fixed logging test

* fix mypy setup

* mypy fix

* mypy

* mypy
This commit is contained in:
Eduard van Valkenburg
2025-07-02 17:17:28 +02:00
committed by GitHub
Unverified
parent 0c61aee8e5
commit 7cc29fe192
27 changed files with 699 additions and 21 deletions
+27
View File
@@ -0,0 +1,27 @@
# Copyright (c) Microsoft. All rights reserved.
import importlib
import importlib.metadata
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode
_IMPORTS = {
"get_logger": "._logging",
}
def __getattr__(name: str):
if name == "__version__":
return __version__
if name in _IMPORTS:
submod_name = _IMPORTS[name]
module = importlib.import_module(submod_name, package=__name__)
return getattr(module, name)
raise AttributeError(f"module {__name__} has no attribute {name}")
def __dir__():
return [*list(_IMPORTS.keys()), "__version__"]
+11
View File
@@ -0,0 +1,11 @@
# Copyright (c) Microsoft. All rights reserved.
import importlib.metadata
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0" # Fallback for development mode
from ._logging import get_logger
__all__ = ["__version__", "get_logger"]
View File
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) Microsoft. All rights reserved.
import logging
from .exceptions import AgentFrameworkException
logging.basicConfig(
format="[%(asctime)s - %(pathname)s:%(lineno)d - %(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
def get_logger(name: str = "agent_framework") -> logging.Logger:
"""Get a logger with the specified name, defaulting to 'agent_framework'.
Args:
name (str): The name of the logger. Defaults to 'agent_framework'.
Returns:
logging.Logger: The configured logger instance.
"""
if not name.startswith("agent_framework"):
raise AgentFrameworkException("Logger name must start with 'agent_framework'.")
return logging.getLogger(name)
View File
View File
+7
View File
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft. All rights reserved.
class AgentFrameworkException(Exception):
"""Base class for exceptions in the Agent Framework."""
pass
View File
View File