config

import nblite.config as this_module

ExportRule

Inherits from: BaseModel


CodeLocation

Inherits from: BaseModel


Methods

file_ext

file_ext(self) -> str

jupytext_format

jupytext_format(self) -> str

NBLiteConfig

Inherits from: BaseModel


Methods

init

__init__(self, **kwargs)

_has_cycle

_has_cycle(cls, rules: List[ExportRule]) -> bool

_order_pipeline

_order_pipeline(cls, pipeline: List[ExportRule]) -> List[ExportRule]

__post_process

__post_process(self)

conf = NBLiteConfig(
    docs_cl="nbs",
    export_pipeline=[
        ExportRule(from_key="nbs", to_key="pts"),
        ExportRule(from_key="pts", to_key="lib"),
        ExportRule(from_key="test_nbs", to_key="test_pts"),
        ExportRule(from_key="test_pts", to_key="test_lib"),
    ],
    code_locations={
        "nbs": CodeLocation(path="nbs", format="ipynb"),
        "pts": CodeLocation(path="pts", format="percent"),
        "test_nbs": CodeLocation(path="test_nbs", format="ipynb"),
        "test_pts": CodeLocation(path="test_pts", format="percent"),
        "lib": CodeLocation(path="my_module", format="module"),
        "test_lib": CodeLocation(path="test_module", format="module"),
    }
)

parse_config_dict

parse_config_dict(config_dict) -> NBLiteConfig

toml_string = '''
export_pipeline = """
    #nbs->pts
    pts ->lib
    test_nbs-> test_pts, test_pts->test_lib
"""
docs_cl = "nbs"

[cl.lib]
path = "my_module"
format = "module"

[cl.test_lib]
path = "test"

[cl.nbs]
format = "ipynb"

[cl.pts]
format = "percent"

[cl.test]
format = "module"

[cl.test_nbs]
format = "ipynb"

[cl.test_pts]
'''

parse_config_dict(toml.loads(toml_string)).model_dump()
{'export_pipeline': [{'from_key': 'pts', 'to_key': 'lib'},
  {'from_key': 'test_nbs', 'to_key': 'test_pts'},
  {'from_key': 'test_pts', 'to_key': 'test_lib'}],
 'code_locations': {'lib': {'path': 'my_module', 'format': 'module'},
  'test_lib': {'path': 'test', 'format': 'module'},
  'nbs': {'path': 'nbs', 'format': 'ipynb'},
  'pts': {'path': 'pts', 'format': 'percent'},
  'test': {'path': 'test', 'format': 'module'},
  'test_nbs': {'path': 'test_nbs', 'format': 'ipynb'},
  'test_pts': {'path': 'test_pts', 'format': 'percent'}},
 'docs_cl': 'nbs',
 'docs_title': None}
toml_string = '''
export_pipeline = """
    pts ->lib
"""
docs_cl = "nbs"
'''

parse_config_dict(toml.loads(toml_string)).model_dump()
{'export_pipeline': [{'from_key': 'pts', 'to_key': 'lib'}],
 'code_locations': {'pts': {'path': 'pts', 'format': 'percent'},
  'lib': {'path': 'lib', 'format': 'module'}},
 'docs_cl': 'nbs',
 'docs_title': None}
_find_config_file(Path('../../test_proj')).name
'nblite.toml'

read_config

read_config(path) -> NBLiteConfig

read_config('../../test_proj/nblite.toml')
NBLiteConfig(export_pipeline=[ExportRule(from_key='nbs', to_key='pcts'), ExportRule(from_key='pcts', to_key='lgts'), ExportRule(from_key='lgts', to_key='lib')], code_locations={'lib': CodeLocation(path='my_module', format='module'), 'pcts': CodeLocation(path='pcts', format='percent'), 'lgts': CodeLocation(path='lgts', format='light'), 'nbs': CodeLocation(path='nbs', format='ipynb')}, docs_cl='pcts', docs_title='nblite')

get_project_root_and_config

get_project_root_and_config(curr_folder: Union[Path, None]) -> Path

root_path, config = get_project_root_and_config('../../test_proj')
Path(root_path).name
'test_proj'

get_top_level_code_locations

get_top_level_code_locations(config: NBLiteConfig) -> List[str]

Returns the top level code locations in the export pipeline.


root_path, config = get_project_root_and_config('../../test_proj')
get_top_level_code_locations(config)
['nbs']
config = read_config('../../test_proj/nblite.toml')
get_downstream_module(config, 'nbs')
'lib'