From 3527576f6978ffaa330d5fe053ffbe17b3c9e325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=AE=E6=98=8A?= Date: Mon, 2 Dec 2024 12:05:04 +0800 Subject: [PATCH] add loguru (#7) --- pdm.lock | 32 ++++++++++++++++++++++++++++++-- pyproject.toml | 2 +- src/easybuilder/__init__.py | 2 +- src/easybuilder/checker.py | 12 +++++++----- src/easybuilder/worker.py | 6 ++++++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/pdm.lock b/pdm.lock index 6128797..2040ee1 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:1b330fcac28c2ae2aa2241fb0e4793ef3dd8da5c21aaeb65748e977b856cec79" +content_hash = "sha256:cb4fd0a228e11aa8cc941e1d010a13bbfe679d65ec15c2a610c8e30a141de35c" [[metadata.targets]] requires_python = ">=3.9" @@ -15,7 +15,7 @@ name = "colorama" version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." -groups = ["dev"] +groups = ["default", "dev"] marker = "sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, @@ -45,6 +45,22 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "loguru" +version = "0.7.2" +requires_python = ">=3.5" +summary = "Python logging made (stupidly) simple" +groups = ["default"] +dependencies = [ + "aiocontextvars>=0.2.0; python_version < \"3.7\"", + "colorama>=0.3.4; sys_platform == \"win32\"", + "win32-setctime>=1.0.0; sys_platform == \"win32\"", +] +files = [ + {file = "loguru-0.7.2-py3-none-any.whl", hash = "sha256:003d71e3d3ed35f0f8984898359d65b79e5b21943f78af86aa5491210429b8eb"}, + {file = "loguru-0.7.2.tar.gz", hash = "sha256:e671a53522515f34fd406340ee968cb9ecafbc4b36c679da03c18fd8d0bd51ac"}, +] + [[package]] name = "packaging" version = "24.2" @@ -97,3 +113,15 @@ files = [ {file = "tomli-2.1.0-py3-none-any.whl", hash = "sha256:a5c57c3d1c56f5ccdf89f6523458f60ef716e210fc47c4cfb188c5ba473e0391"}, {file = "tomli-2.1.0.tar.gz", hash = "sha256:3f646cae2aec94e17d04973e4249548320197cfabdf130015d023de4b74d8ab8"}, ] + +[[package]] +name = "win32-setctime" +version = "1.1.0" +requires_python = ">=3.5" +summary = "A small Python utility to set file creation time on Windows" +groups = ["default"] +marker = "sys_platform == \"win32\"" +files = [ + {file = "win32_setctime-1.1.0-py3-none-any.whl", hash = "sha256:231db239e959c2fe7eb1d7dc129f11172354f98361c4fa2d6d2d7e278baa8aad"}, + {file = "win32_setctime-1.1.0.tar.gz", hash = "sha256:15cf5750465118d6929ae4de4eb46e8edae9a5634350c01ba582df868e932cb2"}, +] diff --git a/pyproject.toml b/pyproject.toml index b3eeb31..aef596b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = "Default template for PDM package" authors = [ {name = "svtter", email = "svtter@qq.com"}, ] -dependencies = [] +dependencies = ["loguru>=0.7.2"] requires-python = ">=3.9" readme = "README.md" license = {text = "MIT"} diff --git a/src/easybuilder/__init__.py b/src/easybuilder/__init__.py index d3ec452..3ced358 100644 --- a/src/easybuilder/__init__.py +++ b/src/easybuilder/__init__.py @@ -1 +1 @@ -__version__ = "0.2.0" +__version__ = "0.2.1" diff --git a/src/easybuilder/checker.py b/src/easybuilder/checker.py index 9e29cdf..73694d1 100644 --- a/src/easybuilder/checker.py +++ b/src/easybuilder/checker.py @@ -1,16 +1,18 @@ import os +from loguru import logger + def check_clean(folder: str = "."): # 检查git仓库是否有未提交的更改 os.chdir(folder) result = os.popen("git status --porcelain").read() if not os.path.exists(".git"): - print("错误: 当前目录不是git仓库") + logger.error("错误: 当前目录不是git仓库") exit(1) if result: - print("错误: git仓库不干净,请先提交所有更改") - print("未提交的更改:") - print(result) + logger.error("错误: git仓库不干净,请先提交所有更改") + logger.error("未提交的更改:") + logger.error(result) exit(1) - print("git仓库状态检查通过") + logger.info("git仓库状态检查通过") diff --git a/src/easybuilder/worker.py b/src/easybuilder/worker.py index a598a9f..88722c9 100644 --- a/src/easybuilder/worker.py +++ b/src/easybuilder/worker.py @@ -1,3 +1,5 @@ +import loguru + from . import task @@ -9,6 +11,10 @@ class Worker(object): def __init__(self): pass + def get_logger(self): + """using loguru for logger""" + return loguru.logger + def before_run(self): for t in self.default_tasks: t().action()