This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/python/intern/bpy_capi_utils.h
Campbell Barton 2d2baeaf04 Fix: T78228 Send all python errors to info editor
Python exceptions are now shown in the info editor,
this also resolves an old bug where errors were printed twice.

This was originally based on D9752 by @ShadowChaser although many
changes have been made from the original patch.

Details:

- BPy_errors_to_report no longer prints additional output.
- BKE_report_print_test was added so it's possible to check if calling
  BKE_report also printed to the stdout.
- Callers to BPy_errors_to_report are responsible for ensuring output
  is printed to the stdout/stderr.
- Python exceptions no longer add a trailing newline,
  needed to avoid blank-space when displayed in the info-editor.
2022-04-06 18:02:58 +10:00

55 lines
1.5 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup pythonintern
*/
#pragma once
#if PY_VERSION_HEX < 0x030a0000
# error "Python 3.10 or greater is required, you'll need to update your Python."
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct EnumPropertyItem;
struct ReportList;
/* error reporting */
short BPy_reports_to_error(struct ReportList *reports, PyObject *exception, bool clear);
/**
* A version of #BKE_report_write_file_fp that uses Python's stdout.
*/
void BPy_reports_write_stdout(const struct ReportList *reports, const char *header);
bool BPy_errors_to_report_ex(struct ReportList *reports,
const char *error_prefix,
bool use_full,
bool use_location);
/**
* \param reports: When set, an error will be added to this report, when NULL, print the error.
*
* \note Unless the caller handles printing the reports (or reports is NULL) it's best to ensure
* the output is printed to the `stdout/stderr`:
* \code{.cc}
* BPy_errors_to_report(reports);
* if (!BKE_reports_print_test(reports)) {
* BKE_reports_print(reports);
* }
* \endcode
*/
bool BPy_errors_to_report(struct ReportList *reports);
struct bContext *BPY_context_get(void);
extern void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate);
/**
* Context should be used but not now because it causes some bugs.
*/
extern void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate);
#ifdef __cplusplus
}
#endif