Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_target_metric(file_name):
lines = open(file_name).readlines(2)
if len(lines) != 1:
raise StateFileError('file contains more then one line')
# Extract float from string. I.e. from 'AUC: 0.596182'
nums = StateFile.FLOATS_FROM_STRING.findall(lines[0])
if len(nums) < 1:
raise StateFileError("Unable to parse metrics from the first line")
return float(nums[0])
def create_state_files(self, targets, lock):
"""
Create state files for all targets.
"""
for t in targets:
orig_target, processed_data_item = t
input, data_item = orig_target
output = data_item.data.relative
if processed_data_item == None:
Logger.debug('Skipping creating state file for failed import {}'.format(data_item.state.relative))
continue
Logger.debug('Creating state file for {}'.format(data_item.data.relative))
state_file = StateFile(StateFile.COMMAND_IMPORT_FILE,
data_item,
self.settings,
argv=[input, output],
input_items=[],
output_files=[output],
lock=lock)
state_file.save()
Logger.debug('State file "{}" was created'.format(data_item.state.relative))
def decode_paths(l):
return StateFile._replace_paths(l, '/', '\\')
def checkout_targets(self, targets):
data = []
for item in targets:
prev_state = StateFile.loads(self.git.get_file_content_before_last_merge(item.state.relative))
curr_state = StateFile.load(item)
state = StateFile(data_item=item,
cmd=curr_state.cmd,
out=curr_state.out,
out_git=curr_state.out_git,
locked=curr_state.locked,
deps=curr_state.deps,
md5=prev_state.md5)
state.save()
CmdCheckout.checkout([item])
msg = 'DVC merge files: {}'.format(' '.join(data))
self.commit_if_needed(msg)
def load_json(json, settings):
return StateFile(StateFile.decode_path(json.get(StateFile.PARAM_COMMAND)),
None,
settings,
StateFile.decode_paths(json.get(StateFile.PARAM_INPUT_FILES, [])),
StateFile.decode_paths(json.get(StateFile.PARAM_OUTPUT_FILES, [])),
StateFile.decode_paths(json.get(StateFile.PARAM_CODE_DEPENDENCIES, [])),
json.get(StateFile.PARAM_LOCKED, False),
StateFile.decode_paths(json.get(StateFile.PARAM_ARGV)),
StateFile.decode_path(json.get(StateFile.PARAM_STDOUT)),
StateFile.decode_path(json.get(StateFile.PARAM_STDERR)),
json.get(StateFile.PARAM_CREATED_AT),
StateFile.decode_path(json.get(StateFile.PARAM_CWD)),
json.get(StateFile.PARAM_SHELL, False),
json.get(StateFile.PARAM_TARGET_METRICS, {}),
json.get(StateFile.PARAM_TARGET_COMMIT, None))
def loadd(data, fname=None):
return StateFile(fname=fname,
cmd=data.get(StateFile.PARAM_CMD, None),
out=data.get(StateFile.PARAM_OUT, None),
out_git=data.get(StateFile.PARAM_OUT_GIT, None),
deps=data.get(StateFile.PARAM_DEPS, []),
locked=data.get(StateFile.PARAM_LOCKED, None))
def find(data_item):
return StateFile._find(data_item.data.abs, data_item.data.dirname, data_item._git.git_dir_abs)
def collect_targets(self):
targets = []
flist = self.collect_data()
items = self.settings.path_factory.to_data_items(flist)[0]
for item in items:
command = StateFile.load(item)
if not command.cmd and command.locked:
targets.append(item)
return targets
def loadd(data, fname=None):
return StateFile(fname=fname,
cmd=data.get(StateFile.PARAM_CMD, None),
out=data.get(StateFile.PARAM_OUT, None),
out_git=data.get(StateFile.PARAM_OUT_GIT, None),
deps=data.get(StateFile.PARAM_DEPS, []),
locked=data.get(StateFile.PARAM_LOCKED, None))