Skip to main content

Directory layout object for testing and documentation

Project description

dirlay

Directory layout object for testing and documentation

license pypi python versions tests coverage tested with multipython uses docsub mypy uv Ruff

Features

  • Create and remove directory tree with files
  • Chdir to layout subdirectories
  • Display as rich tree for docs
  • Uses pathlib2 for Python 2

Installation

$ pip install dirlay[rich]

Usage

>>> from dirlay import DirectoryLayout, to_tree

Create directory layout tree

>>> layout = DirLayout({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> layout.basedir is None
True
>>> layout.mktree()
>>> layout.basedir
PosixPath('/tmp/...')

And remove when not needed anymore:

>>> layout.rmtree()

Chdir to subdirectory

>>> import os
>>> os.chdir('/tmp')

When layout is instantiated, current directory remains unchanged:

>>> layout = DirLayout({'a': {'b/c.txt': 'ccc'}})
>>> layout.mktree()
>>> layout.getcwd()
PosixPath('/tmp')

On first chdir, initial working directory is stored internally, and will be restored on rmtree. Without argument, chdir sets current directory to layout.basedir.

>>> layout.basedir
PosixPath('/tmp/...')
>>> layout.chdir()
>>> layout.getcwd()
PosixPath('/tmp/...')

If chdir has argument, it must be a path relative to basedir.

>>> layout.chdir('a/b')
>>> layout.getcwd()
PosixPath('/tmp/.../a/b')

When directory is removed, current directory is restored:

>>> layout.rmtree()
>>> layout.getcwd()
PosixPath('/tmp')

Print as tree

>>> layout = DirLayout({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> layout.print_tree()
๐Ÿ“‚ .
โ””โ”€โ”€ ๐Ÿ“‚ a
    โ”œโ”€โ”€ ๐Ÿ“‚ b
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ c.txt
    โ””โ”€โ”€ ๐Ÿ“„ d.txt

Display basedir path and file contents:

>>> layout.mktree()
>>> layout.print_tree(real_basedir=True, show_content=True)
๐Ÿ“‚ /tmp/...
โ””โ”€โ”€ ๐Ÿ“‚ a
    โ”œโ”€โ”€ ๐Ÿ“‚ b
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ c.txt
    โ”‚       โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚       โ”‚ ccc โ”‚
    โ”‚       โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฏ
    โ””โ”€โ”€ ๐Ÿ“„ d.txt
        โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฎ
        โ”‚ ddd โ”‚
        โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฏ

Extra keyword aguments will be passed through to rich.tree.Tree:

>>> layout.print_tree(real_basedir=True, show_content=True, hide_root=True)
๐Ÿ“‚ a
โ”œโ”€โ”€ ๐Ÿ“‚ b
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ c.txt
โ”‚       โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚       โ”‚ ccc โ”‚
โ”‚       โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฏ
โ””โ”€โ”€ ๐Ÿ“„ d.txt
    โ•ญโ”€โ”€โ”€โ”€โ”€โ•ฎ
    โ”‚ ddd โ”‚
    โ•ฐโ”€โ”€โ”€โ”€โ”€โ•ฏ

See also

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

dirlay-0.2.0.tar.gz (93.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dirlay-0.2.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dirlay-0.2.0.tar.gz.

File metadata

  • Download URL: dirlay-0.2.0.tar.gz
  • Upload date:
  • Size: 93.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for dirlay-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7310e81538a0a9c2fcf734056bcbe47ab302cc1945926039853d6bc2d3e99972
MD5 e3f4812985783fa928927c40d274bcdd
BLAKE2b-256 71d91fb630a732e691107cca48ea29e0d3433a21bc7ceb3a0b64d97149571e44

See more details on using hashes here.

File details

Details for the file dirlay-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dirlay-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for dirlay-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb8a25b95778b235b41a2a23b1a730f01c15ec11d5e7323a09cd3b9922dd0c2d
MD5 af09723e1cc3dc15513a66b98b3ccc3e
BLAKE2b-256 b67b6b4b237f2565f5f72e337540401e13e32284ef9b533b5d24c03fae23f74f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page