[docs]classLSFiles(_MutableSequence[_Path]):"""Index all Python files in project."""
[docs]defpopulate(self,exclude:str|None=None)->None:"""Populate object with index of versioned Python files. :param exclude: List of paths to exclude. """repo=_git.Repo(_Path.cwd())forpathinrepo.git.ls_files().splitlines():ifpath.endswith(".py")and(notexcludeor_re.match(exclude,path)isNone):self.append(_Path.cwd()/path)
[docs]defreduce(self)->list[_Path]:"""Get all relevant python files starting from project root. :return: List of project's Python file index, reduced to their root, relative to $PROJECT_DIR. Contains no duplicate items so $PROJECT_DIR/dir/file1.py and $PROJECT_DIR/dir/file2.py become $PROJECT_DIR/dir but PROJECT_DIR/file1.py and $PROJECT_DIR/file2.py remain as they are. """project_dir=_Path.cwd()returnlist({project_dir/p.relative_to(project_dir).parts[0]forpinself})
[docs]defargs(self,reduce:bool=False)->tuple[str,...]:"""Return tuple suitable to be run with starred expression. :param reduce: :func:`~lsfiles.utils._Tree.reduce` :return: Tuple of `Path` objects or str repr. """paths=list(self)ifreduce:paths=self.reduce()returntuple(str(p)forpinpaths)