Minimal directory interface and some implementations
Project description
minidir: Minimal directory interface and implementation
The minimal interface for directories and files and two implementations: in-memory and real file system versions.
It's a good choice when we want to separate file-access side effects from pure functional part of our code base.
Installation
Already published on Pypi
pip install minidir
Usage
- Interface:
Directory
->Path
,File
Directory
is the container where we accessFile
byPath
- Implementation
SystemDirectory
: aDirectory
backed by real file system.FakeDirectory
: aDirectory
only exists in-memory.
Some error like NameCollision
and NotFound
will be raised in corresponding situations.
Example:
import minidir
class SomeClass:
folder: minidir.Directory
def __init__(self, folder: minidir.Directory) -> None:
# inject directory to separate side effect from core logic
pass
def main():
# use actual file system during production
instance = SomeClass(minidir.SystemDirectory("/path/to/root"))
def test_some_class():
# use in-memory implementation during test
instance = SomeClass(minidir.FakeDirectory())
Future Work
- Implementations for network-oriented storage, e.g. WebDAV, S3, Dropbox ...
- Stream based file read / write interface.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
minidir-0.1.3.tar.gz
(4.5 kB
view hashes)