From 1987693f34fb05afb9fd46b436a16abb95e3a165 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 24 Dec 2017 22:40:08 -0800 Subject: [PATCH] Refactoring: extract method stage_file_basename() --- dvc/command/run.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dvc/command/run.py b/dvc/command/run.py index 325122362..2bb7246fd 100644 --- a/dvc/command/run.py +++ b/dvc/command/run.py @@ -7,7 +7,7 @@ from dvc.stage import Stage class CmdRun(CmdBase): def run(self): - fname = self.get_stage_file(self.args.file, self.args.outs, self.args.outs_no_cache) + fname = self.stage_file_name(self.args.file, self.args.outs, self.args.outs_no_cache) self.project.run(cmd=' '.join(self.args.command), outs=self.args.outs, @@ -20,16 +20,22 @@ class CmdRun(CmdBase): return 0 @staticmethod - def get_stage_file(args_file, args_out, args_outs_no_cache): + def stage_file_name(args_file, args_outs, args_outs_no_cache): if args_file: return args_file - if args_out or args_outs_no_cache: - result = args_out[0] if args_out else args_outs_no_cache[0] - result = os.path.basename(result) - result += Stage.STAGE_FILE_SUFFIX + if args_outs: + result = CmdRun._stage_file_basename(args_outs) + elif args_outs_no_cache: + result = CmdRun._stage_file_basename(args_outs_no_cache) else: result = Stage.STAGE_FILE Logger.info(u'Using \'{}\' as a stage file'.format(result)) return result + + @staticmethod + def _stage_file_basename(fname): + result = os.path.basename(fname) + result += Stage.STAGE_FILE_SUFFIX + return result