General console printout updates (#48)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
8530e3fae0
commit
27d6545117
12 changed files with 81 additions and 105 deletions
|
|
@ -1,9 +1,10 @@
|
|||
import glob
|
||||
import inspect
|
||||
import platform
|
||||
import sys
|
||||
import urllib
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
from typing import Optional
|
||||
|
||||
import pkg_resources as pkg
|
||||
import torch
|
||||
|
|
@ -128,3 +129,27 @@ def check_file(file, suffix=''):
|
|||
def check_yaml(file, suffix=('.yaml', '.yml')):
|
||||
# Search/download YAML file (if necessary) and return path, checking suffix
|
||||
return check_file(file, suffix)
|
||||
|
||||
|
||||
def git_describe(path=ROOT): # path must be a directory
|
||||
# Return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
|
||||
try:
|
||||
assert (Path(path) / '.git').is_dir()
|
||||
return check_output(f'git -C {path} describe --tags --long --always', shell=True).decode()[:-1]
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
|
||||
def print_args(args: Optional[dict] = None, show_file=True, show_func=False):
|
||||
# Print function arguments (optional args dict)
|
||||
x = inspect.currentframe().f_back # previous frame
|
||||
file, _, func, _, _ = inspect.getframeinfo(x)
|
||||
if args is None: # get args automatically
|
||||
args, _, _, frm = inspect.getargvalues(x)
|
||||
args = {k: v for k, v in frm.items() if k in args}
|
||||
try:
|
||||
file = Path(file).resolve().relative_to(ROOT).with_suffix('')
|
||||
except ValueError:
|
||||
file = Path(file).stem
|
||||
s = (f'{file}: ' if show_file else '') + (f'{func}: ' if show_func else '')
|
||||
LOGGER.info(colorstr(s) + ', '.join(f'{k}={v}' for k, v in args.items()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue