README¶
This repository has been archived and is no longer maintained
lsfiles¶
Path object VC index¶
Index versioned .py files
Install¶
pip install lsfiles
Development¶
poetry install
Usage¶
The LSFiles
instance is a list-like object instantiated with an empty index
>>> from lsfiles import LSFiles
>>> from pathlib import Path
>>>
>>> files = LSFiles()
>>> files
<LSFiles []>
The LSFiles
index calls git ls-files
and only versioned files are indexed
>>> files.populate()
>>> for path in sorted([p.relative_to(Path.cwd()) for p in files]):
... print(path)
docs/conf.py
lsfiles/__init__.py
lsfiles/_indexing.py
lsfiles/_objects.py
lsfiles/_version.py
tests/__init__.py
tests/_environ.py
tests/_test.py
tests/conftest.py
whitelist.py
The LSFiles
instance is an index of unique file paths
It’s implementation of extend
prevents duplicates
>>> p1 = Path.cwd() / "f1"
>>> p2 = Path.cwd() / "f1"
>>>
>>> files = LSFiles()
>>> files.extend([p1, p2])
>>> sorted([p.relative_to(Path.cwd()) for p in files.reduce()])
[PosixPath('f1')]
Reduce minimizes index to directories and individual files relative to the current working dir
The list value is returned, leaving the instance unaltered
>>> p1 = Path.cwd() / "f1"
>>>
>>> d = Path.cwd() / "dir"
>>> p2 = d / "f2"
>>> p3 = d / "f3"
>>>
>>> files = LSFiles()
>>> files.extend([p1, p2, p3])
>>> sorted(p.relative_to(Path.cwd()) for p in files.reduce())
[PosixPath('dir'), PosixPath('f1')]
Exclusions can be added on instantiation
Exclusions are evaluated by their basename, and does not have to be an absolute path
>>> p1 = Path.cwd() / "docs" / "conf.py"
>>> p2 = Path.cwd() / "lsfiles" / "__init__.py"
>>>
>>> files = LSFiles()
>>> files.populate(f".*\/{p1.name}")
>>>
>>> ps = [str(p) for p in files]
>>>
>>> assert not str(p1) in ps
>>> assert str(p2) in ps