def copy_fs(version_view: FS, deliverable: FS) -> None: # TODO The note below is probably obsolete. It was written when # we were using the DeliverableFS to make the deliverable. We've # now switched to using the DeliverableView. (The obsolete # DeliverableFS has been deleted from the repo.) In any case, # this doesn't seem to hurt anything, but it can probably all be # replaced by fs.copy.copy_file()--see the last line. Try it and # see. # TODO I could (and used to) just do a fs.copy.copy_fs() from the # version_view to a DeliverableFS. I removed it to debug issues # with the validation tool. Now I find this hack is just as easy # (though I wonder about efficiency). It bothers me that this # visits hack parallels a visits hack in # plain_lidvid_to_visits_dirpath(). I should figure this out and # make it clean. For now, though, this works. # Uses dollar-terminated paths for path, dirs, files in version_view.walk(): parts = fs.path.parts(path) if len(parts) == 4: if len(parts[3]) == 10: visit = "visit_" + parts[3][4:6].lower() + "$" parts[3] = visit new_path = fs.path.join(*parts) if not deliverable.isdir(new_path): deliverable.makedir(new_path) for file in files: old_filepath = fs.path.join(path, file.name) new_filepath = fs.path.join(new_path, file.name) fs.copy.copy_file(version_view, old_filepath, deliverable, new_filepath)
def create_cowfs(base_fs: FS, read_write_layer: FS, recreate: bool = False) -> "COWFS": additions_fs = read_write_layer.makedir("/additions", recreate=recreate) deletions_fs = read_write_layer.makedir("/deletions", recreate=recreate) return COWFS(base_fs, additions_fs, deletions_fs)
def write_dictionary_to_fs(fs: FS, dir_path: str, d: Dict[Any, Any]) -> None: for k, v in d.items(): assert type(k) in [str, str] type_v = type(v) sub_path = join(dir_path, str(k)) if type_v == dict: fs.makedir(sub_path) write_dictionary_to_fs(fs, sub_path, v) elif type_v in [str, str]: fs.writetext(sub_path, str(v)) else: assert False, f"unexpected type {type_v} at {sub_path}"
def run( self, trial: Trial, judge: TrialJudge, checkpoint_basedir_fs: FSBase, ) -> None: checkpoint = Checkpoint( checkpoint_basedir_fs.makedir(trial.trial_id, recreate=True)) if not judge.can_accept(trial): return self._current_trial = trial self.initialize() try: if len(checkpoint) > 0: self._rung = int(checkpoint.latest.readtext("__RUNG__")) + 1 self.load_checkpoint(checkpoint.latest) budget = judge.get_budget(trial, self.rung) while budget > 0: report = self.run_single_rung(budget) report = report.with_rung(self.rung).with_sort_metric( self.generate_sort_metric(report.metric)) decision = judge.judge(report) if decision.should_checkpoint: with checkpoint.create() as fs: fs.writetext("__RUNG__", str(self.rung)) self.save_checkpoint(fs) budget = decision.budget self._rung += 1 finally: self.finalize()
def __init__(self, root_fs: FS, config: Config): super(RealSideEffects, self).__init__(root_fs) self.fragments_fs = root_fs.makedir(config.change_fragments_path, recreate=True)