46 Commits

Author SHA1 Message Date
Campbell Barton
744819cf9b Addons: only ever check "addons_core" for bundled add-ons
Avoid checking every scripts directory for add-ons core,
as creating this directory would cause "addons" to be ignored.
2024-05-16 15:06:10 +10:00
Campbell Barton
ecec9de4e6 Cleanup: remove internal argument to override the support level
This was only ever used for addons_contrib which has been removed.
2024-05-16 09:03:16 +10:00
Campbell Barton
c4a0bbb1f4 Extensions: Support online extensions and move add-ons outside Blender
The extensions system allows to extend Blender with connectivity to the internet. Right now it means Blender can
discover and install add-ons and themes directly from the internet, and notify users about their updates.

By default this is disabled (opt-in), and users can enable it the first time they try to install an extension or visit
the Prefences > Extensions tab. If this is enabled, Blender will automatically check for updates for
extensions.blender.org upon startup.

When will Blender access the remote repositories:

* Every time you open the Preferences → Extensions: ALL the enabled repositories get checked for the latest info (json)
* Every time you try to install by dragging: ALL the enabled repositories get checked for the latest info (json).
* Every time you start Blender: selected repositories get checked for the latest info (json).

------------------

From the Blender code point of view, this means that most of the add-ons and themes originally bundled with Blender
will now be available from the online platform, instead of bundled with Blender. The exception are add-ons which are
deemed core functionality which just happened to be written as Python add-ons.

Links:
* Original Extenesions Platform Announcement: https://code.blender.org/2022/10/blender-extensions-platform/
* Extensions website: https://extensions.blender.org/
* User Manual: https://docs.blender.org/manual/en/4.2/extensions/index.html#extensions-index
* Technical specifications: https://developer.blender.org/docs/features/extensions/
* Changes on add-ons bundling: https://devtalk.blender.org/t/changes-to-add-on-bundling-4-2-onwards/34593

------------------

This PR does the following:

* Move extensions out of experimental.
* No longer install `scripts/addons` & `scripts/addons_contrib`.
* Add `scripts/addons_core` to blender's repository.

These add-ons will still be bundled with Blender and will be always enabled in the future, with their preferences
moved to be more closely integrated with the rest of Blender. This will happen during the remaining bcon2 period.
For more details, see #121830

From scripts/addons:

* copy_global_transform.py
* hydra_storm
* io_anim_bvh
* io_curve_svg
* io_mesh_uv_layout
* io_scene_fbx
* io_scene_gltf2
* pose_library
* ui_translate
* viewport_vr_preview

Extra: bl_pkg (scripts/addons_contrib)

Note: The STL (legacy) add-on is going to be moved to the extensions platform. There is already a C++ version on core
which is enabled by default.

All the other add-ons are already available at extensions.blender.org. To use them you need to:

* Go to User Preferences > Extensions
* You will be greated with an "Online Extensions" message, click on "Enable Repository".
* Search the add-on you are looking for (e.g, Import Images as Planes).
* Click on Install

Over time their maintaince will be transferred over to the community so their development can carry on. If you used to
help maintain a bundled add-on please read: https://devtalk.blender.org/t/changes-to-add-on-bundling-4-2-onwards/34593

Ref: !121825
2024-05-15 19:26:29 +02:00
Campbell Barton
2c47937a96 Extensions: add Preferences.extensions
Accessing extensions options in preferences.filepaths didn't make so
much sense.
2024-05-15 00:52:23 +10:00
YimingWu
c324c19765 Fix #121021: Avoid size change of addon_modules during iteration
Copy modules before filtering `addon_modules` to avoid
change of dictionnary size during iterations. Otherwise errors
can be triggerd when running `python -m pytest test.py` since
it may modify the module dict.

Co-authored-by: Alexis-19 <alexis-19@noreply.localhost>
Pull Request: https://projects.blender.org/blender/blender/pulls/121100
2024-05-11 08:58:20 +02:00
Campbell Barton
3d84a1170f Extensions: ensure extensions "site-packages" precede Python's
Ensure extensions modules aren't overridden to the systems modules.
Without this, installing a system module could break an extension.
2024-05-08 21:32:16 +10:00
Campbell Barton
95fcffed4a Cleanup: remove debug print 2024-05-03 23:23:35 +10:00
Campbell Barton
0a17f4a711 Extensions: add an extensions-local site-packages
This will be used as the destination location for wheels.
Currently this is only added to the `sys.path` if it already exists.
2024-05-02 12:49:02 +10: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
429959e268 UI: always report to the user when an add-ons fail to load
Failure to import the module would print a message but not show
any feedback to the user - failing silently.
2024-03-21 16:57:31 +11:00
Campbell Barton
3cb687c32c addon_utils: show a useful error when loading a module without a file
When loading an add-on without a __file__ set the "cause" was empty.

Now the modules __path__ is included (when available) which points
to the path that failed to load to help with troubleshooting.
2024-03-21 16:54:15 +11:00
Campbell Barton
16919ea5f2 Fix addon_utils.enable() error when the module has no __file__
Although this error isn't specific to extensions, extensions containing
a blender_manifest.toml but no __init__.py would import a module
with the __file__ set to None.
While there is logic to handle this case, it didn't account for modules
already in sys.modules with __file__ set to None.

From a user perspective enabling the extension silently failed raising
an error on the second attempt to enable.
2024-03-21 16:54:15 +11:00
Campbell Barton
0b13d1f31a Extensions: suppress noisy "bl_info" prints unless --debug-python is set
Ref !119521
2024-03-20 15:43:40 +11:00
Campbell Barton
4ed06c648d Fix #119664: Persistent state not set when disabling add-ons
The wrong persistent attribute was set when disabling an add-on,
also correct the message when disabling an already disabled add-on.
2024-03-20 11:56:25 +11:00
Campbell Barton
adb304f0ed Extensions: improve UI for adding/removing repositories
- Adding new repositories now differentiates between "Online" & "Local"
  where adding a local repository doesn't prompt for a URL.
- Support removing repositories and their files (uses confirmation
  defaulting to "Cancel" to avoid accidents).
- Show an error icon next to repositories that have invalid settings,
  these repositories are now ignored until the settings are corrected,
  required fields are highlighted red when they're unset & required.
- Rename "directory" to "custom_directory" since an automatic path is
  used when not set - created in the users scripts directory.
- Use toggles for custom-directory & remote URL instead of relying on
  the value to be left an empty string for alternative behavior.
2024-02-02 20:46:45 +11:00
Campbell Barton
c9ad858d9d Extensions: update manifest to bl_info conversion
Update extension to bl_info conversion to account for recent changes.
2024-02-01 22:42:24 +11:00
Campbell Barton
fb29925158 Extensions: support addon_utils.module_bl_info() for enabled extensions
Add-ons "bl_info" was supported for add-ons which weren't registered,
however the real modules weren't handled causing module_bl_info()
to return dummy values when an extensions add-ons module was passed in.

This caused the minimum Blender version check after enabling an add-on
to do nothing.

Now the "bl_info" from extension modules is ignored and the bl_info
is created on demand from the manifest.
2024-02-01 17:11:15 +11:00
Campbell Barton
355fd2313d Extensions: detect time-stamp changes to extensions manifest on refresh
- Add a warning when an extensions meta-data is missing.
- Remove the time-stamps from message that time-stamps have changes
  since knowing the exact times isn't helpful.
2024-02-01 17:03:47 +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
fb16dbf9ae Extensions: support authors as a list from the TOML manifest
Also fix blank errors caused by catching assertions which resulted
in empty strings.
2024-01-31 17:43:44 +11:00
Campbell Barton
73214e9b26 Extensions: change the manifest filename
Use the name "blender_manifest.toml" for clarity.
2024-01-30 09:42:01 +11:00
Campbell Barton
8841990764 Extensions: use the TOML manifest as a source for extensions bl_info 2024-01-25 14:36:20 +11:00
Campbell Barton
b686f2a536 UI: show the version as a string for extensions
Extensions use SEMVER, not a tuple of numbers.
2024-01-25 14:36:20 +11:00
Campbell Barton
6aede44fb7 PyAPI: remove checks for add-ons pre 2.8x
This made sense when migrating from 2.7x, now 2.8x add-ons may also
have issues in 4.1 so this check isn't so relevant.
2024-01-25 13:00:48 +11:00
Campbell Barton
b8b1189bc4 Cleanup: assign a variable for the extension module with a trailing "."
This is used in enough places to simplify checks.
2024-01-25 13:00:48 +11:00
Campbell Barton
9cc6ee75e7 Extensions: support using a default local user directory
This is needed so extensions repositories can reference
user-script directories without them having hard-coded paths
which will be invalid when upgrading a Blender version.
2024-01-24 16:50:32 +11:00
Campbell Barton
53a8570aec Extensions: enable the package management add-on when enabled
Package management has been moved into addons_contrib so the addon
can be enabled when enabling extension repositories.

This means users can test extension repositories without having to
install a separate add-on.

Additional work is still needed with the server before this is ready
for general testing though.

Part of #117286.
2024-01-24 13:25:27 +11:00
Campbell Barton
7daf900181 Cleanup: spelling in comments, remote debug print 2024-01-19 17:28:14 +11:00
Campbell Barton
665472a18b Extensions: changes to repositories are now accounted for by add-ons
Add-ons using the extension API now follow changes to their
repositories.

- Removing a repository disables and removes associated add-ons.
- Disabling a repository disables the add-on but keeps add-on &
  its preferences.
- Enabling a repository re-enables add-ons that use it.
- Renaming a repository updates the names of associated add-ons &
  it's preferences.
2024-01-19 17:19:09 +11:00
Campbell Barton
5149aed4ac PyAPI: improve warnings when addons from extensions repos fail to load 2024-01-17 18:30:16 +11:00
Campbell Barton
e87b67398c Extensions: add/remove bl_ext sub-modules when repo.enabled is toggled
This disables any add-ons which are part of the disabled repository.
2023-12-19 18:41:37 +11:00
Campbell Barton
9a75c29bf8 Fix #113206: add-on unregister() not called on exit
Own regression in [0] caused add-ons not to run the unregister function
on exit.

[0]: e1b72e569decd4fdee87eb1ae2b43569d8c6bd26
2023-10-04 16:09:30 +11:00
Campbell Barton
4790c6ac61 addon_utils: don't print a traceback when the add-on isn't found
This was already done for ImportError but missed, ModuleNotFoundError.
2023-09-15 17:23:08 +10:00
Campbell Barton
0c26c84704 Cleanup: spelling in comments 2023-09-05 11:04:27 +10:00
Campbell Barton
e1b72e569d Fix #111649: 3rd party Python modules can cause Python error on exit
Disabling all add-ons on exit could raise exceptions when `sys.modules`
contained modules that ran logic in their `__getattr__` function.

Resolve by accessing the modules name-space directly,
bypassing the `__getattr__` function.
2023-08-30 16:16:24 +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
c61aa42f7d PyAPI: make addon_utils.paths_with_extension_repos an internal function
This is only needed for internal use at the moment, rename to make it
clear it's only for internal use.

Also remove unnecessary variable assignments.
2023-08-09 20:36:31 +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
31cb31d736 PyAPI: add-on name-spacing for extension repositories
Support name-spaced add-ons, exposed via user configurable extension
repositories.

Directories for add-ons can be added at run-time and are name-spaced to
avoid name-collisions with Python modules or add-ons from other
repositories.

This is exposed as an experimental feature "Extension Repositories".

Details:

- A `bUserExtensionRepo` type which represents a repository which is
  listed in the add-ons repository.

- `JunctionModuleHandle` class to manage a package with sub-modules
  which can point to arbitrary locations.

- `bpy.app.handlers._extension_repos_update_{pre/post}` internal
  callbacks run before/after changes to extension repositories,
  callbacks are used to sync the changes to the Python package that
  exposes these to add-ons.

- The size of an add-on name has been increased so a user-defined package
  prefix can be included without enforcing shorter add-on names.

- Functionality relating to package management has been left out of this
  change and will be developed separately.

Further work:

- While a repository can be renamed, enabled add-ons aren't renamed.
  Eventually we might want to support this although we could also
  disallow renaming repositories with add-ons enabled as the name isn't
  all that significant.

- Removing a repository should remove all the add-ons located in this
  repository.

- Sub-module names are currently restricted to `[A-Za-z]+[A-Za-z0-9_]*`
  we might want to relax this to allow unicode characters (we might
  still want to disallow `-` or any characters that would prevent
  attribute access in code).

Ref !110869.

Reviewed By: brecht
2023-08-09 20:24:24 +10:00
Campbell Barton
58e4a7ae2b Cleanup: minor changes for add-on & module listing
Use list-comprehension for addon_utils.paths and other minor changes.
2023-08-07 10:46:45 +10:00
Campbell Barton
53e6803977 Cleanup: check for "BaseException" instead of "Exception"
Prefer the more generic exception type as it's possible exceptions
derive from this and not "Exception".

Also use the name 'ex' for exceptions instead of 'e'.
2023-07-30 16:14:13 +10:00
Campbell Barton
9f5be2a861 Cleanup: quiet pylint warnings using BaseException 2023-07-30 16:14:11 +10:00
Campbell Barton
52109ff7f0 Refactor: out addon_utils fake_module(..) into a top-level function
Even though it's private, it's useful to be able to access this for
prototyping support for scanning addons in other other locations.
2023-07-29 22:20:40 +10:00
Campbell Barton
6ff81c6505 PyAPI: internal changes needed to support sub-modules as add-ons
Apply minor changes needed for an add-on to be a sub-module.
2023-07-29 22:15:11 +10:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Sergey Sharybin
03806d0b67 Re-design of submodules used in blender.git
This commit implements described in the #104573.

The goal is to fix the confusion of the submodule hashes change, which are not
ideal for any of the supported git-module configuration (they are either always
visible causing confusion, or silently staged and committed, also causing
confusion).

This commit replaces submodules with a checkout of addons and addons_contrib,
covered by the .gitignore, and locale and developer tools are moved to the
main repository.

This also changes the paths:
- /release/scripts are moved to the /scripts
- /source/tools are moved to the /tools
- /release/datafiles/locale is moved to /locale

This is done to avoid conflicts when using bisect, and also allow buildbot to
automatically "recover" wgen building older or newer branches/patches.

Running `make update` will initialize the local checkout to the changed
repository configuration.

Another aspect of the change is that the make update will support Github style
of remote organization (origin remote pointing to thy fork, upstream remote
pointing to the upstream blender/blender.git).

Pull Request #104755
2023-02-21 16:39:58 +01:00