def _abspath(self, first_is_basedir: bool = False) -> str: """ Return the absolute path of the current crumb path. Parameters ---------- first_is_basedir: bool If True and the current crumb path starts with a crumb argument and first_is_basedir, the first argument will be replaced by the absolute path to the current dir, otherwise the absolute path to the current dir will be added as a prefix. Returns ------- abspath: str """ if os.path.isabs(self._path): return self._path splits = self._path.split(os.path.sep) basedir = [os.path.abspath(os.path.curdir)] if _is_crumb_arg(splits[0]): if first_is_basedir: splits.pop(0) basedir.extend(splits) return os.path.sep.join(basedir)
def test_split(crumb): splt = crumb.split() for s in splt: if os.path.isdir(s): assert os.path.exists(s) else: assert _is_crumb_arg(s) or isinstance(s, str)
def test_split(crumb): splt = crumb.split() for s in splt: if op.isdir(s): assert op.exists(s) else: assert _is_crumb_arg(s) or isinstance(s, string_types)
def test_arg_name(): assert not _is_crumb_arg(Path(os.path.expanduser('~')))
def test_arg_name(): assert not _is_crumb_arg(Path(op.expanduser('~')))
def is_crumb_arg(crumb_arg): """ Return True if `crumb_arg` is a well formed crumb argument, i.e., is a string that starts with `start_sym` and ends with `end_sym`. False otherwise. """ return _is_crumb_arg(crumb_arg)