def resolve_path(path, ds=None): """Resolve a path specification (against a Dataset location) Any explicit path (absolute or relative) is returned as an absolute path. In case of an explicit relative path, the current working directory is used as a reference. Any non-explicit relative path is resolved against as dataset location, i.e. considered relative to the location of the dataset. If no dataset is provided, the current working directory is used. Returns ------- Absolute path """ # first make sure it's actually a valid path: from datalad.support.network import PathRI if not isinstance(RI(path), PathRI): raise ValueError("%s is not a valid path" % path) path = expandpath(path, force_absolute=False) if is_explicit_path(path): # normalize path consistently between two (explicit and implicit) cases return dlabspath(path, norm=True) # no dataset given, use CWD as reference # note: abspath would disregard symlink in CWD top_path = getpwd() \ if ds is None else ds.path if isinstance(ds, Dataset) else ds return normpath(opj(top_path, path))
def resolve_path(path, ds=None): """Resolve a path specification (against a Dataset location) Any explicit path (absolute or relative) is returned as an absolute path. In case of an explicit relative path, the current working directory is used as a reference. Any non-explicit relative path is resolved against as dataset location, i.e. considered relative to the location of the dataset. If no dataset is provided, the current working directory is used. Returns ------- Absolute path """ # first make sure it's actually a valid path: from datalad.support.network import PathRI if not isinstance(RI(path), PathRI): raise ValueError("%s is not a valid path" % path) path = expandpath(path, force_absolute=False) if is_explicit_path(path): # normalize path consistently between two (explicit and implicit) cases return dlabspath(path, norm=True) # no dataset given, use CWD as reference # note: abspath would disregard symlink in CWD top_path = getpwd() \ if ds is None else ds.path if isinstance(ds, Dataset) else ds return normpath(opj(top_path, path))
def test_dlabspath(path): if not has_symlink_capability(): raise SkipTest # initially ran into on OSX https://github.com/datalad/datalad/issues/2406 opath = opj(path, "origin") os.makedirs(opath) lpath = opj(path, "linked") os.symlink('origin', lpath) for d in opath, lpath: # regardless under which directory, all results should not resolve # anything eq_(d, dlabspath(d)) # in the root of ds with chpwd(d): eq_(dlabspath("bu"), opj(d, "bu")) eq_(dlabspath("./bu"), opj(d, "./bu")) # we do not normpath by default eq_(dlabspath("./bu", norm=True), opj(d, "bu"))
def _resolve_path(path, ds=None): """Resolve a path specification (against a Dataset location) Any explicit path (absolute or relative) is returned as an absolute path. In case of an explicit relative path, the current working directory is used as a reference. Any non-explicit relative path is resolved against as dataset location, i.e. considered relative to the location of the dataset. If no dataset is provided, the current working directory is used. Returns ------- Absolute path """ path = expandpath(path, force_absolute=False) if is_explicit_path(path): # normalize path consistently between two (explicit and implicit) cases return dlabspath(path, norm=True) # no dataset given, use CWD as reference # note: abspath would disregard symlink in CWD top_path = getpwd() \ if ds is None else ds.path if isinstance(ds, Dataset) else ds return normpath(opj(top_path, path))