@@ -22,16 +22,33 @@ class Debug(object):
2222 def __init__ (self ):
2323 import metaflow .metaflow_config as config
2424
25+ have_debug_options = False
2526 for typ in config .DEBUG_OPTIONS :
2627 if getattr (config , "DEBUG_%s" % typ .upper ()):
2728 op = partial (self .log , typ )
29+ have_debug_options = True
2830 else :
2931 op = self .noop
3032 # use debug.$type_exec(args) to log command line for subprocesses
3133 # of type $type
3234 setattr (self , "%s_exec" % typ , op )
3335 # use the debug.$type flag to check if logging is enabled for $type
3436 setattr (self , typ , op != self .noop )
37+ # In some environments (I'm looking at you Bazel), the path to the filename is
38+ # super long and not very useful. We will print it once and truncate the rest.
39+ # This is not 100% accurate as each package is in a separate directory so the
40+ # prefix length may be a bit different but it's good enough and removes a lot
41+ # of noise while also keeping the cost low (instead of having to figure out
42+ # the prefix for each package)
43+ self .prefix_len = 0
44+ if have_debug_options :
45+ # Figure out the name of the current file and strip out everything before
46+ #
47+ self .prefix_len = len (inspect .stack ()[0 ][1 ][: - len ("metaflow/debug.py" )])
48+ self .log (
49+ "options" ,
50+ "File prefix is: %s" % inspect .stack ()[0 ][1 ][: self .prefix_len ],
51+ )
3552
3653 def log (self , typ , args ):
3754 if is_stringish (args ):
@@ -40,7 +57,10 @@ def log(self, typ, args):
4057 s = " " .join (args )
4158 lineno = inspect .currentframe ().f_back .f_lineno
4259 filename = inspect .stack ()[1 ][1 ]
43- print ("debug[%s %s:%s]: %s" % (typ , filename , lineno , s ), file = sys .stderr )
60+ print (
61+ "debug[%s %s:%s]: %s" % (typ , filename [self .prefix_len :], lineno , s ),
62+ file = sys .stderr ,
63+ )
4464
4565 def __getattr__ (self , name ):
4666 # Small piece of code to get pyright and other linters to recognize that there
0 commit comments