示例#1
0
def shell(r: Union[Build, RRef, DRef, Path, str, None] = None) -> None:
    """ Open the Unix Shell in the directory associated with the argument passed.
  Path to the shell executable is read from the `SHELL` environment variable,
  defaulting to `/bin/sh`. If `r` is None, open the shell in the root of the
  Pylightnix storage.

  The function is expected to be run in REPL Python shells like IPython.
  """
    cwd: str
    if r is None:
        import pylightnix.core
        cwd = pylightnix.core.PYLIGHTNIX_STORE
    elif isrref(r):
        cwd = store_rref2path(RRef(r))
    elif isdref(r):
        cwd = store_dref2path(DRef(r))
    elif isinstance(r, Build):
        assert len(r.outgroups) > 0, (
            "Shell function requires at least one build output path to be defined"
        )
        cwd = r.outgroups[0][Tag('out')]
    elif isdir(r):
        cwd = str(r)
    elif isfile(r):
        cwd = dirname(str(r))
    else:
        assert False, (
            f"Expecting `RRef`, `DRef`, a directory or file path (either a string or "
            f"a `Path`), or None. Got {r}")
    Popen([environ.get('SHELL', '/bin/sh')], shell=False, cwd=cwd).wait()
示例#2
0
def catref(r: RRef, fn: List[str]) -> List[str]:
    """ Return the contents of r's artifact line by line. `fn` is a list of
  folders, relative to rref's root. """
    if isrref(r) and isinstance(r, RRef):
        return list(catrref_(r, fn))
    else:
        assert False, 'not implemented'
示例#3
0
 def _cfgpathof(s) -> Path:
     if isrref(s):
         return store_cfgpath(rref2dref(RRef(s)))
     elif isdref(s):
         return store_cfgpath(DRef(s))
     else:
         return store_cfgpath(instantiate(s).dref)
示例#4
0
def lsref(r: Union[RRef, DRef]) -> List[str]:
    """ List the contents of `r`. For [DRefs](#pylightnix.types.DRef), return
  realization hashes. For [RRefs](#pylightnix.types.RRef), list artifact files.
  """
    if isrref(r):
        return list(lsrref(RRef(r)))
    elif isdref(r):
        return list(lsdref_(DRef(r)))
    else:
        assert False, f"Invalid reference {r}"
示例#5
0
def rmref(r: Union[RRef, DRef]) -> None:
    """ Forcebly remove a reference from the storage. Removing
  [DRefs](#pylightnix.types.DRef) also removes all their realizations.

  Currently Pylightnix makes no attempts to synchronize an access to the
  storage. In scenarious involving parallelization, users are expected to take
  care of possible race conditions.
  """
    if isrref(r):
        dirrm(store_rref2path(RRef(r)))
    elif isdref(r):
        dirrm(store_dref2path(DRef(r)))
    else:
        assert False, f"Invalid reference {r}"