flow#

Functions to manage the flow of scripts from prototyping to computing.

Includes conversion of notebooks to scripts.

Functions#

get_caller_path()

Dynamically extracts the full filepath of the calling notebook or script.

convert_to_script([commit, fix, formatters, ...])

Convert Jupyter notebook to a script

test_script(*args[, verbose, committed])

Run a test of a script

Module Contents#

openplaces.flow.get_caller_path()#

Dynamically extracts the full filepath of the calling notebook or script. Prioritizes specific environment markers (VS Code, ipynbname) before falling back to standard script detection.

openplaces.flow.convert_to_script(commit=False, fix=True, formatters=['ruff'], raise_error=True, show=False, verbose=False)#

Convert Jupyter notebook to a script

Includes numerous string edits:

  • ‘Set arguments’ > ‘Get arguments’ (currently for FIPS only)

  • Import standard imports from lib.core

  • Simplify headings

  • Remove ‘In [*]’

  • Format header

  • Drop anything after ‘Convert notebook to script’

Parameters:
  • commit (bool) – If True, will write to the Python script. This will trigger the script to be updated by the current scheduler (db/update.ipynb), which is bases its decisions on the last-modified timestamp of the scripts (not diffs to last run version, which would be better).

  • fix (bool) – If True, will use ruff check –fix to try and fix all issues

  • formatters (list of str) – Formatters to apply if fix=True. Only ruff is currently supported.

  • raise_error (bool) – If True, will raise non-compliance errors. If False, will only print the error.

  • show (bool) – If True, will print code regardless of whether error was found

  • verbose (bool:) – If True, will output additional information to troubleshoot.

openplaces.flow.test_script(*args, verbose=False, committed=True)#

Run a test of a script

Parameters:
  • *args (tuple of strings) – Unnamed arguments will be passed as strings

  • verbose (bool) – If True, will print outputs. Will be set to True if ‘–verbose’ is in args.

  • committed (bool) – If True, will run the committed version of the script. If False, will run the test version.