Skip to main content

lsfiles

License PyPI Build CodeQL pre-commit.ci status codecov.io readthedocs.org python3.8 Black isort docformatter pylint Security Status Known Vulnerabilities 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

Metadata

Release files for lsfiles 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lsfiles 0.5.1
File Size Uploaded
lsfiles-0.5.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lsfiles 0.5.1
File Interpreter ABI Platform
lsfiles-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / lsfiles-0.5.1.tar.gz

Download URL lsfiles-0.5.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
860bb1fc8b9f029c42066eb6aabc68236249dfcfe22f7968c3cc88335387f893
BLAKE2b-256 checksum
How to use checksums
55320121510fceac32087d1ff4ccc1a9857f2108dcaf0fd5185498e8fc84c414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0

Release files / lsfiles-0.5.1-py3-none-any.whl

Download URL lsfiles-0.5.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ac6fec5593ee5472f1b49e228e51ed29d76ffa3fd153ce86d555188c8c79531
BLAKE2b-256 checksum
How to use checksums
274e74af94a09d3597fe1457678cdd7acbf607723c6682a05858500cdf55882f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.13 Darwin/22.6.0

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page