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-dirVerified import paths — ran on the pinned version, not inferred.
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.
Pass an explicit `mode` argument: `provide_dir('/path/to/dir', mode=0o755)`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`.
For file paths, extract the directory part before calling `provide_dir`: `provide_dir(os.path.dirname('path/to/file.txt'))`.Install the package using pip: `pip install provide-dir`. Ensure the import statement is `import provide_dir` or `from provide_dir import provide_dir`.
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)`.
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.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.
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`.
No dependency data recorded yet.