Utils#

(nbrefactor.fileops.utils)

File utilities’ methods used across the library

compute_plot_path(path, ipynb_fname)[source]#

Computes the full plot path. If the given path is a directory, constructs a plot filename using the provided notebook filename and plot extension. Ensures that the directory exists.

Parameters:
  • path (str) – Path to a directory or file where the plot should be saved.

  • ipynb_fname (str) – The name of the Jupyter notebook file (without extension).

Returns:

The full path to the plot

Return type:

str

ensure_dir(path)[source]#

Ensures that the given directory exists, and creates it if it does not exist

Parameters:

path (str) – Path to the dir.

ensure_ipynb_validity(path)[source]#

Ensures that the given path points to a valid .ipynb file.

Parameters:

path (str) – Path to the Jupyter notebook file.

Raises:
  • FileNotFoundError – If the file does not exist.

  • ValueError – If the file is not a .ipynb file.