
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Directory layout object for testing and documentation
dict
tree['a/b.md']
tree / 'a/b.md'
(relative), tree // 'a/b.md'
(absolute)tree |= {'d': {}}
, del tree['a']
contextmanager
interface to unlink tree on exit$ pip install dirlay[rich]
>>> from dirlay import Dir
Define directory structure and files content:
>>> tree = Dir({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> tree.data == {'a': {'b': {'c.txt': 'ccc'}, 'd.txt': 'ddd'}}
True
>>> tree / 'a/b/c.txt'
PosixPath('a/b/c.txt')
>>> tree['a/b/c.txt']
<Node 'a/b/c.txt': 'ccc'>
>>> 'z.txt' in tree
False
Content of files and directories can be updated:
>>> tree |= {'a/d.txt': {'e.txt': 'eee'}}
>>> tree['a/b/c.txt'].data *= 2
>>> tree.root()
<Node '.': {'a': {...}}>
>>> tree.data == {'a': {'b': {'c.txt': 'cccccc'}, 'd.txt': {'e.txt': 'eee'}}}
True
Instantiate on the file system (in temporary directory by default) and remove when exiting the context.
>>> with tree.mktree():
... assert getcwd() != tree.basedir # cwd not changed
... str(tree['a/b/c.txt'].abspath.read_text())
'cccccc'
Optionally, change current working directory to a layout subdir, and change back after context manager is exited.
>>> with tree.mktree(chdir='a/b'):
... assert getcwd() == tree.basedir / 'a/b'
... str(Path('c.txt').read_text())
'cccccc'
Directory layout can be constructed from dict:
>>> tree = Dir({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> tree.basedir is None
True
>>> tree.mktree()
<Dir '/tmp/...': {'a': ...}>
>>> tree.basedir
PosixPath('/tmp/...')
And remove when not needed anymore:
>>> tree.rmtree()
>>> import os
>>> os.chdir('/tmp')
When layout is instantiated, current directory remains unchanged:
>>> tree = Dir({'a/b/c.txt': 'ccc'})
>>> tree.mktree()
<Dir '/tmp/...': {'a': {'b': {'c.txt': 'ccc'}}}>
>>> getcwd()
PosixPath('/tmp')
On first chdir
, initial working directory is stored internally, and will be
restored on destroy
. Without argument, chdir
sets current directory to
tree.basedir
.
>>> tree.basedir
PosixPath('/tmp/...')
>>> tree.chdir()
>>> getcwd()
PosixPath('/tmp/...')
If chdir
has argument, it must be a path relative to basedir
.
>>> tree.chdir('a/b')
>>> getcwd()
PosixPath('/tmp/.../a/b')
When directory is removed, current directory is restored:
>>> tree.rmtree()
>>> getcwd()
PosixPath('/tmp')
>>> tree = Dir({'a': {'b/c.txt': 'ccc', 'd.txt': 'ddd'}})
>>> tree.print_rich()
📂 .
└── 📂 a
├── 📂 b
│ └── 📄 c.txt
└── 📄 d.txt
Display basedir
path and file content:
>>> tree.mktree()
<Dir '/tmp/...': ...>
>>> tree.print_rich(real_basedir=True, show_data=True)
📂 /tmp/...
└── 📂 a
├── 📂 b
│ └── 📄 c.txt
│ ╭─────╮
│ │ ccc │
│ ╰─────╯
└── 📄 d.txt
╭─────╮
│ ddd │
╰─────╯
Extra keyword arguments will be passed through to rich.tree.Tree
:
>>> tree.print_rich(show_data=True, hide_root=True)
📂 a
├── 📂 b
│ └── 📄 c.txt
│ ╭─────╮
│ │ ccc │
│ ╰─────╯
└── 📄 d.txt
╭─────╮
│ ddd │
╰─────╯
>>> tree.rmtree()
FAQs
Directory layout object for testing and documentation
We found that dirlay demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.