nbqol.env.pathutils#
Path utilities for Jupyter notebooks and Git repositories.
This module provides utilities for finding notebook paths, locating Git repositories, and manipulating path relationships.
Functions
|
Add the git root to the sys.path. |
|
Get the relative path between two paths. |
Get the path to the current notebook. |
|
|
Get the path to the root of the current git repository, up to max_depth levels. |
- diffpath(path, root)[source]#
Get the relative path between two paths.
- Parameters:
path (str) – The target path.
root (str) – The root path to compute the relative path from.
- Returns:
The relative path from root to path.
- Return type:
str
- notebook_path()[source]#
Get the path to the current notebook.
- Returns:
The path to the current notebook.
- Return type:
str
- path_to_git_root(max_depth=3)[source]#
Get the path to the root of the current git repository, up to max_depth levels.
This function searches for a .git directory starting from the current working directory and moving up through parent directories, up to max_depth levels.
- Parameters:
max_depth (int) – The maximum depth to search for the git root.
- Returns:
The path to the root of the git repository, if found. None: If no git repository is found within max_depth levels.
- Return type:
str
Examples
>>> from nbqol.env import path_to_git_root >>> git_root = path_to_git_root() >>> print(git_root) '/path/to/git/repo'
- add_git_root_to_sys_path(**kwargs)[source]#
Add the git root to the sys.path.
This function finds the git repository root and adds it to sys.path, allowing imports from the git repository root.
- Parameters:
**kwargs – Keyword arguments to pass to path_to_git_root.
- Returns:
The path that was added to sys.path if successful. None: If no git repository is found.
- Return type:
str
Examples
>>> from nbqol.env import add_git_root_to_sys_path >>> add_git_root_to_sys_path() '/path/to/git/repo'