mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
Target logic for repro command
This commit is contained in:
+12
-1
@@ -53,7 +53,18 @@ class CmdRepro(CmdRun):
|
||||
def run(self):
|
||||
with DvcLock(self.is_locker, self.git):
|
||||
recursive = not self.parsed_args.single_item
|
||||
return self.repro_target(self.parsed_args.target, recursive, self.parsed_args.force)
|
||||
if self.parsed_args.target:
|
||||
target = self.parsed_args.target
|
||||
else:
|
||||
target_conf_file_path = self.settings.path_factory.path(self.settings.config.target_file)
|
||||
target_file = open(target_conf_file_path.relative).read()
|
||||
if not target_file:
|
||||
Logger.error('Reproduction target is not defined. ' +
|
||||
'Specify data file or set target by `dvc target` command.')
|
||||
return 1
|
||||
target = [target_file]
|
||||
|
||||
return self.repro_target(target, recursive, self.parsed_args.force)
|
||||
pass
|
||||
|
||||
def repro_target(self, target, recursive, force):
|
||||
|
||||
+23
-12
@@ -3,7 +3,6 @@ import os
|
||||
from dvc.command.base import CmdBase, DvcLock
|
||||
from dvc.logger import Logger
|
||||
from dvc.runtime import Runtime
|
||||
from dvc.state_file import StateFile
|
||||
|
||||
|
||||
class CmdTarget(CmdBase):
|
||||
@@ -16,16 +15,16 @@ class CmdTarget(CmdBase):
|
||||
parser.add_argument('-u', '--unset', action='store_true', default=False,
|
||||
help='Reset target.')
|
||||
|
||||
parser.add_argument('target', metavar='', help='Target data item.')
|
||||
parser.add_argument('target', metavar='', nargs='?', help='Target data item.')
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
with DvcLock(self.is_locker, self.git):
|
||||
return self.change_target(self.parsed_args.target, not self.parsed_args.unset)
|
||||
return self.change_target(self.parsed_args.target, self.parsed_args.unset)
|
||||
|
||||
def change_target(self, target, unset):
|
||||
if target and unset:
|
||||
Logger.error('Unable to set target {} and unset it in a single command'.format(target))
|
||||
Logger.error('Unable to set target {} and use --unset in a single command'.format(target, unset))
|
||||
return 1
|
||||
|
||||
if not target and not unset:
|
||||
@@ -35,19 +34,31 @@ class CmdTarget(CmdBase):
|
||||
target_conf_file_path = self.settings.path_factory.path(self.settings.config.target_file)
|
||||
|
||||
if unset:
|
||||
if os.path.exists(target_conf_file_path.relative):
|
||||
if not os.path.isfile(target_conf_file_path.relative):
|
||||
Logger.error('Target conf file {} exists but it is not a regular file'.format(
|
||||
target_conf_file_path.relative))
|
||||
return 1
|
||||
os.remove(target_conf_file_path.relative)
|
||||
if not os.path.exists(target_conf_file_path.relative):
|
||||
Logger.error('Target conf file {} does not exists'.format(
|
||||
target_conf_file_path.relative))
|
||||
return 1
|
||||
|
||||
if not os.path.isfile(target_conf_file_path.relative):
|
||||
Logger.error('Target conf file {} exists but it is not a regular file'.format(
|
||||
target_conf_file_path.relative))
|
||||
return 1
|
||||
|
||||
if open(target_conf_file_path.relative).read() == '':
|
||||
return 0
|
||||
|
||||
os.remove(target_conf_file_path.relative)
|
||||
open(target_conf_file_path.relative, 'a').close()
|
||||
else:
|
||||
with open(target_conf_file_path.relative, 'w') as fd:
|
||||
target_data_item = self.settings.path_factory.existing_data_item(target)
|
||||
fd.write(target_data_item.data_dvc_short)
|
||||
fd.write(target_data_item.data.dvc)
|
||||
|
||||
return 0
|
||||
if target:
|
||||
msg = 'DVC target: {}'.format(target)
|
||||
else:
|
||||
msg = 'DVC target unset'
|
||||
return self.commit_if_needed(msg)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ def print_usage():
|
||||
def main():
|
||||
cmds = ['--help', '--version', 'init', 'run', 'sync', 'repro', 'data', 'remove', 'import', 'lock', 'cloud', \
|
||||
'cloud', 'cloud-run', 'cloud-instance-create', 'cloud-instance-remove', 'cloud-instance-describe', \
|
||||
'test', 'test-aws', 'test-gcloud', 'test-cloud', 'gc']
|
||||
'test', 'test-aws', 'test-gcloud', 'test-cloud', 'gc', 'target']
|
||||
|
||||
if len(sys.argv) < 2 or sys.argv[1] not in cmds:
|
||||
if len(sys.argv) >= 2:
|
||||
|
||||
Reference in New Issue
Block a user