generated from seyLu/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/pip/twine-5.1.0
- Loading branch information
Showing
13 changed files
with
132 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# core | ||
typer[all]==0.12.0 | ||
requests==2.31.0 | ||
requests==2.32.3 | ||
python-dotenv==1.0.1 | ||
PyYAML==6.0.1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
import os | ||
from logging import Logger | ||
from logging.config import fileConfig | ||
|
||
import rich | ||
|
||
from ghlabel.config import is_ghlabel_debug_mode | ||
|
||
GHLABEL_LOGS_DIR: str = os.path.join("logs") | ||
|
||
|
||
class GhlabelLogger: | ||
def __init__(self) -> None: | ||
self.logger: GhlabelLogger | ||
|
||
if not os.path.isdir(GHLABEL_LOGS_DIR): | ||
os.makedirs(GHLABEL_LOGS_DIR) | ||
fileConfig(os.path.join(os.path.dirname(__file__), "logging.ini")) | ||
|
||
def init(self, module_name: str) -> "GhlabelLogger": | ||
"""NOTE: pass in __name__ as module name""" | ||
logger: Logger = logging.getLogger(module_name) | ||
|
||
if is_ghlabel_debug_mode(): | ||
logger.setLevel(level=logging.DEBUG) | ||
else: | ||
logger.setLevel(level=logging.ERROR) | ||
|
||
self.logger = logger # type: ignore[assignment] | ||
return self.logger | ||
|
||
def exception(self, ex: Exception) -> None: | ||
rich.print( | ||
f"\nSomething went wrong. See logs ([blue underline]{GHLABEL_LOGS_DIR}[/blue underline]) for more details.\n" | ||
) | ||
rich.print(" [[red]Exception[/red]]:", str(ex)) | ||
self.logger.exception(ex) | ||
|
||
def error(self, message: str) -> None: | ||
self.logger.error(message) | ||
|
||
def warning(self, message: str) -> None: | ||
self.logger.warning(message) | ||
|
||
def info(self, message: str) -> None: | ||
self.logger.info(message) | ||
|
||
|
||
ghlabel_logger: GhlabelLogger = GhlabelLogger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
g_GHLABEL_DEBUG_MODE = False | ||
|
||
|
||
def set_ghlabel_debug_mode(is_debug: bool) -> None: | ||
global g_GHLABEL_DEBUG_MODE # noqa: PLW0603 | ||
g_GHLABEL_DEBUG_MODE = is_debug | ||
|
||
|
||
def is_ghlabel_debug_mode() -> bool: | ||
global g_GHLABEL_DEBUG_MODE # noqa: PLW0602 | ||
return g_GHLABEL_DEBUG_MODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
keys=root | ||
|
||
[logger_root] | ||
level=DEBUG | ||
level=INFO | ||
handlers=screen,file | ||
|
||
[formatters] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.