Registry / devops / provide-dir

provide-dir

JSON →
library0.1.2pypypi✓ verified 87d ago

The `provide-dir` library is a lightweight utility that ensures a given directory path exists, creating all necessary parent directories if they don't. It's built on top of `os.makedirs` and offers a simplified interface. Currently at version 0.1.2, it follows an infrequent but steady release cadence, with updates typically several months apart.

pip install provide-dir
INSTALL
IMPORT
SIG · PROVIDE-DIR
P
provide-dir
devopspythonv0.1.2
Install
1.6s avg
Import
24ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.026s · 18MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.021s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

provide_dir
from provide_dir import provide_dir

This quickstart demonstrates how to use `provide_dir` to create a nested directory structure. It will create `temp_test_dir/my/nested/directory` and print the resulting path. The `os.environ.get` ensures it's runnable without specific environment setup.

from provide_dir import provide_dir import os # Define a test directory path base_dir = os.environ.get('TEST_BASE_DIR', 'temp_test_dir') dir_path = os.path.join(base_dir, 'my', 'nested', 'directory') print(f"Attempting to create: {dir_path}") # Create the directory and all its parents created_path = provide_dir(dir_path) print(f"Directory ensured at: {created_path}") print(f"Does the directory exist? {os.path.isdir(created_path)}") # Clean up (optional) # import shutil # shutil.rmtree(base_dir)
Debug
Known issues
gotchaThe `mode` argument (permissions) defaults to `0o777` (world-writable), which might be too permissive for certain environments or security requirements. Always explicitly set `mode` (e.g., `0o755`) if specific permissions are needed.
fix
Pass an explicit `mode` argument: `provide_dir('/path/to/dir', mode=0o755)`
affects: All versions
gotchaIf `exist_ok` is set to `False` (the default is `True`), a `FileExistsError` will be raised if the target directory already exists. This can be unexpected if you assume it will always succeed for existing paths.
fix
Ensure `exist_ok=True` (which is the default) if you want the function to succeed silently when the directory already exists. If you need to detect existing directories, handle `FileExistsError`.
affects: All versions
gotchaThis function is designed to create directories. If you provide a path that is intended to be a *file* (e.g., `path/to/file.txt`), `provide_dir` will create `path/to/file.txt` as a *directory*, not just its parent `path/to`. To create parent directories for a file, use `os.path.dirname` first.
fix
For file paths, extract the directory part before calling `provide_dir`: `provide_dir(os.path.dirname('path/to/file.txt'))`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'provide_dir'
The `provide-dir` library is not installed in the Python environment, or there's a typo in the import statement.
fix
Install the package using pip: `pip install provide-dir`. Ensure the import statement is `import provide_dir` or `from provide_dir import provide_dir`.
AttributeError: module 'provide_dir' has no attribute 'provide_dir'
This typically happens if you import the module as `import provide_dir` but then try to access a nested attribute `provide_dir.provide_dir()` when the main function is directly available at the top level of the module.
fix
If importing the entire module, call the function directly as `provide_dir.provide_dir(path)`. Alternatively, import the function directly: `from provide_dir import provide_dir` and then call it as `provide_dir(path)`.
TypeError: expected str, bytes or os.PathLike object, not <type>
The `provide_dir` function expects its argument to be a string, bytes, or a path-like object, but received an incompatible type such as a list, tuple, or None.
fix
Ensure the path argument passed to `provide_dir()` is a string (e.g., `provide_dir('/path/to/my/directory')`), a `pathlib.Path` object, or a bytes object.
PermissionError: [Errno 13] Permission denied: '<path>'
The Python process does not have the necessary write permissions to create the specified directory or any of its parent directories in the given path.
fix
Run the script with appropriate permissions (e.g., as a user with write access to the target location) or choose a different directory where the process has write permissions.
FileExistsError: [Errno 17] File exists: '<path>'
Although `provide-dir` is built on `os.makedirs` with `exist_ok=True` (which should prevent this if the path is an existing directory), this error occurs if the specified path already exists, but it refers to a *file* instead of a directory.
fix
Ensure the path provided to `provide_dir()` does not already exist as a file. If it does, either choose a different path, or remove the existing file if it's safe to do so before calling `provide_dir`.
Upgrade
Version history
0.1.2latest on PyPI · released Apr 13, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
provide-dir — pip install provide-dir · libregistry