utils

import nblite.utils as this_module

get_nb_format_from_path

get_nb_format_from_path(path: str) -> str

get_nb_format_from_path('file.pct.py')
'module'

get_nb_path_info

get_nb_path_info(nb_path: str, root_path: str, config: NBLiteConfig)

root_path = '../../test_proj'
root_path, config = get_project_root_and_config(root_path)
get_nb_path_info('../../test_proj/nbs/notebook1.ipynb', '../../test_proj', config)
{'name': Path('nbs/notebook1'),
 'cl_name': Path('notebook1'),
 'basename': 'notebook1',
 'format': 'ipynb',
 'file_ext': 'ipynb',
 'cl_path': 'nbs'}

is_code_loc_nb

is_code_loc_nb(nb_path: str, root_path: str, config: NBLiteConfig)

Returns True if the notebook is a notebook associated with a code location.


root_path = '../../test_proj'
print(is_code_loc_nb('../../test_proj/nbs/notebook1.ipynb', root_path, config))
print(is_code_loc_nb('../../test_proj/nbs/notebook1.pct.py', root_path, config))
print(is_code_loc_nb('../../test_proj/test.txt', root_path, config))
True
False
False

get_code_location_nbs

get_code_location_nbs(
   root_path: str,
   cl: CodeLocation,
   ignore_dunders: bool,
   ignore_periods: bool
)

Returns all notebooks in a code location. If ignore_dunders is True,

notebooks that being with a dunder (double underscore ’__’) in their names, or notebooks in folders that start with dunders, are ignored.


get_code_location_nbs('../../test_proj', CodeLocation(path='nbs', format='ipynb'))
[Path('../../test_proj/nbs/notebook2.ipynb'),
 Path('../../test_proj/nbs/notebook1.ipynb'),
 Path('../../test_proj/nbs/func_notebook.ipynb'),
 Path('../../test_proj/nbs/func_notebook2.ipynb'),
 Path('../../test_proj/nbs/index.ipynb'),
 Path('../../test_proj/nbs/submodule/notebook3.ipynb'),
 Path('../../test_proj/nbs/folder/notebook4.ipynb'),
 Path('../../test_proj/nbs/folder/subfolder/notebook7.ipynb')]
get_code_location_nbs('../../test_proj', CodeLocation(path='nbs', format='ipynb'), ignore_dunders=False)
[Path('../../test_proj/nbs/notebook2.ipynb'),
 Path('../../test_proj/nbs/__notebook6.ipynb'),
 Path('../../test_proj/nbs/notebook1.ipynb'),
 Path('../../test_proj/nbs/func_notebook.ipynb'),
 Path('../../test_proj/nbs/func_notebook2.ipynb'),
 Path('../../test_proj/nbs/index.ipynb'),
 Path('../../test_proj/nbs/__scratch/notebook5.ipynb'),
 Path('../../test_proj/nbs/submodule/notebook3.ipynb'),
 Path('../../test_proj/nbs/folder/notebook4.ipynb'),
 Path('../../test_proj/nbs/folder/subfolder/notebook7.ipynb')]

is_nb_unclean

is_nb_unclean(
   nb_path: Union[str, None],
   file_content: Union[str, None],
   include_top_metadata: bool
)

is_nb_unclean(file_content='{"cells":[]}')
False
is_nb_unclean('../../test_proj/nbs/notebook1.ipynb')
False

get_unclean_nbs

get_unclean_nbs(root_path: str, ignore_dunders: bool)

Get all notebooks that have metadata or execution count.

Returns: bool: True if all notebooks are clean, False otherwise.


unclean_nbs = get_unclean_nbs('../../test_proj')

get_relative_path

get_relative_path(from_path: str, to_path: str)

Returns the relative path to the root path.


get_relative_path('.', '/Users/lukastk/')
Path('../../../..')

is_ignorable_path

is_ignorable_path(path: str, cl_path: str)

Returns True if any part of the path, relative to the code location path, starts with an underscore or period.