Commit Graph

3095 Commits

Author SHA1 Message Date
Campbell Barton
3de916ca25 RNA: support for marking properties as deprecated
Deprecation meta-data support for RNA properties.

- Properties may have a deprecated note and version.
- Warnings shown when these are accessed from Python.
- A note is included in the generated documentation.

Support for marking functions as deprecated can be added in the future.

Ref !139487
2025-07-29 22:09:59 +10:00
Campbell Barton
c4ba04428c PyAPI: show Python warnings by default when debugging
Show warnings for debug builds or when `--debug-python` is passed in.

Without this, only scripts running in the `__main__` namespace
show warnings - hiding warnings for almost all scripts & add-ons.

This is also needed so deprecation warnings can be shown, see !139487.
2025-07-29 22:09:59 +10:00
Brecht Van Lommel
fa007002b1 Refactor: Logging: Move G.quiet to CLOG, replace some printfs
* Replace G.quiet by CLG_quiet_set/get
* CLOG_INFO_NOCHECK prints are now suppressed when quiet, these were
  typically inside a if (!G.quiet) conditional already.
* Change some prints for blend files, color management and rendering to
  use CLOG, that were previously using if (!G.quiet) printf().

Pull Request: https://projects.blender.org/blender/blender/pulls/143138
2025-07-28 13:36:13 +02:00
Campbell Barton
01436bfbf3 Build: unbreak WITH_INTERNATIONAL=ON 2025-07-27 13:27:27 +10:00
Campbell Barton
9f056204e5 Cleanup: use UTF8 string functions in source/blender/python
Use UTF8 aware functions unless raw bytes are expected.
2025-07-27 12:49:02 +10:00
Campbell Barton
83a489d9ac Cleanup: remove commented code
These errors are handled by exceptions.
2025-07-27 12:49:02 +10:00
Hans Goudey
9c9695b103 Refactor: Move ReportList definition from DNA to blenkernel
Ever since [0], ReportList is not actually used in any DNA structs.
That makes sense, since reports are conceptually only necessary
at runtime. Move the definition of the struct to BKE_report.hh, and
fix a bunch of include errors where types were previously available
transitively. Besides adding some clarity, theoretically this change
could reduce compile times because of less header parsing.

[0]: 1bf6d8b0b9

Pull Request: https://projects.blender.org/blender/blender/pulls/138872
2025-07-24 15:59:52 +02:00
Brecht Van Lommel
7f0f8d4e94 PyDoc: Document all app handler arguments
Previously this was only done for a couple handlers.

Ref #142330

Pull Request: https://projects.blender.org/blender/blender/pulls/142873
2025-07-23 14:23:21 +02:00
Campbell Barton
5e3db5fbb0 Cleanup: consistent use of back-ticks in code-comments 2025-07-23 20:59:16 +10:00
Campbell Barton
d3fd04c816 Fix #142909: SystemError when collections contain non UTF8 names
The Python API wasn't accounting for structs name properties using
path sub-types, which allow non UTF8 byte sequences.

This meant accessing the SpaceFileBrowser.recent_folders collection
could cause unhandled exceptions because
FileBrowserFSMenuEntry.name uses the PROP_FILENAME sub-type.

Resolve by adding a wrapper around the RNA struct name lookup
that handles path properties properly.
2025-07-23 12:38:23 +10:00
Campbell Barton
ec62b843da PyAPI: warn when PropertyGroup sub-classes don't define __slots__
Warn since this allows for confusing assignments, see #141948.
2025-07-16 17:44:06 +10:00
Guillermo Venegas
1a247fbaa8 Refactor: WM: Make OperatorCallContext an enum class, move to namespace
This allows forward declaring `OpCallContext`, avoiding the
transitive include `WM_Types.hh` in `UI_interface_layout.hh`

Pull Request: https://projects.blender.org/blender/blender/pulls/141804
2025-07-15 03:08:04 +02:00
Bastien Montagne
159ea313f3 BPY: Add basic blendfile version info in data returned by bpy.data.libraries.load()
Only major and minor versions are available at that point, not the
blendfile subversion.

Version info is available in both `bpy_library` items returned by the
context handler, as a `version` property that is a tuple of two numbers.

Co-authored-by: Campbell Barton <campbell@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/141462
2025-07-14 14:43:08 +02:00
Campbell Barton
ec8751f826 Cleanup: white-space around C-style comment blocks
Also use C++ style comments for disabling code.
2025-07-13 21:58:53 +10:00
Brecht Van Lommel
4653b65f7c Logging: Add DEBUG, TRACE severity, replace numeric levels
The numeric levels have no obvious meaning. This removes the distinction
between severity and levels, instead there is a single list of named levels
with defined meaning.

Debug means information that's mainly useful for developers, and trace is for
very verbose code execution tracing.

Pull Request: https://projects.blender.org/blender/blender/pulls/140244
2025-07-09 20:59:26 +02:00
Campbell Barton
5f4478f2e4 Merge branch 'blender-v4.5-release' 2025-07-08 22:02:07 +10:00
Andrej730
8246ea913f Fix: wrong argument name in doc-string
Correct regression from !141334.

Ref !141592
2025-07-08 12:00:32 +00:00
Campbell Barton
5781276ecb Cleanup: remove capabilities from the PyAPI that aren't used 2025-07-08 16:41:46 +10:00
Campbell Barton
439253eab5 Cleanup: use consistent terms in capability flags
Consistently use terms "cursor" & "clipboard" as a prefix
so they auto-complete more usefully.

Previously both ordering was used.
2025-07-08 16:35:42 +10:00
Campbell Barton
2a414eea0c PyAPI: Refactor attribute access to avoid creating & clearing exceptions
- Add PyObject_GetOptionalAttrString (only available in Python 3.13).
- When registering RNA classes use optional attribute access to avoid
  raising and clearing exceptions.
- Refactor macro that handles substituting Python's built-ins
  with a `for` loop for better readability.
2025-07-04 12:09:16 +10:00
Campbell Barton
dad8bddd78 Cleanup: remove redundant calls to PyErr_Clear after PyErr_Print
I was under the impression both were needed however
PyErr_Print always clears the error too.
2025-07-04 11:10:54 +10:00
Campbell Barton
b99e4e1de1 PyAPI: treat "None" fallback properties as missing in class registration
If `__name__` or `__doc__` were None, the property would be detected as
being set when checking if the property is set (for required properties).

This is more of a technical correction as its unlikely developers would
run into this in practice since `__name__` should never be None and
the description is not a required property.
2025-07-04 11:02:24 +10:00
Thomas Dinges
b5c0f2dc32 Merge branch 'blender-v4.5-release' 2025-07-03 11:16:04 +02:00
Thomas Dinges
c94d5340b6 Cleanup: Make format 2025-07-03 11:14:58 +02:00
Campbell Barton
f0df1f5f38 Merge branch 'blender-v4.5-release' 2025-07-03 18:39:27 +10:00
Andrej730
1a9e90e965 PyDoc: bpy_struct, add missing types and more explicit signatures
- `bpy_struct.id_data` - provide a type.
- `bpy_struct` - add missing return types to
  `bpy_struct.get`, `bpy_struct.pop`, `bpy_struct.path_resolve`.
- `bpy_struct` - add missing argument types to some methods.
- `bpy_struct` - provide explicit `/` and `*` in signatures to make it
  clear which arguments are positional / keyword-only.

Ref !141334
2025-07-03 18:25:09 +10:00
Campbell Barton
3b538a01d9 Cleanup: quiet deprecation warning building with Python 3.14
Replace use of `_PyDict_Pop` with `PyDict_Pop` when available.
2025-06-30 15:55:19 +10:00
Campbell Barton
e9f675f40b PyAPI: add missing options to bpy.data.library.load(..)
Support options which were available from the operator:
set_fake, recursive, reuse_local_id & clear_asset_data.
2025-06-30 15:47:16 +10:00
Campbell Barton
b2ec149652 Merge branch 'blender-v4.5-release' 2025-06-30 14:31:56 +10:00
Andrej730
b025874666 Fix: Pydocs: EnumProperty items is also allowing iterables
Ref !141134
2025-06-30 14:31:15 +10:00
Campbell Barton
6253a33aa3 Cleanup: use nodiscard attribute for functions in the Python API
In most (cases functions returning a PyObject pointer
requires it to be used by the caller, declare functions in the Python
API with the `nodiscard` attribute.
2025-06-28 10:15:27 +10:00
Campbell Barton
7bc5347d91 Merge branch 'blender-v4.5-release' 2025-06-26 18:39:03 +10:00
Campbell Barton
2355a32017 Fix crash calling bpy.data.file_path_map with non UTF8 paths 2025-06-26 18:35:37 +10:00
Campbell Barton
c71b314565 Cleanup: return a boolean from BPY_context_member_get, check it's result 2025-06-26 14:28:40 +10:00
Campbell Barton
e7fe0932e6 Merge branch 'blender-v4.5-release' 2025-06-25 23:38:40 +10:00
Campbell Barton
5b06823f99 Fix #140929: Crash attempting to link from the current file from Python
Add an error check that the path being linked doesn't match the current
blend file.

Also resolve reference leak in the case of library override errors.
2025-06-25 13:37:52 +00:00
Bastien Montagne
7276b2009a Core: Add new 'system IDprops' storage for runtime-generated RNA properties.
This commit cleanly splits IDProperties storage for its two very different
usages:
* "User-defined" data, also known as "custom properties". Mostly exposed
  in UI and as 'dictionary' in Python scripting, these are unique to each data
  (each object can have its own set of custom properties).
* "System-defined" data, mainly as backend-storage for runtime RNA
  structures and properties. While these are not necessarily present in the
  storage, they are registered for a data type, and therefore always available
  to all data of that type through RNA access.

See #123232 for rationales, designs and alternative investigated solutions.

## User-facing Changes

When using Blender, the only noticeable change is that python-defined RNA
data are not listed anymore in the Custom Properties panels (e.g. Cycles
data).

From a Python API perspective, the main changes are:
* Runtime RNA structs defined by sub-classing `PropertyGroup` and
  registering them are no more accessible through the 'dict' syntax.
  * They remain accessible through a dedicated 'bl_system_properties_get()`
    callback, but its usages are only expected to be for testing and
    debugging.
  * The result of this call will be `None` by default when there has been
    nothing written into it yet, unless its optional `do_create` parameter
    is set to `True`.
* Some types (like `Node`, `UIList`, etc.) cannot store raw IDProperties
  anymore (using the 'dict' syntax).

## Technical Details

* Adds System idprops to some data types (IDs, ViewLayer...).
* Moves some other containers (e.g operator properties, or some UI types like
  UILists) to only have system-defined properties.
* For a few specific types (like `PropertyGroup`), the same storage is used,
  but exposed in RNA as both user and system properties.
* Adds RNA API accessor callback to system idprops.
* Adds a function `bl_system_properties_get()`, which wraps system-defined
  idprops and gives 'dict-like' access to them. Currently mainly used by some
  unittests.
* System IDProps are always ignored by RNA diffing code (and therefore
  liboverride processing), as their value is already exposed through RNA
  properties, and should always be processed through these RNA properties.
* Modifies bpy rna binding to use these new system idprops for property
  accesses, and keeps using user-defined idprops for 'dict-type' accesses.
* Handles versioning by copying 'user idprops' (existing ones) into new
  'system idprops'.

### IDProperties Split

These types keep their historic IDProperty storage for user properties,
and get a new `system_id_properties` storage for system properties:

`ID`, `ViewLayers`, `Bone`, `EditBone`, `BoneCollection`, `PoseBone`, `Strip`

These types can both be extended with registrable RNA properties, and
expose Custom Properties in the UI.

### IDProperties become System Ones

These types keep a single IDProperties storage (their DNA struct does not
change), but it is now exclusively used for system-defined properties.

`OperatorProperty`, `View3DShading`, `UIList`, `AddonPreferences`,
`KeyConfigPreferences`, `GizmoProperties`, `GizmoGroupProperties`,
`Node`, `NodeSocket`, `NodeTreeInterfaceSocket`, `TimelineMarker`,
`AssetMetaData``

Since user properties were never available in the UI for them, they lose
their 'dict-like' IDProperties access in the Python API.

### Single Storage, Exposed as Both in API

These types still use a single IDProperty storage, but expose it both as
user properties and as system ones through RNA API.

* `PropertyGroup`: They need both access APIs since they are both
  used for raw IDProperty groups (the 'dict-like' access), and
  internally to access data of runtime-defined RNA structs.
* `IDPropertyWrapPtr`: Done mainly to follow `PropertyGroup`.
* `NodesModifier`: cannot become purely system idprops currently, as
  there is no other access than the 'raw ID properties' paths to their
  values. This can be changed once #132129 is finally implemented.

Pull Request: https://projects.blender.org/blender/blender/pulls/135807
2025-06-23 18:25:24 +02:00
Guillermo Venegas
091db9d52b Cleanup: UI: Use UI_interface_layout.hh instead of UI_interface.hh
This removes the include `UI_interface_layout.hh` from
`UI_interface_c.hh`, and in many places this swaps the include
from `UI_interface.hh` to `UI_interface_layout.hh`.

Also, cleanups some `UI_interface.hh` includes with
`UI_interface_icons.hh` or `UI_interface_types.hh`
2025-06-20 18:07:47 +02:00
Campbell Barton
2e3d19ca4f Merge branch 'blender-v4.5-release' 2025-06-20 19:55:35 +10:00
Campbell Barton
bfb6b184f5 Fix #140332: Crash with Python/RNA class registration
Resolve reference counting error in the RNA API which mixed up ownership
between ExtensionRNA::data & StructRNA::py_data.

In practice this generally worked as RNA_struct_free_extension behaved
as if ExtensionRNA owned the reference instead of StructRNA, so as long
as only one reference was removed, there wasn't any difference.

When re-registering Python classes with RNA, ownership wasn't handled
properly which could result in negative reference counts,
crashing in some cases.
2025-06-20 09:54:13 +00:00
Campbell Barton
715a8268fa Build: resolve errors & deprecation warnings with Python 3.14 beta
Python 3.14 has moved some functionality into the public API,
use the updated names even with older Python versions.

Also resolve an error caused by variable reuse with delayed annotation
evaluation for TextureProperties_MixIn on startup.

Resolve #140695.
2025-06-20 14:34:25 +10:00
Campbell Barton
6197335658 Build: resolve errors & deprecation warnings with Python 3.14 beta
Python 3.14 has moved some functionality into the public API,
use the updated names even with older Python versions.

Also resolve an error caused by variable reuse with delayed annotation
evaluation for TextureProperties_MixIn on startup.

Resolve #140695.
2025-06-20 04:19:35 +00:00
Clément Foucault
decd88f67e Python: Remove deprecated BGL API
The API was in a deprecation state for many years now.
This API was not compatible with Metal nor Vulkan.

This also remove `Image.bindcode`.

Pull Request: https://projects.blender.org/blender/blender/pulls/140370
2025-06-16 12:50:50 +02:00
Campbell Barton
2a1be1f704 Fix memory leaks in Python argument parsing
Resolve some of the leaks exposed by running tests with guarded-alloc
checks enabled.
2025-06-11 15:15:20 +10:00
Campbell Barton
6195e84c65 Merge branch 'blender-v4.5-release' 2025-06-10 22:22:12 +10:00
Campbell Barton
1999b72ec2 Fix memory leaks in Python argument parsing
Resolve some of the leaks exposed by running tests with guarded-alloc
checks enabled.
2025-06-10 22:21:58 +10:00
Aras Pranckevicius
5ad6d42c83 IO: Remove Collada import/export
Removes Collada import/export (has been deprecated since 4.2).

Pull Request: https://projects.blender.org/blender/blender/pulls/139337
2025-06-06 08:38:57 +02:00
Campbell Barton
e8afe173a0 PyAPI: add bpy.app.built_options.experimental_features
Provide a way to check if blender is running WITH_EXPERIMENTAL_FEATURES
defined.
2025-06-06 10:48:25 +10:00
Andrej730
f7ce58cefc Fix: PyDocs: Annotations for callables with variable number of arguments
Annotation `Callable[[Any, ...], str | None]` is not supported by Python
typing system and ... will be misinterpreted as unknown type instead of
option to provide variable number of arguments.

Ref !138804
2025-06-04 15:23:38 +10:00
Hans Goudey
77b14f2dcb Cleanup: Grammar: Fallback vs. fall back
The former is a noun or adjective, the latter is a verb.
2025-06-02 17:13:56 -04:00