nbqol.env#
Environment detection and path utilities for Jupyter notebooks.
This module provides tools for detecting notebook paths, Git repository paths, and other environment-related functionality.
Functions
|
Add the git root to the sys.path. |
|
Get the relative path between two paths. |
Check if code is running in a Jupyter environment. |
|
Check if code is running in Visual Studio Code. |
|
Check if code is running in a Jupyter notebook within VS Code. |
|
Get the path to the current notebook. |
|
|
Get the path to the root of the current git repository, up to max_depth levels. |
- 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'
- 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
- is_running_in_jupyter()[source]#
Check if code is running in a Jupyter environment.
This function checks if the code is running within an IPython kernel, which is the case for Jupyter notebooks and similar environments.
- Returns:
True if running in Jupyter, False otherwise
- Return type:
bool
Examples
>>> from nbqol import stylizer >>> stylizer.is_running_in_jupyter() True # If running in Jupyter False # If running in a standard Python environment
- is_running_in_vscode()[source]#
Check if code is running in Visual Studio Code.
This function checks environment variables to determine if the code is running within the Visual Studio Code environment.
- Returns:
True if running in VS Code, False otherwise
- Return type:
bool
Examples
>>> from nbqol import stylizer >>> stylizer.is_running_in_vscode() True # If running in VS Code False # If running elsewhere
- is_running_in_vscode_jupyter()[source]#
Check if code is running in a Jupyter notebook within VS Code.
This function combines checks for both Jupyter and VS Code to determine if the code is running in a Jupyter notebook specifically within VS Code.
- Returns:
True if running in a VS Code Jupyter notebook, False otherwise
- Return type:
bool
Examples
>>> from nbqol import stylizer >>> stylizer.is_running_in_vscode_jupyter() True # If running in a VS Code Jupyter notebook False # If running elsewhere
Modules
Path utilities for Jupyter notebooks and Git repositories. |