Skip to content

Commit

Permalink
Use black to format non-source files
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Jul 29, 2023
1 parent 8bdb2d3 commit 6723663
Show file tree
Hide file tree
Showing 5 changed files with 2,102 additions and 1,623 deletions.
85 changes: 43 additions & 42 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,65 @@


extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.extlinks',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'sphinx.ext.autosectionlabel',
'nbsphinx',
'sphinx.ext.mathjax',
'sphinx.ext.intersphinx',
'sphinx_automodapi.automodapi',
'sphinx_automodapi.smart_resolver',
'IPython.sphinxext.ipython_directive',
'IPython.sphinxext.ipython_console_highlighting',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.extlinks",
"sphinx.ext.ifconfig",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.autosectionlabel",
"nbsphinx",
"sphinx.ext.mathjax",
"sphinx.ext.intersphinx",
"sphinx_automodapi.automodapi",
"sphinx_automodapi.smart_resolver",
"IPython.sphinxext.ipython_directive",
"IPython.sphinxext.ipython_console_highlighting",
# 'matplotlib.sphinxext.mathmpl',
# 'matplotlib.sphinxext.only_directives', # not needed after matplotlib
# >3.0.0
'matplotlib.sphinxext.plot_directive',
"matplotlib.sphinxext.plot_directive",
# 'matplotlib.sphinxext.ipython_directive',
'recommonmark', # Parses markdown
]
"recommonmark", # Parses markdown
]

if os.getenv('SPELLCHECK'):
extensions += 'sphinxcontrib.spelling'
if os.getenv("SPELLCHECK"):
extensions += "sphinxcontrib.spelling"
spelling_show_suggestions = True
spelling_lang = 'en_US'
spelling_lang = "en_US"


source_suffix = ['.rst', '.md']
master_doc = 'index'
project = 'dtscalibration'
source_suffix = [".rst", ".md"]
master_doc = "index"
project = "dtscalibration"
year = str(date.today().year)
author = 'Bas des Tombe and Bart Schilperoort'
copyright = '{0}, {1}'.format(year, author)
version = release = '2.0.0'
author = "Bas des Tombe and Bart Schilperoort"
copyright = "{0}, {1}".format(year, author)
version = release = "2.0.0"

pygments_style = 'trac'
templates_path = ['.']
pygments_style = "trac"
templates_path = ["."]
extlinks = {
'issue': ('https://github.com/dtscalibration/python-dts-calibration/issues'
'/%s', '#'),
'pr': ('https://github.com/dtscalibration/python-dts-calibration/pull/%s',
'PR #'),
}
exclude_patterns = ['_build', '**.ipynb_checkpoints', 'Thumbs.db', '.DS_Store']
"issue": (
"https://github.com/dtscalibration/python-dts-calibration/issues" "/%s",
"#",
),
"pr": ("https://github.com/dtscalibration/python-dts-calibration/pull/%s", "PR #"),
}
exclude_patterns = ["_build", "**.ipynb_checkpoints", "Thumbs.db", ".DS_Store"]

html_theme = 'nature'
html_theme = "nature"

html_use_smartypants = True
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"
html_split_index = False
html_sidebars = {
'**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'],
}
html_short_title = '%s-%s' % (project, version)
"**": ["searchbox.html", "globaltoc.html", "sourcelink.html"],
}
html_short_title = "%s-%s" % (project, version)

napoleon_use_ivar = True
napoleon_use_rtype = False
Expand Down
76 changes: 47 additions & 29 deletions docs/nb_examples_to_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
try:
# this file is excecuted as script
wd = os.path.dirname(os.path.realpath(__file__))
print('run as script: wd', wd)
print("run as script: wd", wd)
except:
# Excecuted from console. pwd = ./docs
wd = os.getcwd()
print('run from console: wd', wd)
print("run from console: wd", wd)
pass

file_ext = '*.ipynb'
file_ext = "*.ipynb"

# ./examples/notebooks
inpath = os.path.join(wd, '..', 'examples', 'notebooks')
inpath = os.path.join(wd, "..", "examples", "notebooks")

# ./docs/examples/notebooks
outpath = os.path.join(wd, 'examples', 'notebooks')
fp_index = os.path.join(wd, 'examples', 'index.rst')
outpath = os.path.join(wd, "examples", "notebooks")
fp_index = os.path.join(wd, "examples", "index.rst")

# clean outputdir
shutil.rmtree(outpath)
Expand All @@ -35,42 +35,60 @@
for fp, fn in zip(filepathlist, filenamelist):
if clean_nb:
# save clean notebook to github
check_call(['jupyter', 'nbconvert',
'--clear-output',
'--ClearOutputPreprocessor.enabled=True',
'--inplace',
fp])
check_call(
[
"jupyter",
"nbconvert",
"--clear-output",
"--ClearOutputPreprocessor.enabled=True",
"--inplace",
fp,
]
)
else:
check_call(['jupyter', 'nbconvert',
'--execute',
'--ExecutePreprocessor.kernel_name=python',
'--KernelGatewayApp.force_kernel_name=python',
"--ExecutePreprocessor.timeout=60",
'--inplace',
fp])
check_call(
[
"jupyter",
"nbconvert",
"--execute",
"--ExecutePreprocessor.kernel_name=python",
"--KernelGatewayApp.force_kernel_name=python",
"--ExecutePreprocessor.timeout=60",
"--inplace",
fp,
]
)
# run the notebook to:
# 1) check whether no errors occur.
# 2) save and show outputconvert notebook to rst for documentation
# outfilepath = os.path.join(outpath, fn)
check_call(['jupyter', 'nbconvert',
'--execute',
'--to', 'rst',
'--ExecutePreprocessor.kernel_name=python',
'--KernelGatewayApp.force_kernel_name=python',
"--ExecutePreprocessor.timeout=60",
'--output-dir', outpath,
'--output', fn,
fp])
check_call(
[
"jupyter",
"nbconvert",
"--execute",
"--to",
"rst",
"--ExecutePreprocessor.kernel_name=python",
"--KernelGatewayApp.force_kernel_name=python",
"--ExecutePreprocessor.timeout=60",
"--output-dir",
outpath,
"--output",
fn,
fp,
]
)

# write index file to toc
fp_index = os.path.join(wd, 'examples', 'index.rst')
fp_index = os.path.join(wd, "examples", "index.rst")
s = """Learn by Examples
=================
.. toctree::
"""

with open(fp_index, 'w+') as fh:
with open(fp_index, "w+") as fh:
fh.write(s)
for fn in filenamelist:
sf = " notebooks/{}.rst\n".format(fn)
Expand Down
Loading

0 comments on commit 6723663

Please sign in to comment.