51 Commits

Author SHA1 Message Date
Campbell Barton
1216651ca9 PyAPI: make internal modules explicitly "private"
Rename modules in `./scripts/modules/` to use an underscore prefix to
make it clear they aren't intended to be part of public API's. This
also means there is no implication that these modules should be stable,
allowing us to change them based on Blender's internal usage.

The following modules have been marked as private:

- `animsys_refactor`
- `bl_console_utils`
- `bl_i18n_utils`
- `bl_previews_utils`
- `bl_rna_utils`
- `bl_text_utils`
- `bl_ui_utils`
- `bpy_restrict_state`
- `console_python`
- `console_shell`
- `graphviz_export`
- `keyingsets_utils`
- `rna_info`
- `rna_manual_reference`
- `rna_xml`

Note that we could further re-arrange these modules
(under `_bpy_internal` in some cases), this change is mainly to mark
them as private, further changes can be handed on a case-by-case basis.

Ref !147773
2025-10-13 09:35:09 +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
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
Hans Goudey
5747f839e8 Cleanup: Grammar: Fix uses of "it's own" 2025-05-29 14:41:20 -04:00
Andrej730
380e8455e8 PyDoc: Fix typing issues with bpy.utils.register_tool
- Add `type[]` for the `tool_cls` as it's expecting tool type class,
  not the instance (similar to #132420)
- Add `set[str]` to `after` type as it's seems to be the way it's used
  the most widely, e.g. in "UI Tool Simple" example that comes with Blender:

`bpy.utils.register_tool(MyTool, after={"builtin.scale_cage"}, separator=True, group=True)`

Pull Request: https://projects.blender.org/blender/blender/pulls/133975
2025-02-05 07:06:53 +01:00
Brecht Van Lommel
a6b293daac Python Module: Bundle VFX library python bindings
When calling bpy.utils.expose_bundled_modules(), these modules are
added to sys.path.

This provides a solution/workaround to two problems:
* Using bpy together with packages like usd-core is problematic. Besides
  crashing due to C++ symbol conflicts, it's just impossible to import
  different versions of the same module, or to have distinct environment
  variables for both. (#127132)
* Blender add-ons using these VFX modules do not currently work with
  the bpy module.

This adds about 15MB to the bpy package.

Pull Request: https://projects.blender.org/blender/blender/pulls/133082
2025-01-17 10:13:31 +01:00
jlalleve
2feadc623b Core: Environment variables for deployment
* BLENDER_SYSTEM_SCRIPTS support for multiple script paths, separated by
  ; on Windows and : on other platforms.
* New BLENDER_CUSTOM_SPLASH to replace the splash screen image.
* New BLENDER_CUSTOM_SPLASH_BANNER to overlay an image on the splash.

Contributed by Sony Interactive Entertainment: https://github.com/PlayStation-OpenSource
2025-01-14 20:57:31 +01:00
Campbell Barton
444f1064c9 Cleanup: remove unused functions, imports 2025-01-04 21:09:41 +11:00
Campbell Barton
f17379a5d0 Merge branch 'blender-v4.3-release' 2024-11-03 16:07:40 +11:00
Campbell Barton
3bcfb151c1 PyDoc: use Python's type annotation syntax for doc-strings
Replace plain-text type information with the type syntax used
for Python's type annotations as it's more concise, especially for
callbacks which often didn't include useful type information.

Note that this change only applies to inline doc-strings,
generated doc-strings from RNA need to be updated separately.

Details:

- Many minor corrections were made when "list" was incorrectly used
  instead of "sequence".
- Some type information wasn't defined in the doc-strings and has been
  added.
- Verbose type info would benefit from support for type aliases.
2024-11-03 15:44:35 +11:00
Bastien Montagne
1e55d034a1 Fix massive amount of memleaks on exit in BPY.
Essentially, our current code would not properly remove (dereference)
its python objects matching various RNA data created during execution.

Some cases are fairly trivial to understand (like the lack of handling
of unregstering for our 'startup' operators and UI), other were more
subtle (like unregistered PropertyGroups who would remove/free their RNA
struct definition, without releasing first the potential matching python
object).

Co-authored-by: Campbell Barton <campbell@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/128899
2024-10-17 18:05:31 +02:00
Campbell Barton
3e6565b9d7 Merge branch 'blender-v4.3-release' 2024-10-17 15:48:06 +11:00
Campbell Barton
e2862ed7ca Cleanup: rename variables handling modules loaded at startup
The term "global" isn't meaningful in this context,
use "registered" instead.
2024-10-17 15:46:42 +11:00
Campbell Barton
d02c603816 Merge branch 'blender-v4.3-release' 2024-10-17 13:02:19 +11:00
Campbell Barton
6d24201045 Fix error on script reload if the modules aren't found in sys.modules
While unlikely, account for modules loaded on startup not being in
`sys.modules` when reloading scripts.
2024-10-17 12:59:07 +11:00
Campbell Barton
1a1e75c253 Cleanup: replace implicit BaseException with Exception
Exception is more appropriate as a general exception in these cases.
2024-10-08 09:41:51 +11:00
Campbell Barton
9f931ee3d2 Presets: consider presets within the extensions repo to be "built-in"
It was possible to remove a preset defined within an extension,
the only way to restore it was to uninstall & re-install the extension.
2024-08-15 16:06:11 +10:00
Campbell Barton
f42713ab1d Fix unhandled permissions exception in bpy.utils.is_path_builtin
An excepting would be raised when the parent/child paths didn't
have permissions to access.
2024-08-15 16:06:10 +10:00
Campbell Barton
5f9be675f0 Cleanup: move bpy.utils parent-path check into a function 2024-08-15 16:06:08 +10:00
Campbell Barton
2cf09525a7 PyAPI: include bpy.utils.extension_path_user in __all__
This wasn't being included in generated docs.
2024-07-31 09:52:25 +10:00
nutti
e0cdfb8566 Fix: Docstring of the bpy.utils.user_resource argument
Correct argument name is `resource_type`

Pull Request: https://projects.blender.org/blender/blender/pulls/125316
2024-07-29 14:04:41 +02:00
Campbell Barton
fd5780e97b PyAPI: add bpy.utils.register_preset_path utility function
Support add-ons including their own preset paths,
needed to resolve #124020.
2024-07-16 15:50:28 +10:00
Andrej730
1f0592b3b1 Docs: corrections to bpy.utils.register_tool
- Replaced `tool` argument with `tool_cls`.
- Removed `space_type` argument that's not present in the method.

Ref: !118900
2024-07-02 16:18:08 +10:00
Campbell Barton
96906536db Extensions: add a Python API for user editable extension directories
Provide a convenient way to access a writable directory for extensions.
This will typically be accessed via:

  bpy.utils.extension_path_user(__package__, create=True)

This API is provided as some extensions on extensions.blender.org
are writing into the extensions own directory which is error prone:

- The extensions own directory is removed when upgrading.
- Users may not have write access to the extensions directory,
  especially with "System" repositories which may be on shared network
  drives for example.

These directories are only removed when:

- Uninstalling the extension.
- Removing the repository and its files.
2024-06-26 14:23:17 +10:00
Campbell Barton
6450141a18 Fix #122769: bpy.utils.register_submodule_factory fails with extensions
The unregister function from register_submodule_factory didn't support
a sub-module name argument.
2024-06-07 13:42:59 +10:00
Ray Molenkamp
9f1f869e16 make.bat: Enable .py formatting with make format
autopep8_format_paths.py was never wired up in the windows tooling,
this PR wires it up, to get around a 8191 limitation for command
lines on windows an alternative "--no-subprocess" option has been
introduced to call the pep8 module directly from python.

TODO: A subprocess is still used for getting the version information

Contributors:

- @campbellbarton fixes to autopep8_format_paths.py to support
  the -no-subprocess option.

Pull Request: https://projects.blender.org/blender/blender/pulls/120794
2024-06-06 09:10:19 -06:00
Brecht Van Lommel
f7797a90f6 Core: Make BLENDER_SYSTEM_SCRIPTS always add paths
Originally this would replace scripts that come bundled with Blender,
but it's unclear how this is useful.

Searching for this online mainly leads to people asking how they can
use it to add scripts. For example in a studio environment you might
want to deploy add-ons and startup scripts for all users.

Even if you wanted to use it for replacement though, it wasn't really
doing that and inconsistent for different types of scripts:

* startup: ignored
* modules: replaces bundled scripts
* presets: adds to bundled scripts
* addons (in 4.1): ignored
* addons_core (in 4.2): ignored
* startup/bl_app_templates_system: replaces bundled scripts

This change makes it add scripts from this path for all. This is a
breaking change, though arguably this feature was just broken to
begin with and not used much in practice because of that.

The alternative would be add a new set of environment variables to
avoid breaking existing behavior. But that also means keeping around the
broken behavior or fixing it in another way.

Supporting multiple paths may be used too, but for now just support
a single one as doing this for all BLENDER_SYSTEM variables is
non-trivial. The main use case for that would be add-ons anyway, and
those will mainly be handled through upcoming
BLENDER_SYSTEM_EXTENSIONS instead.

Ref #122512

Pull Request: https://projects.blender.org/blender/blender/pulls/122689
2024-06-06 15:28:44 +02:00
Campbell Barton
949dfbfaa8 Cleanup: Python script formatting
- Double quotes for strings.
- Trailing commas when wrapped lines.
2024-06-06 11:26:28 +10:00
Bastien Montagne
b8febd87e1 Fix #121712: outdated mapping between UI translations and Doc languages.
Both lists got heavily out of sync over the years.

Some day would be nice to have this managed in a single place.
2024-05-14 16:53:00 +02:00
Campbell Barton
5088b0154d Cleanup: replace %-formatting with str.format in scripts/modules/
The "bl_i18n_utils" module has been excluded I'm not sure how best
to run it with reasonable code coverage.
2024-04-27 16:06:51 +10:00
Campbell Barton
dd864603f1 Cleanup: minor change to string formatting & __file__
Use __repr__ for formatting file instead of __str__ because non-standard
characters will be escaped and the string will be properly quoted.

Also, a modules __file__ is not *guaranteed* to be a string
(although it almost always is), nevertheless, __repr__ generally
results more more humanly readable results.

Note that __repr__ was already used to format __file__ in most places.
2024-04-27 11:58:02 +10:00
Campbell Barton
44defbd2c7 Extensions: add BLENDER_USER_EXTENSIONS user directory
Replace: `{BLENDER_RESOURCE_PATH_USER}/extensions`
With:    `{BLENDER_USER_EXTENSIONS}`

This follows BLENDER_USER_CONFIG & BLENDER_USER_SCRIPTS conventions.
Reading the environment variable and accessible via
`bpy.utils.user_resource('SCRIPTS')`
2024-03-22 16:08:25 +11:00
Campbell Barton
6bfc8612bf Cleanup: remove BLENDER_USER_AUTOSAVE
This was only used on WIN32 when the temporary directory didn't exist.
When the check was added [0] this made some sense because it relied on
`U.tempdir` existing, since then additional checks have been added to
ensure a temporary directory can be used. Further, this fall-back
location isn't documented in the user manual.

[0]: 615db01b01
2024-03-22 16:08:25 +11:00
Campbell Barton
9372e0dfe0 CLI: support defining custom commands via C++ & Python API
Add support for add-ons to define commands using the new argument
`-c` or `--command`.

Commands behave as follows:

- Passing in a command enables background mode without the need to pass
  in `--background`.
- All arguments following the command are passed to the command
  (without the need to use the `--` argument).
- Add-ons can define their own commands via
  `bpy.utils.register_cli_command` (see examples in API docs).
- Passing in `--command help` lists all available commands.

Ref !119115
2024-03-08 11:10:13 +11:00
Campbell Barton
a8e73616b9 Cleanup: rename add-on related variables for clarity
- Rename info to bl_info, to avoid confusion with extensions manifest,
  which should eventually be accessible in a similar way.
- Rename module_name to addon_module_name to avoid confusion with
  extension repositories name-spaced modules.
- Clarify naming for TOML manifest.
2024-02-01 17:03:40 +11:00
Campbell Barton
06705c5864 PyAPI: support bpy.utils.register_tool without a keyconfig set 2023-12-20 13:05:20 +11:00
Campbell Barton
08e5f94a70 Fix #113309: Broken key-map after "Reload Scripts"
Regression caused by [0]. Resolve by adding a 'keep_properties' argument
to KeyConfig.update so the key-map items can be restored after the
operators have been reloaded.

[0]: 88a875ec3a
2023-10-13 14:37:48 +11:00
Campbell Barton
8d62b7c01c Fix fast-path addon_utils._initialize_once not being used on startup
Changes to initialization from [0] accidentally reverted renaming
_initialize to _initialize_once.

[0] 6de294a191
2023-09-15 17:00:46 +10:00
nutti
e55599c120 Python API: Fix docstring about bpy.utils.load_scripts
Document layout of `bpy.utils.load_scripts` is collapsed due to the invalid format of docstring.
This PR fix it.

Pull Request: https://projects.blender.org/blender/blender/pulls/112127
2023-09-08 14:16:01 +02:00
Campbell Barton
7df693b70d Fix crash loading Blender when the key-configuration fails to load
An error in the key-map could cause the default keymap to be removed
leaving Blender without a default keymap.

Prevent the crash, even though Blender wont be usable in this state.
2023-09-06 14:23:05 +10:00
Campbell Barton
a191e113c4 Cleanup: remove redundant preset lookup loading the default key-config 2023-09-06 14:23:02 +10:00
Campbell Barton
6de294a191 PyAPI: postpone loading add-ons until after key-maps have been defined
Loading add-ons after key-maps resolves a problem where add-ons would
setup shortcuts before Blender had created the key-maps.
Making add-ons have to declare the key-maps using region & window types
matching Blender's internal values.

This PR a pitfall pointed out in #110030.

Ref !110092
2023-09-05 11:35:14 +10:00
Campbell Barton
88a875ec3a Fix #111702: Crash accessing KeyMapItem.properties on script reload 2023-08-31 12:04:30 +10:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Campbell Barton
49f342d742 Cleanup: rename addon_utils._initiazlize to _initiazlize_once
Make it clear this is only intended to be called once.
2023-08-09 20:29:33 +10:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton
c4c1cc7cd3 Cleanup: double quotes for non-enum strings
Also use back-ticks for code-references in comments.
2023-04-18 10:51:32 +10:00
Julian Eisel
ac09d18e4e Fix #106840: Add-ons not loading from custom script directories
`script_paths()` wasn't updated correctly, but that was hidden by some
compabtibility logic that was in the patch earlier. Only with my last
change to the PR before merging it that was removed and the error became
quite visible.
2023-04-12 13:02:31 +02:00
Julian Eisel
ba25023d22 Python: Support multiple custom script directories in Preferences
Makes it possible to select multiple custom script directories in Preferences >
File Paths, replacing the single Scripts path option. Each of these directories
supports the regular script directory layout with a startup file (or files?),
add-ons, modules and presets.
When installing an add-on, the script directory can be chosen.

NOTE: Deprecates the `bpy.types.PreferencesFilePaths.script_directory`
property, and replaces `bpy.utils.script_path_pref` with
`bpy.utils.script_paths_pref`.

Pull Request: https://projects.blender.org/blender/blender/pulls/104876
2023-04-11 15:20:52 +02:00
Hans Goudey
cef82a1d39 Cleanup: Grammar: "it's" vs "its" 2023-03-24 08:34:21 -04:00