Skip to content

Commit c2c5b28

Browse files
committed
[PATCH] Formatting changes
1 parent 31ec400 commit c2c5b28

File tree

4 files changed

+20
-88
lines changed

4 files changed

+20
-88
lines changed

pyproject.toml

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -106,70 +106,8 @@ testpaths = [
106106

107107

108108
[tool.ruff]
109-
lint.select = [
110-
"A", # Builtins
111-
# "AIR", # Airflow
112-
"ANN", # Annotations
113-
"ARG", # Unused arguments
114-
"ASYNC", # Asynchronous code
115-
"B", # Bugbear
116-
"BLE", # Blind except
117-
"C4", # Comprehensions
118-
"C90", # mccabe
119-
"COM", # Commas
120-
# "CPY", # Copyright
121-
"D1", # Undocumented public elements
122-
"D2", # Docstring conventions
123-
"D3", # Triple double quotes
124-
"D4", # Docstring text format
125-
# "DJ", # Django
126-
"DTZ", # Datetimes
127-
"E", # Errors
128-
"EM", # Error messages
129-
"ERA", # Commented-out code
130-
"EXE", # Executable
131-
"F", # Pyflakes
132-
"FA", # __future__ annotations
133-
# "FAST", # FastAPI
134-
"FBT", # "Boolean trap"
135-
"FIX", # "FIXME"-comments
136-
"FLY", # F-strings
137-
"FURB", # Refurb
138-
"G", # Logging format
139-
"I", # Isort
140-
"ICN", # Import conventions
141-
"INP", # Disallow PEP-420 (Implicit namespace packages)
142-
"INT", # gettext
143-
"ISC", # Implicit str concat
144-
"LOG", # Logging
145-
"N", # PEP-8 Naming
146-
# "NPY", # Numpy
147-
# "PD", # Pandas
148-
"PERF", # Unnecessary performance costs
149-
"PGH", # Pygrep hooks
150-
"PIE", # Unnecessary code
151-
"PL", # Pylint
152-
"PT", # Pytest
153-
"PTH", # Use Pathlib
154-
"PYI", # Stub files
155-
"Q", # Quotes
156-
"RET", # Return
157-
"RUF", # Ruff
158-
"RSE", # Raise
159-
"S", # Bandit
160-
"SIM", # Code simplification
161-
"SLF", # Private member access
162-
"SLOT", # __slots__
163-
"T10", # Debugger
164-
"T20", # Print
165-
"TC", # Type checking
166-
"TD", # "TODO"-comments
167-
"TID", # Tidy imports
168-
"TRY", # Exception handling
169-
"UP", # Pyupgrade
170-
"W", # Warnings
171-
"YTT", # sys.version
172-
]
109+
lint.fixable = ["ALL"]
110+
lint.select = ["ALL"]
173111
lint.ignore = [
174112
"D203", # One blank line before class docstring
175113
"D212", # Multi-line summary first line

src/project_name/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
PACKAGE_NAME = "project_name"
1414

1515
with pkg_resources.as_file(pkg_resources.files(project_name)) as package_dir:
16-
DEFAULT_CONFIG_FILE_PATH = package_dir / 'logger_config.toml'
16+
DEFAULT_CONFIG_FILE_PATH = package_dir / "logger_config.toml"
1717

1818
LOGGER_CONFIG_FILE = Path(os.environ.get("PROJECT_NAME_LOGGER_CONFIG_FILE", DEFAULT_CONFIG_FILE_PATH))

src/project_name/logger.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
ROOT_LOGGER_NAME = PACKAGE_NAME
2424

25-
__all__ = ('ROOT_LOGGER_NAME', 'setup_logging')
25+
__all__ = ("ROOT_LOGGER_NAME", "setup_logging")
2626

2727

2828
class RecordAttrs(str, Enum):
@@ -70,18 +70,16 @@ class ColouredFormatter(logging.Formatter):
7070
def format(self, record: logging.LogRecord) -> str:
7171
"""Format the log record."""
7272
log_level_colours = {
73-
logging.CRITICAL: '\033[31;1;40m', # Red, bold
74-
logging.ERROR: '\033[31;40m', # Red
75-
logging.WARNING: '\033[33;40m', # Yellow
76-
logging.INFO: '\033[32;40m', # Green
77-
logging.DEBUG: '\033[36;40m', # Cyan
73+
logging.CRITICAL: "\033[31;1;40m", # Red, bold
74+
logging.ERROR: "\033[31;40m", # Red
75+
logging.WARNING: "\033[33;40m", # Yellow
76+
logging.INFO: "\033[32;40m", # Green
77+
logging.DEBUG: "\033[36;40m", # Cyan
7878
}
79-
reset = '\033[0m'
79+
reset = "\033[0m"
8080

8181
record.msg = f"{log_level_colours.get(record.levelno, reset)}{record.msg}{reset}"
82-
record.levelname = (
83-
f"{log_level_colours.get(record.levelno, reset)}{record.levelname:^8}{reset}"
84-
)
82+
record.levelname = f"{log_level_colours.get(record.levelno, reset)}{record.levelname:^8}{reset}"
8583

8684
return super().format(record)
8785

@@ -122,11 +120,7 @@ class JSONLogFormatter(logging.Formatter):
122120
@override
123121
def __init__(self, *, fmt_keys: FormatKeys | None = None) -> None:
124122
super().__init__()
125-
self.fmt_keys = (
126-
fmt_keys
127-
if fmt_keys is not None
128-
else FormatKeys()
129-
)
123+
self.fmt_keys = fmt_keys if fmt_keys is not None else FormatKeys()
130124

131125
@override
132126
def format(self, record: logging.LogRecord) -> str:
@@ -135,18 +129,18 @@ def format(self, record: logging.LogRecord) -> str:
135129

136130
def _prepare_log_dict(self, record: logging.LogRecord) -> LogDict:
137131
required_fields: LogDict = {
138-
'message': record.getMessage(),
139-
'timestamp': dt.datetime.fromtimestamp(
132+
"message": record.getMessage(),
133+
"timestamp": dt.datetime.fromtimestamp(
140134
record.created,
141135
tz=dt.timezone.utc,
142136
),
143137
}
144138

145139
if record.exc_info is not None:
146-
required_fields['exc_info'] = self.formatException(record.exc_info)
140+
required_fields["exc_info"] = self.formatException(record.exc_info)
147141

148142
if record.stack_info is not None:
149-
required_fields['stack_info'] = self.formatStack(record.stack_info)
143+
required_fields["stack_info"] = self.formatStack(record.stack_info)
150144

151145
message: LogDict = { # type: ignore[assignment]
152146
key: msg_val
@@ -166,8 +160,8 @@ def _prepare_log_dict(self, record: logging.LogRecord) -> LogDict:
166160

167161
def setup_logging() -> None:
168162
"""Set up logging."""
169-
(Path.cwd() / 'logs').mkdir(exist_ok=True)
170-
logger_data = LOGGER_CONFIG_FILE.read_text(encoding='utf-8')
163+
(Path.cwd() / "logs").mkdir(exist_ok=True)
164+
logger_data = LOGGER_CONFIG_FILE.read_text(encoding="utf-8")
171165
logging_config = tomllib.loads(logger_data)
172166
logging.config.dictConfig(logging_config)
173167

src/project_name/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main() -> None:
1111
"""Lorem Ipsum."""
1212
setup_logging()
1313

14-
logger.debug("debug message", extra={'foo': 'hello'})
14+
logger.debug("debug message", extra={"foo": "hello"})
1515
logger.info("info message")
1616
logger.warning("warning message")
1717
logger.error("error message")
@@ -23,5 +23,5 @@ def main() -> None:
2323
logger.exception("exception message")
2424

2525

26-
if __name__ == '__main__':
26+
if __name__ == "__main__":
2727
main()

0 commit comments

Comments
 (0)