Skip to content

Commit

Permalink
Use output filename as a defult stage file name. Close iterative#351
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpetrov committed Dec 14, 2017
1 parent 99ecc9e commit 282b7c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def parse_args(argv=None):
help='Lock data item - disable reproduction.')
run_parser.add_argument('-f',
'--file',
default=StateFile.DVCFILE_NAME,
help='Specify name of the state file')
run_parser.add_argument('-c',
'--cwd',
Expand Down
24 changes: 19 additions & 5 deletions dvc/command/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from dvc.command.common.base import CmdBase
from dvc.data_cloud import file_md5
from dvc.exceptions import DvcException
from dvc.logger import Logger
from dvc.state_file import StateFile
Expand All @@ -20,20 +19,35 @@ def __init__(self, settings):
def run(self):
cmd = ' '.join(self.parsed_args.command)

if os.path.isfile(self.parsed_args.file):
Logger.error("Stage file {} already exists".format(self.parsed_args.file))
stage_file = self.get_stage_file()
if os.path.isfile(stage_file):
Logger.error("Stage file {} already exists".format(stage_file))
return 1

state = StateFile(fname=os.path.join(self.parsed_args.cwd, self.parsed_args.file),
state = StateFile(fname=os.path.join(self.parsed_args.cwd, stage_file),
cmd=cmd,
out=self.parsed_args.out,
out_git=self.parsed_args.out_git,
deps=self.parsed_args.deps,
locked=self.parsed_args.lock)
locked=self.parsed_args.lock,
cwd=self.parsed_args.cwd)

self.run_command(self.settings, state)
return self.commit_if_needed('DVC run: {}'.format(state.cmd))

def get_stage_file(self):
if self.parsed_args.file:
return self.parsed_args.file

if self.parsed_args.out or self.parsed_args.out_git:
result = self.parsed_args.out[0] if self.parsed_args.out else self.parsed_args.out_git[0]
result += StateFile.STATE_FILE_SUFFIX
Logger.info(u'Using \'{}\' as a stage file'.format(result))
return result

Logger.info(u'Using \'{}\' as stage file'.format(StateFile.DVCFILE_NAME))
return StateFile.DVCFILE_NAME

@staticmethod
def run_command(settings, state):
Executor.exec_cmd_only_success(state.cmd, cwd=state.cwd, shell=True)
Expand Down
5 changes: 3 additions & 2 deletions dvc/state_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self,
out=None,
out_git=None,
deps=None,
locked=None):
locked=None,
cwd=None):
super(StateFile, self).__init__()

self.cmd = cmd
Expand All @@ -50,7 +51,7 @@ def __init__(self,
self.locked = locked

self.path = os.path.abspath(fname) if fname else None
self.cwd = os.path.dirname(self.path) if self.path else None
self.cwd = cwd

@staticmethod
def parse_deps_state(settings, deps, currdir=None):
Expand Down

0 comments on commit 282b7c6

Please sign in to comment.