Skip to content

Commit bb7d386

Browse files
committed
Set phase earlier; minor other fixes
1 parent 4c3b048 commit bb7d386

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

metaflow/cli.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ def start(
475475
# be raised. For resume, since we ignore those options, we ignore the error.
476476
raise ctx.obj.delayed_config_exception
477477

478+
# Initialize the phase early so it can be used in the mutators
479+
# The phase is determined by which CLI subcommand is being invoked (e.g. "run" → LAUNCH,
480+
# "step" → TASK, "batch" → TRAMPOLINE).
481+
system_context._update(phase=_phase_from_cli_args(getattr(ctx, "saved_args", None)))
482+
478483
# Init all values in the flow mutators and then process them
479484
for decorator in ctx.obj.flow._flow_mutators:
480485
decorator.external_init()
@@ -564,13 +569,7 @@ def start(
564569

565570
decorators._init(ctx.obj.flow)
566571

567-
# Populate the system context singleton for this process. The phase is
568-
# determined by which CLI subcommand is being invoked (e.g. "run" → LAUNCH,
569-
# "step" → TASK, "batch" → TRAMPOLINE).
570-
saved_args = getattr(ctx, "saved_args", None)
571-
phase = _phase_from_cli_args(saved_args)
572572
system_context._update(
573-
phase=phase,
574573
flow=ctx.obj.flow,
575574
graph=ctx.obj.graph,
576575
environment=ctx.obj.environment,

metaflow/debug.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)