finesse.utilities.bug_report module

class finesse.utilities.bug_report.SourceType(*values)[source]

Bases: Enum

INTERACTIVE = 'Interactive'
REPL = 'REPL'
SCRIPT = 'Script'
STDIN = 'stdin'
finesse.utilities.bug_report.bug_report(title: str | None = None, file: str | Path | None = None, include_source: bool = False)[source]

Generate a markdown bug report, suitable for copy-pasting into chatrooms or GitLab issues. Contains the source code, the triggered exception (if any) and machine and python environment information.

Parameters

titlestr | None, optional

Title to insert on top of markdown, by default None

filestr | Path | None, optional

Whether to write the report to file. Will silently overwrite existing files, by default None

include_sourcebool, optional

Wether to include the source code that caused the exception (the contents of the Jupyter notebook or Python script file) into the bug report. Be careful when including source with proprietary/confidential information source in bug reports shared in public spaces like Gitlab or the Matrix channel. Defaults to False

finesse.utilities.bug_report.get_formatted_argv() str[source]
finesse.utilities.bug_report.get_formatted_source() str[source]
finesse.utilities.bug_report.get_formatted_traceback() str[source]
finesse.utilities.bug_report.get_package_versions() str[source]

Report all currently imported package version by looping over sys.modules and looking for ‘__version__’ attributes. Explicitly avoids calling into conda/pip since there are too many package managers to accommodate for.

Returns

str

list of <package> == <version> for every package

finesse.utilities.bug_report.get_source() str[source]

Get source of the ‘__main__’ module. Supports Ipython (Jupyter Notebook, VSCode), interactive interpreter and regular python modules.

Returns

str

Source code

finesse.utilities.bug_report.get_source_type() SourceType[source]

Type of source for the python code currently being executed.

Returns

SourceType

Interactive environment (jupyter), terminal REPL or plain python script

finesse.utilities.bug_report.ipynb_to_md(ipynb: dict) str[source]

Converts notebook json object to markdown. Extracts markdown cells as raw text and code blocks wrapped in a python code block.

Parameters

ipynbdict

notebook json dict

Returns

str

Markdown representing notebook

finesse.utilities.bug_report.wrap_block(code: str, lang: str = 'python') str[source]

Wraps a string in a markdown code block like.

`python print('foo') `

Parameters

codestr

code to wrap

langstr, optional

language of code, by default “python”

Returns

str

Markdown code block