-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Cleanup python imports (#2226)
- Loading branch information
Showing
18 changed files
with
243 additions
and
263 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import inspect | ||
import os | ||
|
||
from taichi.core import util | ||
|
||
|
||
def get_logging(name): | ||
def logger(msg, *args, **kwargs): | ||
# Python inspection takes time (~0.1ms) so avoid it as much as possible | ||
if util.ti_core.logging_effective(name): | ||
msg_formatted = msg.format(*args, **kwargs) | ||
func = getattr(util.ti_core, name) | ||
frame = inspect.currentframe().f_back | ||
file_name, lineno, func_name, _, _ = inspect.getframeinfo(frame) | ||
file_name = os.path.basename(file_name) | ||
msg = f'[{file_name}:{func_name}@{lineno}] {msg_formatted}' | ||
func(msg) | ||
|
||
return logger | ||
|
||
|
||
def set_logging_level(level): | ||
util.ti_core.set_logging_level(level) | ||
|
||
|
||
DEBUG = 'debug' | ||
TRACE = 'trace' | ||
INFO = 'info' | ||
WARN = 'warn' | ||
ERROR = 'error' | ||
CRITICAL = 'critical' | ||
|
||
debug = get_logging(DEBUG) | ||
trace = get_logging(TRACE) | ||
info = get_logging(INFO) | ||
warn = get_logging(WARN) | ||
error = get_logging(ERROR) | ||
critical = get_logging(CRITICAL) | ||
|
||
|
||
def _get_file_name(asc=0): | ||
return inspect.stack()[1 + asc][1] | ||
|
||
|
||
def _get_function_name(asc=0): | ||
return inspect.stack()[1 + asc][3] | ||
|
||
|
||
def _get_line_number(asc=0): | ||
return inspect.stack()[1 + asc][2] |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.