Commit Graph

81 Commits

Author SHA1 Message Date
Campbell Barton
f4f50fa2c5 Cleanup: replace typing.Union/Option with logical OR for extensions
Also remove use of deprecated typing.Sequence.
2024-10-18 10:08:12 +11:00
Campbell Barton
a66601ee95 Cleanup: remove deprecated typing built-ins for extension logic
Deprecated since Python 3.9 but still used in many docs/examples.
2024-10-17 19:11:40 +11:00
Campbell Barton
b0fb6a1b2c Fix #128840: extension build asserts when "type" is missing
Building an extension when the manifest didn't define a "type"
would assert instead of reporting the missing field.

Return earlier when there are errors to prevent the assertion.
2024-10-10 23:28:11 +11:00
Campbell Barton
1563ba7e6c Fix #128175: Updating extension can remove the extension on WIN32
On Windows an entire directory may be locked when any files inside it
are opened by another process. This can cause operations that
recursively remove a directory (uninstalling & updating) to fail
with a partially removed extension.

The case of uninstalling was already handled, where failure to remove
a directory would stage the extension for later removal.
In the case of updating however, the user could be left with a broken
(partially removed) extension where some files were removed, as the
directory was locked, the update would fail to extract new files.

Address this issue by renaming the directory before recursive removal.

The following logic has been implemented:

- If any files in the directory are locked, renaming will fail.
  So even though the operation fails the extension is left intact.

- If renaming succeeds, it's possible to apply the update.

  While it's possible (albeit unlikely) recursive removal fails,
  which could be caused by file-system permissions issues corruption or
  a process could open a file between rename & removal.

  In this case the renamed directory is staged for later removal.

Other changes:

- Resolve a related problem where the user could install an
  extension previously staged for removal, now installing an extension
  ensured it's not removed later.

  This would occur if uninstalling failed, the user resolves
  directory-lock, uninstalls again, then re-installs the extension.

- When an extension fails to be removed, don't attempt to remove
  user configuration for that extension.

  Prefer to keep the extension & it's settings in their "current state"
  if it can't be removed.
2024-10-03 12:15:27 +10:00
Campbell Barton
729004390d Cleanup: quiet pylint warnings for extensions 2024-10-01 16:07:05 +10:00
Campbell Barton
22cdf8da1e Extensions: only apply SSL workaround for Python older than 3.12.6
Skip the workaround for versions of Python that contain the fix.
2024-10-01 13:06:05 +10:00
Campbell Barton
54153629f4 Fix #127329: Keyboard interrupt doesn't work from Python 2024-09-11 14:30:51 +10:00
Campbell Barton
805f66c5c4 Extensions: restore fix for removing extensions with symlinks
Regression from [0], removed the fix for #123827.

[0]: 08b75549e3
2024-08-04 20:52:00 +10:00
Campbell Barton
3a88af5402 Fix #125660: Extensions fail to sync HTTPS repositories on WIN32
Workaround: `[ASN1] nested asn1 error` error when making HTTPS
connections on systems with certificates that OpenSSL cannot parse
are installed.

This is a general issue with Python, resolve by applying a proposed
fix [0] to the extensions Python process at run-time.
(this doesn't impact Blender's Python run-time).

The down side is HTTPS connections will only work for extensions
on systems with this problem so this needs to be resolved by Python
long term.

While any changes to Python's SSL checks is worth avoiding,
this simply skips SSL certificates in the windows store that OpenSSL
can't parse instead of failing all SSL connections.

See related issues:

- https://github.com/python/cpython/issues/79846
- https://github.com/openssl/openssl/issues/25023

[0]: https://github.com/python/cpython/pull/91740

Ref !124943.
2024-07-30 22:49:21 +10:00
Campbell Barton
656fe6d3e4 Extensions: support "blocklist" in the remote repository
Support blocking extensions so there is a way for the maintainers of
the remote repository to notify the user if one of their installed
extensions blocked along with a reason for blocking.

Blocked extensions cannot be installed from the preferences or by
dropping a URL.

When an installed & blocked extension is found:

- An icon int the status bar shows an alert,
  clicking on the icon shows the blocked extensions.
- The extensions preferences show a warning.
- The extensions & add-ons UI shows an alert icon
  and "details" section shows the reason.

Details:

- Blocked & installed extensions are shown first in the installed
  extensions panel.
- The internal "install" logic prevents downloading & installing
  blocked extensions.
- Blocked extensions can still be downloaded & installed from disk.
- The "list" command includes an error message if any installed
  extensions are blocked.
- The "server-generate" command can optionally take a configuration
  file that includes the blocklist for the generated JSON.

See design #124954.
2024-07-26 16:05:34 +10:00
Campbell Barton
8019ad8912 Fix unhandled exception for non dictionary items in extensions repo
Ensure items in the repository list are dictionaries.
2024-07-26 11:50:26 +10:00
Campbell Barton
1aa37c8df2 Extensions: require 3 numbers for blender_version_{min/max}
When validating the manifest, require 3 numbers to match the official
extensions web-site which expects this.

See #124885.
2024-07-23 17:06:57 +10:00
Campbell Barton
f3a0ecb4e2 Fix #124885: unable to use manifest with "X.X" blender version
Allow `blender_version_{min/max}` to contain 1..3 numbers.
2024-07-23 14:30:15 +10:00
Campbell Barton
68c2c9cb26 Fix #125142: Legacy add-ons don't install when "bl_info" is first
When "bl_info" was on the first line, the legacy add-on would not
install. Correct the check which would also incorrectly detect legacy
add-ons when "bl_info" wasn't found at all.
2024-07-22 13:03:36 +10:00
Campbell Barton
375b173d67 Extensions: correct help text for the "build" command 2024-07-11 10:18:45 +10:00
Campbell Barton
912194390a Extensions: ensure generated strings in the TOML file are valid
While this wasn't likely to cause any problems in practice,
using the sub-command "build --split-platform" with a platform
containing any characters that need escaping would have produced a TOML
with invalid syntax.

Add a utility function that's guaranteed to create a valid TOML string.
2024-07-09 15:32:09 +10:00
Campbell Barton
9bbf269fe3 Extensions: suppress all pylint warnings & handle add-on errors
- Suppress pylint warnings via comments or be minor changes.
- Any errors disabling add-ons before upgrading or uninstalling are now
  reported to the operators.
- Disable cyclic import warning is it's impractical to resolve.
- Enable useless-suppression warning.
2024-07-08 15:29:27 +10:00
Campbell Barton
05feac04fa Extensions: minor changes to error handling & uninstalling
- Any change that cases validate to fail reports a fatal_error.
- If removing a package fails, attempt to the remove cache.
2024-07-08 13:27:58 +10:00
Campbell Barton
74f8ac15f5 Extensions: "build --split-platform" now includes it's own wheels
The `[build.generated]` section now includes a filtered list of wheels
to simplify checking existing wheels on the server.

Also disallow quotes & control characters in wheel paths because they
already shouldn't be used and doing so would cause escaping issues in
the generated TOML.

Implements #124242.
2024-07-08 12:50:43 +10:00
Campbell Barton
5877efbec3 Extensions: add missing checks for errors in IO, JSON & TOML data
Exceptions need be caught and forwarded so they show it in Blender's
interface. While most common errors where accounted for, various IO
errors & malformed JSON/TOML could cause internal operations to fail
with unhandled exceptions.
2024-07-07 17:43:33 +10:00
Campbell Barton
a53aad6f73 Extensions: refactor message logging into a class
Pass a logging class between functions instead of a function. Has the
advantage that different kinds of messages are exposed as methods.
2024-07-05 20:46:40 +10:00
Campbell Barton
08b75549e3 Extensions: add a new error type "FATAL_ERROR"
Some errors were reported as warnings because they didn't prevent the
operation from completing (such as failing to remove some paths when
uninstalling).

Change message types for the extensions internal command line program:

- Add "fatal error" to use when an operation fails and exits with a
  non-zero error code.
- Use "error" when an operation fails which doesn't prevent other
  actions from succeeding.
- Use "warn" reporting issues what don't prevent the operation
  from completing but may cause problems.
2024-07-05 20:46:40 +10:00
Campbell Barton
e3457bccbf Extensions: sub-commands "build" & "validate" validate manifest tags
Enforce tags from extensions.blender.org with support for using an
alternate set of tags (for other repositories), or no tag validation
at all if the repositories choose not to enforce this.

- By default building & validating an extensions fails when unknown
  tags are used.

- The option `--valid-tags`` has been added which can either:

  - Reference a JSON file which lists valid tags per extension type.
  - Pass in an empty string to disable tag validation.

Default to constraining packages to use Blender's official tags as every
extension defining their own tags is likely to result in many similar
tags & a bad user experience. Details in code-comments.

Implements #123986.
2024-07-04 11:56:07 +10:00
Campbell Barton
33fb83ae74 Fix using network shares for extensions on WIN32
- Support UNC paths.
- Normalize URL's to account for differences between browsers.
2024-07-02 12:53:00 +10:00
Campbell Barton
603b833fe3 Fix error accessing remote extension repositories via file:// on WIN32
Converting the URL back to a path left a slash before the drive letter.
2024-07-02 09:27:59 +10:00
Campbell Barton
0255be9b22 Fix invalid repository paths from generated HTML
The "repository" in links from the generated HTML was only valid when
the URL did not contain a path component.
Resolve by supporting relative "repository".

This simplifies referencing the JSON from a generated HTML since
a relative link doesn't need to know the repositories absolute URL
to the destination.
2024-07-01 23:33:09 +10:00
Campbell Barton
c2326a1639 Fix #123677: Incompatible extensions can be installed from disk 2024-07-01 22:57:38 +10:00
Campbell Barton
7bd846ce0a Fix error including platforms in extensions HTML output 2024-07-01 22:08:34 +10:00
Campbell Barton
75f500ad02 Fix #123923: regression un-installing an extension
Regression in [0] which used an argument only available in Python 3.12.

[0]: 37ae9d5fc4
2024-07-01 16:37:54 +10:00
Campbell Barton
0c54c347d8 Extensions: correct missing return
Harmless but mypy warns about this.
2024-07-01 15:57:42 +10:00
Campbell Barton
2d7b41c8c2 Extensions: Enforce copyright format "YYYY Name" or "YYYY-YYYY Name"
Based on !123846 with additional checks.

Co-authored-by: Mahid Sheikh <standingpad-animations@noreply.localhost>
2024-07-01 15:54:20 +10:00
Campbell Barton
1043b273d5 Extensions: hide the extensions add-on unless debugging extensions 2024-06-28 14:08:56 +10:00
Campbell Barton
37ae9d5fc4 Fix #123827: Extension cannot be uninstalled if symlinked
In the case of user managed files we can't rely on paths to remove
being directories, they could be symbolic links as developers may point
to their own repository. While unlikely the paths to remove could
be files too.

Use a wrapper for shutil.rmtree(..) that handles symlinks & files,
use when removing paths that are expected to be directories from user
managed locations.
2024-06-28 13:40:37 +10:00
Campbell Barton
989de85cf6 Extensions: fixed & refactor internals for extension visibility
Add utility class to check extension visibility to remove
incomplete logic that was duplicated into operator code.
Also minor refactoring to reduce the number of arguments passed
to internal function.s
2024-06-27 14:33:47 +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
17951d12ed Cleanup: correct staticmethod, remove unused imports & formatting 2024-06-26 00:31:59 +10:00
Campbell Barton
84b1c50dc9 Extension: improve server-generate help text 2024-06-23 13:33:02 +10:00
Campbell Barton
6019aa304b Extensions: Improve "server-generate" site, group by type, include links 2024-06-23 12:50:35 +10:00
Campbell Barton
cf73897690 Extensions: add HTML generation to the "server-generate" command
- Optionally generate a simple HTML page (using --html).
- Links include repository, blender_versnon_* & platform information,
  so the information can be used by blender when links are dropped
  into Blender.
- Support using a template as the default HTML is primitive.
2024-06-22 23:48:00 +10:00
Campbell Barton
fc3e0507cc Extensions: development functionality to mark all & clear marks
- Disable enabling on install when installing marked.
  This simplifies installing many packages from a repository which can
  be useful for testing.
- Fix an error installing marked when a local-only package was marked.
2024-06-22 23:03:52 +10:00
Campbell Barton
1ba06956e7 Extensions: support platform & version from URL parameters
Improve errors when dropping incompatible extensions, where previously
the extension would report as being unknown.
2024-06-22 19:13:45 +10:00
Campbell Barton
09be28794a Fix references to undefined modules/variables, remove unused import 2024-06-18 19:21:15 +10:00
Campbell Barton
f98e422e63 Extensions: support build --split-platforms, generated manifest data
- Add an option to build a separate package for each platform, this is
  useful to produce smaller packages when large wheels are included.

- Add a reserved field: "[build.generated]" to the manifest when
  splitting by platform which overrides the root-level platform
  when it exists.
2024-06-18 16:29:57 +10:00
Campbell Barton
e93f0ee53a Extensions: add network timeout and connection limit preferences
These settings are used when running extension updates but may be
used for any operations that perform online access.
2024-06-14 15:32:07 +10:00
Campbell Barton
2dd339bff3 Extensions: quiet warnings from pylint
Some warnings remain which need further investigation.
2024-06-14 15:12:19 +10:00
Campbell Barton
7952f35292 Extensions: filter out extensions by platform and blender version
Exclude extensions which aren't supported by the Blender version or
the platform (for platform dependent extensions).
2024-06-14 15:12:18 +10:00
Campbell Barton
248a5258e0 Extensions: various fixes
- Fix an unhandled exception listing a repository with no remote data.
- Exclude dot-files from being listed when generating a repository.
- Fix missing import (in an unlikely corner case) when accessing
  tags before the repository data was initialized.
- Fix refresh refreshing the remote not updating the
  internal remote meta-data.
- Suppress warnings in tests caused by default repositories
  (now removed before resting).
2024-06-14 15:12:16 +10:00
Campbell Barton
c6680ce7ca Extensions: include the version by default when building packages
Use the `{manifest_id}-{version}.zip` for the generated file
unless an explicit name is given.

Exclude all *.zip files located in the package root.
2024-06-12 22:38:32 +10:00
Campbell Barton
bda9a44785 Extensions: use "v1" version for the generated repository meta-data 2024-06-12 22:38:32 +10:00
Damien Picard
de139dd7e4 UI: Fix and improve a few messages
- "Show the result of running commands in the main interface...": add
  punctuation.
- "Re-Installed" -> "Reinstalled" seems more common.
- "increase_" and "decrease_subdivision" in the Grease Pencil
  modal...: use title case instead of snake case for label.
- "Use a automatic number..." -> "an", typo.
- "... points,{} splines": missing space.
- "End Frame is larger than Start Frame": wrong order in error message.
- "Approximate the object as sphere, which diameter is equal to
  thickness the defined...": grammar.
- "Show Seconds" -> "Use Timecode": this option is not necessarily about
  seconds. Suggested by Pablo Vasquez.
- Brightness and contrast node input descriptions: add missing spaces.
- "Gamma controls the relative intensity... full white.": remove
  trailing ".".

Pull Request: https://projects.blender.org/blender/blender/pulls/122972
2024-06-10 13:26:05 +02:00