baodebug 0.1.0__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.
baodebug-0.1.0/LICENSE ADDED
File without changes
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: baodebug
3
+ Version: 0.1.0
4
+ Summary: An simple Python package for debug
5
+ Author-email: Runqiu Bao <bao@robot.t.u-tokyo.ac.jp>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: dumpvisz,logging
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+
15
+ ## Python usage
16
+
17
+ ```
18
+ import baodebug
19
+
20
+ baodebug.debugutils.ConfigureRootLogger("info") # config logger format
21
+ baodebug.debugutils.SetDebugPath("/root/visz/") # create debug folder here and set to os.environ["DEBUG_PATH"]
22
+
23
+ import logging
24
+ logger = logging.getLogger(__name__)
25
+
26
+ logger.info("this will be printed in green")
27
+ ```
@@ -0,0 +1,13 @@
1
+ ## Python usage
2
+
3
+ ```
4
+ import baodebug
5
+
6
+ baodebug.debugutils.ConfigureRootLogger("info") # config logger format
7
+ baodebug.debugutils.SetDebugPath("/root/visz/") # create debug folder here and set to os.environ["DEBUG_PATH"]
8
+
9
+ import logging
10
+ logger = logging.getLogger(__name__)
11
+
12
+ logger.info("this will be printed in green")
13
+ ```
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"] # Hatchling as the build backend
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "baodebug" # Package name
7
+ version = "0.1.0" # Package version
8
+ description = "An simple Python package for debug"
9
+ readme = "README.md" # Path to the README file
10
+ license = "MIT"
11
+ authors = [
12
+ {name = "Runqiu Bao", email = "bao@robot.t.u-tokyo.ac.jp"}
13
+ ]
14
+ dependencies = [] # List dependencies here (e.g., requests, numpy)
15
+ keywords = ["logging", "dumpvisz"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent"
20
+ ]
21
+ requires-python = ">=3.8" # Specify Python version compatibility
22
+
23
+ [tool.hatch.metadata]
24
+ allow-direct-references = true # Optional: for direct dependency references
@@ -0,0 +1 @@
1
+ from . import debugutils
@@ -0,0 +1,66 @@
1
+ import logging
2
+ import cv2
3
+ import os
4
+ import shutil
5
+
6
+
7
+ def SetDebugPath(debug_path):
8
+ if os.path.exists(debug_path):
9
+ shutil.rmtree(debug_path)
10
+ os.makedirs(debug_path, exist_ok=False)
11
+ os.environ['DEBUG_PATH'] = debug_path
12
+
13
+
14
+ logLevelMap = {
15
+ "debug": logging.DEBUG,
16
+ "info": logging.INFO,
17
+ "warning": logging.WARNING,
18
+ "error": logging.ERROR,
19
+ "critical": logging.CRITICAL
20
+ }
21
+
22
+
23
+ class ColorFormatter(logging.Formatter):
24
+
25
+ grey = "\x1b[38;20m"
26
+ yellow = "\x1b[33;20m"
27
+ green = "\x1b[32;20m"
28
+ cyan = "\x1b[36;20m"
29
+ blue = "\x1b[34;20m"
30
+ red = "\x1b[31;20m"
31
+ reset = "\x1b[0m"
32
+ format = "%(asctime)s - %(name)s - %(levelname)s - (%(filename)s:%(lineno)d): %(message)s"
33
+
34
+ FORMATS = {
35
+ logging.DEBUG: blue + format + reset,
36
+ logging.INFO: green + format + reset,
37
+ logging.WARNING: yellow + format + reset,
38
+ logging.ERROR: red + format + reset,
39
+ logging.CRITICAL: cyan + format + reset
40
+ }
41
+
42
+ def format(self, record):
43
+ log_fmt = self.FORMATS.get(record.levelno)
44
+ formatter = logging.Formatter(log_fmt)
45
+ return formatter.format(record)
46
+
47
+
48
+ def ConfigureRootLogger(logLevel):
49
+ """
50
+ configure the root logger formats and handlers.
51
+ """
52
+ rootLogger = logging.getLogger()
53
+ rootLogger.setLevel(logLevelMap[logLevel.lower()])
54
+
55
+ consoleHandler = logging.StreamHandler()
56
+ consoleHandler.setLevel(logLevelMap[logLevel.lower()])
57
+ consoleFormatter = ColorFormatter()
58
+ consoleHandler.setFormatter(consoleFormatter)
59
+
60
+ rootLogger.addHandler(consoleHandler)
61
+
62
+ rootLogger.critical("(set up root logger..)")
63
+
64
+
65
+ def dump_image(image, path):
66
+ cv2.imwrite(path, image)