Example #1
0
def _add_folder_tree_to_new_base_dir(from_path: PosixPath, to_path: str) -> (PosixPath, str):
    """Construct Google storage folder tree based on local folder tree so that the hierarchy is maintained.

    :param from_path: Path to a local folder.
    :param to_path: Path to the target Google storage folder.
    :return: Iterate and yield tuples of (local file, corresponding Google storage file Path)
    """
    folder_tree = from_path.rglob("*")
    for f in folder_tree:
        relative_path = f.relative_to(from_path)
        yield f, to_path + "/" + str(relative_path)
Example #2
0
 def _extract_resulting_binary(self, build_dir: pathlib.PosixPath,
                               extension: str) -> pathlib.PosixPath:
     """Extracts exactly 1 binary from a dir and returns a Path."""
     assert build_dir.is_dir(), f"build_dir {build_dir} was not a dir!"
     # N.B. It's important we use pathlib.Path.rglob (recursive) here, since pants v2 prefixes
     # dist dirs with their address namespace.
     binaries = list(build_dir.rglob(f"*.{extension}"))
     if len(binaries) != 1:
         raise self.BuildFailure(
             "failed to select deterministic build artifact from workdir, needed 1 binary file "
             f"with extension {extension} but found {len(binaries)}. Is the BUILD target a "
             "binary (pex) output type?")
     return binaries[0]
Example #3
0
def read_npy_files(data_dir: PosixPath) -> List[PosixPath]:
    all_npy_files = [x for x in data_dir.rglob('*.npy')]

    return all_npy_files
Example #4
0
def tree(directory: PosixPath) -> None:
    print(f"+ {directory}")
    for path in sorted(directory.rglob("*")):
        depth = len(path.relative_to(directory).parts)
        spacer = "    " * depth
        print(f"{spacer}+ {path.name}")