Commit Graph

3129 Commits

Author SHA1 Message Date
Namit Bhutani
8536fd1223 Sculpt: Compress position undo step data
Stored undo step data for position changes in sculpt mode are now
automatically compressed. Compression is run in background threads,
reducing memory consumption during sculpting sessions while adding
little performance overhead.

For testing and benchmarks, memory usage is now available through
`bpy.app.undo_memory_info()`. Undo memory usage is now tracked by the
existing automated benchmark tests. Some changes to the web benchmark
visualization present the data a bit better.

ZSTD compression is run asynchronously in a backround task pool.
Compression is only blocking if the data is requested immediately for
undo/redo.

Co-authored-by: Hans Goudey <hans@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/141310
2025-09-03 19:15:05 +02:00
Campbell Barton
90764de24d Fix: Python memory leak when deferred property registration fails
Regression in [0], resolve by moving error handling
before creating new objects.

[0] a7b3047cef
2025-09-03 22:10:31 +10:00
Bastien Montagne
469f54f484 BPY: Implement get_transform and set_transform for runtime-defined RNA properties.
Improve handling of runtime defined python RNA properties. Mainly:
* Add `get_transform` and `set_transform` new callbacks.
  These allow to edit the value, while still using the default
  (IDProperty-based) storage system.
* Read-only properties should now be defined using a new `options` flag,
  `READ_ONLY`.
* `get`/`set` should only be used when storing data outside of the
  default system now.
  * Having a `get` without a `set` defined forces property to be
    read-only (same behavior as before).
  * Having a `set` without a `get` is now an error.
* Just like with existing `get/set` callbacks, `get_/set_transform`
  callbacks must always generate values matching the constraints defined
  by their `bpy.props` property definition (same type, within required
  range, same dimensions/sizes for the `Vector` properties, etc.).
* To simplify handling of non-statically sized strings, the relevant
  RNA API has been modified, to use `std::string` instead of
  (allocated) char arrays.

Relevant unittests and benchmarking have been added or updated as part
of this project.

Note: From initial benchmarking, 'transform' versions of get/set are
several times faster than 'real' get/set.

Implements #141042.

Pull Request: https://projects.blender.org/blender/blender/pulls/141303
2025-09-02 11:30:09 +02:00
Campbell Barton
9ff2ccd350 Fix: incorrect handling of 3x3 matrices with RNA get/set callbacks
Thanks to @mont29 for spotting the error.
2025-08-29 22:16:39 +10:00
Campbell Barton
38b13f7aa8 Fix: uninitialized memory use in RNA slice assignment
Resolve run-time error caught by UBSAN & script_pyapi_prop_array test.
2025-08-29 07:27:40 +00:00
Campbell Barton
4b35760354 Fix: incorrect doc-strings for bpy.props type argument 2025-08-26 02:14:31 +00:00
Campbell Barton
753b6c031b PyDoc: include keyword only parameter in doc-strings 2025-08-26 02:14:30 +00:00
Sybren A. Stüvel
494b041585 Python: Improve bpy.data.user_map() argument documentation
Update the call signature in the docstring so that it is clear that the
arguments to `bpy.data.user_map()` are all optional:

```
.. method:: user_map(*, subset=None, key_types=None, value_types=None)
```

This is important for Python stubs that are generated from the
docstrings; see https://github.com/michaelgold/buildbpy/issues/3.

This change feels a bit weird, as the function behaves differently
depending on whether the arguments are there or not. For example,
`subset=None` is not actually valid, as it should be a dictionary and
the function will raise a `TypeError`. But documenting `subset=dict()`
is also incorrect, because explicitly passing that will make the
function behave differently: it reports an empty dictionary, instead of
reporting everything. The same goes for the other parameters.

A better approach (IMO) would be to either add "empty dict/set means
'everything'" logic, or to allow `None` values for these parameters so
that the documented call can actually be made.

Note that this is the case for other calls as well, such as
`bpy.data.file_path_map()`. As such, I don't want to address this in
this commit; this is just for making the docstring reflect the optional
nature of the parameters.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/144933
2025-08-25 11:53:23 +02:00
Campbell Barton
e964f078b5 PyDoc: correct use of back ticks for literal text 2025-08-22 15:10:29 +10:00
Campbell Barton
78c9d16919 PyDoc: correct types, consistent formatting for doc-strings in C++
Correct some types, ensure multi-line docs end with a newline,
sentences end with a full stop.
2025-08-22 14:05:28 +10:00
Andrej730
e41fdebf3a PyDoc: UILayout.introspect(), add missing return value type
Ref !143353
2025-08-22 03:42:34 +00:00
Sybren A. Stüvel
f5ba4dbfe6 Python: Fix parameter name in error message from bpy.data.file_path_map()
When `bpy.data.file_path_map(subset=X)` is called, where `X` has the
wrong type, it now correctly shows `subset` as the erroneous parameter.

Pull Request: https://projects.blender.org/blender/blender/pulls/144914
2025-08-21 14:11:26 +02:00
Bastien Montagne
27a613d9ea Fix: BPY props: broken custom set function for strings.
Another dummy mistake in BPY accessors refactor from yesterday (134d66201a)...
We critically need more unittests in this area!
2025-08-20 12:48:47 +02:00
Campbell Barton
b8ce7d419e Cleanup: use PyErr_SetString when formatting isn't needed 2025-08-20 16:10:54 +10:00
Bastien Montagne
59201ddc28 BPY props: Fix own mistake in recent refactor.
New code from 134d66201a was using uninitialized variable. Not sure how
I missed the compiler warning... :(
2025-08-19 17:49:46 +02:00
Bastien Montagne
134d66201a Cleanup: BPY prop: Move get/set... py callbacks into own scope.
Moving the python call itself into a dedicated sub-scope allows to
ensure local variables (arguments) do not risk leaking into the
rest of the code after being released.

Also use helper macro `PyTuple_SET_ITEMS`.

Pull Request: https://projects.blender.org/blender/blender/pulls/144798
2025-08-19 17:16:31 +02:00
clankill3r
72bda4eaee PyDoc: added missing screen parameter
Ref !144452
2025-08-12 22:42:03 +00:00
Jesse Yurkovich
0240a1f32f Cleanup: CMake: Modernize bf_intern_openvdb dependencies
This follows the other CMake "modernization" commits, this time for
`bf_intern_openvdb` and the OpenVDB dependency itself.

The difference with this one is that `intern/openvdb` becomes an
"optional" dependency itself. This is because downstream consumers often
want to include this dependency rather than openvdb directly, so this
target must also be optional. Optional, in this case, means the target
always exists but may be entirely empty.

Summary
- If you are using BKE APIs to access openvdb features, then use the
  `bf::blenkernel` target
- If you are only using `intern/openvdb` APIs then use the
  `bf::intern::optional::openvdb` target (rare)
- For all other cases, use the `bf::dependencies::optional::openvdb`
  target (rare)

context: https://devtalk.blender.org/t/cmake-cleanup/30260
Pull Request: https://projects.blender.org/blender/blender/pulls/137071
2025-08-12 21:26:38 +02:00
Damien Picard
a166db31a9 Fix #144306: I18n: Wrong values in bpy.app.translations.locales
Commit 798f85a710 changed the way the languages menu is generated in
order to improve the items' descriptions. This revealed that items in
`bpy.app.translations.locales` used this description instead of the
identifier, resulting in them looking like:

  'Locale code: ca_AD. Translation progress: 100%'

instead of:

  'ca_AD'

To use the language code, this commit uses the menu item's identifier
instead of description.

-----

This should be backported to 4.5.

Pull Request: https://projects.blender.org/blender/blender/pulls/144366
2025-08-12 15:02:47 +02:00
Campbell Barton
f96a73961a Cleanup: avoid "nullptr" in Python strings & error messages
This is a C++ term not expected in exceptions and messages.
2025-08-12 13:32:41 +10:00
Brecht Van Lommel
1ebefb8252 Refactor: Logging: Use CLOG for video and ffmpeg
The --debug-ffmpeg flag now is the same as --log video, and only exists for
backwards compatibility. The ffmpeg verbosity can now be controlled with
--log-level.

Pull Request: https://projects.blender.org/blender/blender/pulls/143447
2025-08-11 14:07:45 +02:00
Campbell Barton
ce3998ffea Refactor: simplify "_bpy_types" initialization internals
- Store the `_bpy_types` dictionary on startup instead of
  importing and setting on demand.

- Remove duplicate `_bpy_types` import.
2025-08-10 03:48:48 +00:00
Campbell Barton
eb2cc80cd0 PyAPI: move bpy_types.py to a private module
Use an underscore prefix as this module should not be accessed directly.
2025-08-10 13:45:40 +10:00
Campbell Barton
062fcd00d1 Cleanup: improve confusing/incomplete code-comments 2025-08-08 16:41:38 +10:00
Campbell Barton
28e9e87786 PyDoc: add missing arguments to bpy.app.handlers 2025-08-08 08:47:41 +10:00
Campbell Barton
53cae68ee8 Cleanup: hyphenate the term data-blocks in strings/doc-strings 2025-08-08 08:47:13 +10:00
Campbell Barton
08cf60c66e PyDoc: generate a list of types that support custom properties
Methods for `bpy_struct` such as `get()` & `items()` noted that only
some types support custom-properties.

Since these docs were written many more types support custom properties.
Replace the inline list with a link to a generated list since there are
now too many to include inline.

Resolves #141450.
2025-08-07 14:37:38 +10:00
Campbell Barton
558d1c4774 Cleanup: use the suffix "_maxncpy" instead of "_len" for string sizes
The term "_len" is too easily confused with the strlen(),
excluding the nil byte.
2025-08-07 06:18:21 +10:00
Damien Picard
5998795aa6 UI: Replace contractions with long-form text
Avoid using contractions for can't, aren't, doesn't, and shouldn't.
Following the writing style guide in the Human Interface Guidelines.

Pull Request: https://projects.blender.org/blender/blender/pulls/143852
2025-08-05 11:16:22 +02:00
Campbell Barton
9d449ffcba Build: unbreak WITH_PYTHON_MODULE=ON
Caused by 9f056204e5.
2025-08-05 12:08:24 +10:00
Campbell Barton
6d899a6726 Cleanup: naming & reduce declaration scope in the PyAPI for lib loading
Use terms source/destination instead of from/to.
2025-08-02 02:10:59 +00:00
Campbell Barton
58c7bb3fc7 Cleanup: minor corrections to library loading logic, improve docs
- Share the initialization size for library dictionaries &
  assert this size is up to date.
- Improve doc strings.
2025-08-02 12:05:13 +10:00
Campbell Barton
c04310d69f Fix memory leak when loading libraries fails from Python 2025-08-01 13:40:56 +10:00
Miguel Pozo
0730d3f256 Fix: Python API: bpy.app.is_job_running('SHADER_COMPILATION')
Shader compilation no longer uses the `WM_job` API.
Add a `GPU_shader_batch_is_compiling` function to query if there's any
shader compilation happening, and update `bpy_app_is_job_running` to
handle this as a special case.

Pull Request: https://projects.blender.org/blender/blender/pulls/143559
2025-07-31 20:06:27 +02:00
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