read
Config
nbprocess uses a settings.ini
file in the root of the project to store all configuration details. This file is in ConfigParser
format, and can be read and written conveniently using fastcore’s Config
class.
nbprocess_create_config
nbprocess_create_config (user:str, lib_name:str=None, description='TODOfillmein', author='TODOfillmein', author_email='todo@example.org', path:str='.', cfg_name:str='settings.ini', branch:str='master', host:str='github', git_url: str='https://github.com/%(user)s/%(lib_name)s/tr ee/%(branch)s/', custom_sidebar:<functionbool_ar gat0x7f9a16c5bd00>=False, nbs_path:str='.', lib_path:str='%(lib_name)s', doc_path:str='_docs', tst_flags:str='', version:str='0.0.1', keywords='python', license='apache2', copyright='', status='3', min_python='3.6', audience='Developers', language='English')
Creates a new config file for lib_name
and user
and saves it.
Type | Default | Details | |
---|---|---|---|
user | str | Repo username | |
lib_name | str | None | Name of library |
description | str | TODO fill me in | Description for pypi |
author | str | TODO fill me in | Author for pypi |
author_email | str | todo@example.org | Email for pypi |
path | str | . | Path to create config file |
cfg_name | str | settings.ini | Name of config file to create |
branch | str | master | Repo branch |
host | str | github | Repo hostname |
git_url | str | https://github.com/%(user)s/%(lib_name)s/tree/%(branch)s/ | Repo URL |
custom_sidebar | bool_arg | False | Create custom sidebar? |
nbs_path | str | . | Name of folder containing notebooks |
lib_path | str | %(lib_name)s | Folder name of root module |
doc_path | str | _docs | Folder name containing docs |
tst_flags | str | Test flags | |
version | str | 0.0.1 | Version number |
keywords | str | python | Keywords for pypi |
license | str | apache2 | License for pypi |
copyright | str | Copyright for pypi, defaults to author from current year | |
status | str | 3 | Status for pypi |
min_python | str | 3.6 | Minimum python version for pypi |
audience | str | Developers | Audience for pypi |
language | str | English | Language for pypi |
This is a wrapper for fastcore
’s save_config_file
which sets some nbprocess
defaults. It is also installed as a CLI command.
get_config searches for settings.ini
in the current directory, and then in all parent directories, stopping when it is found.
'fastai', path='..', nbs_path='nbs', tst_flags='tst', cfg_name='test_settings.ini')
nbprocess_create_config(= get_config('test_settings.ini')
cfg 'nbprocess')
test_eq(cfg.lib_name, "https://github.com/fastai/nbprocess/tree/master/")
test_eq(cfg.git_url, = Path.cwd()
cwd
test_eq(cfg.config_path, cwd.parent.absolute())'lib_path'), cwd.parent/'nbprocess')
test_eq(cfg.path('nbs_path'), cwd)
test_eq(cfg.path('doc_path'), cwd.parent/'_docs') test_eq(cfg.path(
Exporting a basic module
Python modules require a __init.py__
file in all directories that are modules. We assume that all directories containing a python file (including in subdirectories of any depth) is a module, and therefore add a __init__.py
to each.
with tempfile.TemporaryDirectory() as d:
= Path(d)
d /'a/b').mkdir(parents=True)
(d/'a/b/f.py').touch()
(d/'a/c').mkdir()
(d
add_init(d)assert not (d/'a/c'/_init).exists(), "Should not add init to dir without py file"
for e in [d, d/'a', d/'a/b']: assert (e/_init).exists(),f"Missing init in {e}"
This is a simple exporter with just enough functionality to correctly export this notebook, in order to bootstrap the creation of nbprocess itself.