def _format_csv(content, delimiter): """Format delimited text to have same column width. Args: content (str): The content of a metric. delimiter (str): Value separator Returns: str: Formatted content. Example: >>> content = ( "value_mse,deviation_mse,data_set\n" "0.421601,0.173461,train\n" "0.67528,0.289545,testing\n" "0.671502,0.297848,validation\n" ) >>> _format_csv(content, ",") "value_mse deviation_mse data_set\n" "0.421601 0.173461 train\n" "0.67528 0.289545 testing\n" "0.671502 0.297848 validation\n" """ reader = csv_reader(StringIO(content), delimiter=builtin_str(delimiter)) rows = [row for row in reader] max_widths = [max(map(len, column)) for column in zip(*rows)] lines = [ " ".join("{entry:{width}}".format(entry=entry, width=width + 2) for entry, width in zip(row, max_widths)) for row in rows ] return "\n".join(lines)
def _make_remote_property(name): """ The config file is stored in a way that allows you to have a cache for each remote. This is needed when specifying external outputs (as they require you to have an external cache location). Imagine a config file like the following: ['remote "dvc-storage"'] url = ssh://localhost/tmp ask_password = true [cache] ssh = dvc-storage This method creates a cached property, containing cache named `name`: self.config == {'ssh': 'dvc-storage'} self.ssh # a RemoteSSH instance """ def getter(self): from dvc.remote import Remote remote = self.config.get(name) if not remote: return None return Remote(self.repo, name=remote) getter.__name__ = builtin_str(name) return cached_property(getter)
def _read_metric_xsv(fd, xsv_path, delimiter): indices = xsv_path.split(",") row = indices[0] row = int(row) if row else None col = int(indices[1]) if len(indices) > 1 and indices[1] else None reader = list(csv.reader(fd, delimiter=builtin_str(delimiter))) return _do_read_metric_xsv(reader, row, col)
def _read_metric_hxsv(cls, fd, hxsv_path, delimiter): import csv col, row = hxsv_path.split(",") row = int(row) reader = list(csv.DictReader(fd, delimiter=builtin_str(delimiter))) return cls._do_read_metric_xsv(reader, row, col)
def _read_metric_xsv(self, fd, xsv_path, delimiter): import csv col, row = xsv_path.split(",") row = int(row) col = int(col) reader = list(csv.reader(fd, delimiter=builtin_str(delimiter))) return self._do_read_metric_xsv(reader, row, col)
def fill_parts(self, scheme, host, user, port, path): assert scheme != "remote" assert isinstance(path, (basestring, _URLPathInfo)) self.scheme, self.host, self.user = scheme, host, user self.port = int(port) if port else self.DEFAULT_PORTS.get(self.scheme) if isinstance(path, _URLPathInfo): self._spath = builtin_str(path) self._path = path else: if path and path[0] != "/": path = "/" + path self._spath = path
def __repr__(self): return builtin_str("{}: '{}'").format(type(self).__name__, self)