Cleanup: various warnings from pylint for extensions & addons

This commit is contained in:
Campbell Barton
2024-06-08 23:33:45 +10:00
parent 5f06d3aa17
commit b0232b4e0e
12 changed files with 75 additions and 79 deletions
+1 -1
View File
@@ -499,7 +499,7 @@ def cli_extension(argv):
class BlExtDummyGroup(bpy.types.PropertyGroup):
"""Dummy"""
# Dummy.
pass
+13 -12
View File
@@ -57,9 +57,10 @@ if show_color:
}
def colorize(text: str, color: str) -> str:
return (color_codes[color] + text + color_codes["normal"])
return color_codes[color] + text + color_codes["normal"]
else:
def colorize(text: str, color: str) -> str:
_ = color
return text
# -----------------------------------------------------------------------------
@@ -136,7 +137,7 @@ class subcmd_utils:
errors.append("Malformed package name \"{:s}\", expected \"repo_id.pkg_id\"!".format(pkg_id_full))
continue
if repo_id:
repo_index, repo_packages = repo_map.get(repo_id, (-1, ()))
repo_index, _repo_packages = repo_map.get(repo_id, (-1, ()))
if repo_index == -1:
errors.append("Repository \"{:s}\" not found in [{:s}]!".format(
repo_id,
@@ -145,7 +146,7 @@ class subcmd_utils:
continue
else:
repo_index = -1
for repo_id_iter, (repo_index_iter, repo_packages_iter) in repo_map.items():
for _repo_id_iter, (repo_index_iter, repo_packages_iter) in repo_map.items():
if pkg_id in repo_packages_iter:
repo_index = repo_index_iter
break
@@ -408,7 +409,7 @@ class subcmd_repo:
def add(
*,
name: str,
id: str,
repo_id: str,
directory: str,
url: str,
cache: bool,
@@ -424,7 +425,7 @@ class subcmd_repo:
repo = extension_repos.new(
name=name,
module=id,
module=repo_id,
custom_directory=directory,
remote_url=url,
)
@@ -438,21 +439,21 @@ class subcmd_repo:
@staticmethod
def remove(
*,
id: str,
repo_id: str,
no_prefs: bool,
) -> bool:
from bpy import context
extension_repos = context.preferences.extensions.repos
extension_repos_module_map = {repo.module: repo for repo in extension_repos}
repo = extension_repos_module_map.get(id)
repo = extension_repos_module_map.get(repo_id)
if repo is None:
sys.stderr.write("Repository: \"{:s}\" not found in [{:s}]\n".format(
id,
repo_id,
", ".join(["\"{:s}\"".format(x) for x in sorted(extension_repos_module_map.keys())])
))
return False
extension_repos.remove(repo)
print("Removed repo \"{:s}\"".format(id))
print("Removed repo \"{:s}\"".format(repo_id))
if not no_prefs:
blender_preferences_write()
@@ -547,7 +548,7 @@ def generic_arg_repo_id(subparse: argparse.ArgumentParser) -> None:
def generic_arg_package_repo_id_positional(subparse: argparse.ArgumentParser) -> None:
subparse.add_argument(
dest="id",
dest="repo_id",
metavar="ID",
type=str,
help=(
@@ -771,7 +772,7 @@ def cli_extension_args_repo_add(subparsers: "argparse._SubParsersAction[argparse
subparse.set_defaults(
func=lambda args: subcmd_repo.add(
id=args.id,
repo_id=args.repo_id,
name=args.name,
directory=args.directory,
url=args.url,
@@ -797,7 +798,7 @@ def cli_extension_args_repo_remove(subparsers: "argparse._SubParsersAction[argpa
subparse.set_defaults(
func=lambda args: subcmd_repo.remove(
id=args.id,
repo_id=args.repo_id,
no_prefs=args.no_prefs,
),
)
@@ -364,7 +364,7 @@ class NotifyHandle:
_notify_queue = []
def _ui_refresh_apply(*, notify):
def _ui_refresh_apply():
# Ensure the preferences are redrawn when the update is complete.
if bpy.context.preferences.active_section == 'EXTENSIONS':
for wm in bpy.data.window_managers:
@@ -407,7 +407,7 @@ def _ui_refresh_timer():
# If the generator exited, either step to the next action or early exit here.
if sync_info is ...:
_ui_refresh_apply(notify=notify)
_ui_refresh_apply()
if len(_notify_queue) <= 1:
# Keep `_notify_queuy[0]` because we may want to keep accessing the text even when updates are complete.
if wm.extensions_updates == WM_EXTENSIONS_UPDATE_CHECKING:
@@ -418,7 +418,7 @@ def _ui_refresh_timer():
return default_wait
# TODO: redraw the status bar.
_ui_refresh_apply(notify=notify)
_ui_refresh_apply()
update_count = notify.updates_count()
if update_count != wm.extensions_updates:
+20 -21
View File
@@ -85,7 +85,7 @@ def rna_prop_repo_enum_local_only_itemf(_self, context):
for repo_item in repo_iter_valid_local_only(context, exclude_system=True)
]
# Prevent the strings from being freed.
rna_prop_repo_enum_local_only_itemf._result = result
rna_prop_repo_enum_local_only_itemf.result = result
return result
@@ -974,7 +974,7 @@ def _extensions_maybe_online_action_poll_impl(cls, repo, action_text):
return False
repos_all = extension_repos_read(use_active_only=False)
if not len(repos_all):
if not repos_all:
cls.poll_message_set("No repositories available")
return False
@@ -1153,7 +1153,7 @@ class EXTENSIONS_OT_repo_sync_all(Operator, _ExtCmdMixIn):
return _extensions_maybe_online_action_poll_impl(cls, repo, "check for updates")
@classmethod
def description(cls, context, props):
def description(cls, _context, props):
if props.use_active_only:
return "Refresh the list of extensions for the active repository"
return "" # Default.
@@ -1252,7 +1252,7 @@ class EXTENSIONS_OT_package_upgrade_all(Operator, _ExtCmdMixIn):
return _extensions_maybe_online_action_poll_impl(cls, repo, "install updates")
@classmethod
def description(cls, context, props):
def description(cls, _context, props):
if props.use_active_only:
return "Upgrade all the extensions to their latest version for the active repository"
return "" # Default.
@@ -1845,9 +1845,11 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
def draw(self, context):
if self._drop_variables is not None:
return self._draw_for_drop(context)
self._draw_for_drop(context)
return
elif self._legacy_drop is not None:
return self._draw_for_legacy_drop(context)
self._draw_for_legacy_drop(context)
return
# Override draw because the repository names may be over-long and not fit well in the UI.
# Show the text & repository names in two separate rows.
@@ -1873,7 +1875,7 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
body.prop(self, "target", text="Target Path")
body.prop(self, "overwrite", text="Overwrite")
def _invoke_for_drop(self, context, event):
def _invoke_for_drop(self, context, _event):
# Drop logic.
print("DROP FILE:", self.url)
@@ -1893,7 +1895,6 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
self._drop_variables = True
self._legacy_drop = None
from .bl_extension_ops import repo_iter_valid_local_only
from .bl_extension_utils import pkg_manifest_dict_from_file_or_error
if not list(repo_iter_valid_local_only(context, exclude_system=True)):
@@ -1922,7 +1923,7 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
return {'RUNNING_MODAL'}
def _draw_for_drop(self, context):
def _draw_for_drop(self, _context):
layout = self.layout
layout.operator_context = 'EXEC_DEFAULT'
@@ -1934,7 +1935,7 @@ class EXTENSIONS_OT_package_install_files(Operator, _ExtCmdMixIn):
layout.prop(self, "enable_on_install", text=rna_prop_enable_on_install_type_map[pkg_type])
def _draw_for_legacy_drop(self, context):
def _draw_for_legacy_drop(self, _context):
layout = self.layout
layout.operator_context = 'EXEC_DEFAULT'
@@ -1972,7 +1973,7 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn):
)
@classmethod
def poll(cls, context):
def poll(cls, _context):
if not bpy.app.online_access:
if bpy.app.online_access_override:
cls.poll_message_set(
@@ -2094,7 +2095,7 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn):
return self.execute(context)
def _invoke_for_drop(self, context, event):
def _invoke_for_drop(self, context, _event):
from .bl_extension_utils import url_parse_for_blender
url = self.url
@@ -2132,15 +2133,15 @@ class EXTENSIONS_OT_package_install(Operator, _ExtCmdMixIn):
def draw(self, context):
if self._drop_variables is not None:
return self._draw_for_drop(context)
self._draw_for_drop(context)
def _draw_for_drop(self, context):
def _draw_for_drop(self, _context):
from .bl_extension_ui import (
size_as_fmt_string,
)
layout = self.layout
repo_index, repo_name, pkg_id, item_remote = self._drop_variables
_repo_index, repo_name, pkg_id, item_remote = self._drop_variables
layout.label(text="Do you want to install the following {:s}?".format(item_remote["type"]))
@@ -2273,12 +2274,12 @@ class EXTENSIONS_OT_package_uninstall_system(Operator):
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, contest):
def poll(cls, _contest):
cls.poll_message_set("System extensions are read-only and cannot be uninstalled")
return False
@classmethod
def description(cls, context, props):
def description(cls, _context, _props):
return EXTENSIONS_OT_package_uninstall.__doc__
def execute(self, _context):
@@ -2303,8 +2304,7 @@ class EXTENSIONS_OT_package_theme_enable(Operator):
pkg_id: rna_prop_pkg_id
repo_index: rna_prop_repo_index
def execute(self, context):
self.repo_index
def execute(self, _context):
repo_item = extension_repos_read_index(self.repo_index)
extension_theme_enable(repo_item.directory, self.pkg_id)
print(repo_item.directory, self.pkg_id)
@@ -2320,7 +2320,6 @@ class EXTENSIONS_OT_package_theme_disable(Operator):
repo_index: rna_prop_repo_index
def execute(self, context):
import os
repo_item = extension_repos_read_index(self.repo_index)
dirpath = os.path.join(repo_item.directory, self.pkg_id)
if os.path.samefile(dirpath, os.path.dirname(context.preferences.themes[0].filepath)):
@@ -2574,7 +2573,7 @@ class EXTENSIONS_OT_userpref_show_online(Operator):
bl_options = {'INTERNAL'}
@classmethod
def poll(cls, context):
def poll(cls, _context):
if bpy.app.online_access_override:
if not bpy.app.online_access:
cls.poll_message_set("Blender was launched in offline-mode which cannot be changed at runtime")
+16 -21
View File
@@ -315,7 +315,7 @@ class notify_info:
_update_state = None
@staticmethod
def update_ensure(context, repos):
def update_ensure(repos):
"""
Ensure updates are triggered if the preferences display extensions
and an online sync has not yet run.
@@ -387,6 +387,10 @@ def extensions_panel_draw_online_extensions_request_impl(
row.operator("extensions.userpref_allow_online", text="Allow Online Access", icon='CHECKMARK')
extensions_map_from_legacy_addons = None
extensions_map_from_legacy_addons_url = None
# NOTE: this can be removed once upgrading from 4.1 is no longer relevant.
def extensions_map_from_legacy_addons_ensure():
import os
@@ -411,10 +415,6 @@ def extensions_map_from_legacy_addons_reverse_lookup(pkg_id):
return ""
extensions_map_from_legacy_addons = None
extensions_map_from_legacy_addons_url = None
# NOTE: this can be removed once upgrading from 4.1 is no longer relevant.
def extensions_panel_draw_missing_with_extension_impl(
*,
@@ -444,7 +444,6 @@ def extensions_panel_draw_missing_with_extension_impl(
box = layout_panel.box()
box.label(text="Add-ons previously shipped with Blender are now available from extensions.blender.org.")
can_install = True
if repo is None:
# Most likely the user manually removed this.
@@ -563,7 +562,7 @@ def extensions_panel_draw_impl(
repos_all = extension_repos_read()
if bpy.app.online_access:
if notify_info.update_ensure(context, repos_all):
if notify_info.update_ensure(repos_all):
# TODO: should be part of the status bar.
from .bl_extension_notify import update_ui_text
text, icon = update_ui_text()
@@ -576,7 +575,7 @@ def extensions_panel_draw_impl(
show_themes = filter_by_type in {"", "theme"}
if show_addons:
used_addon_module_name_map = {addon.module: addon for addon in prefs.addons}
addon_modules = [mod for mod in addon_utils.modules(refresh=False)]
addon_modules = addon_utils.modules(refresh=False)
if show_themes:
active_theme_info = pkg_repo_and_id_from_theme_path(repos_all, prefs.themes[0].filepath)
@@ -627,20 +626,16 @@ def extensions_panel_draw_impl(
local_ex = None
continue
repo = repos_all[repo_index]
has_remote = (repo.remote_url != "")
del repo
if pkg_manifest_remote is None:
repo = repos_all[repo_index]
has_remote = (repo.remote_url != "")
if has_remote:
# NOTE: it would be nice to detect when the repository ran sync and it failed.
# This isn't such an important distinction though, the main thing users should be aware of
# is that a "sync" is required.
errors_on_draw.append("Repository: \"{:s}\" must sync with the remote repository.".format(repo.name))
del repo
continue
else:
repo = repos_all[repo_index]
has_remote = (repo.remote_url != "")
del repo
# Read-only.
is_system_repo = repos_all[repo_index].source == 'SYSTEM'
@@ -971,9 +966,9 @@ class USERPREF_PT_extensions_tags(Panel):
bl_region_type = 'HEADER'
bl_ui_units_x = 13
def draw(self, context):
def draw(self, _context):
# Extended by the `bl_pkg` add-on.
layout = self.layout
pass
class USERPREF_MT_extensions_settings(Menu):
@@ -1148,7 +1143,7 @@ def tags_current(wm):
if filter_by_type == "add-on":
# Legacy add-on categories as tags.
import addon_utils
addon_modules = [mod for mod in addon_utils.modules(refresh=False)]
addon_modules = addon_utils.modules(refresh=False)
for mod in addon_modules:
module_name = mod.__name__
is_extension = addon_utils.check_extension(module_name)
@@ -1183,14 +1178,14 @@ def tags_refresh(wm):
for tag in tags_to_add:
tags_idprop[tag] = True
return tags_idprop, list(sorted(tags_next))
return list(sorted(tags_next))
def tags_panel_draw(panel, context):
from bpy.utils import escape_identifier
layout = panel.layout
wm = context.window_manager
tags_idprop, tags_sorted = tags_refresh(wm)
tags_sorted = tags_refresh(wm)
layout.label(text="Show Tags")
# Add one so the first row is longer in the case of an odd number.
tags_len_half = (len(tags_sorted) + 1) // 2
@@ -1202,7 +1197,7 @@ def tags_panel_draw(panel, context):
col.prop(wm.extension_tags, "[\"{:s}\"]".format(escape_identifier(t)))
def extensions_repo_active_draw(self, context):
def extensions_repo_active_draw(self, _context):
# Draw icon buttons on the right hand side of the UI-list.
from . import repo_active_or_none
layout = self.layout
@@ -171,8 +171,7 @@ def file_mtime_or_none(filepath: str) -> Optional[int]:
def scandir_with_demoted_errors(path: str) -> Generator[os.DirEntry[str], None, None]:
try:
for entry in os.scandir(path):
yield entry
yield from os.scandir(path)
except Exception as ex:
print("Error: scandir", ex)
@@ -121,7 +121,7 @@ def debug_stack_trace_to_file() -> None:
"""
import inspect
stack = inspect.stack(context=1)
with open("/tmp/out.txt", "w") as fh:
with open("/tmp/out.txt", "w", encoding="utf-8") as fh:
for frame_info in stack[1:]:
fh.write("{:s}:{:d}: {:s}\n".format(
frame_info.filename,
@@ -1877,8 +1877,9 @@ def url_is_filesystem(url: str) -> bool:
if url.startswith(URL_KNOWN_PREFIX):
return False
# Argument parsing must ensure this never happens.
raise ValueError("prefix not known")
# Error handling must ensure this never happens.
assert False, "unreachable, prefix not known"
return False
@@ -143,11 +143,12 @@ def generate_from_source(
},
)
# Example usage:
if __name__ == "__main__":
filename, data = generate_from_source(
module_name="blender_example_module",
version="0.0.1",
source="print(\"Hello World\")"
)
print(filename, len(data))
# if __name__ == "__main__":
# filename, data = generate_from_source(
# module_name="blender_example_module",
# version="0.0.1",
# source="print(\"Hello World\")"
# )
# print(filename, len(data))
@@ -458,7 +458,7 @@ class TestSimple(TestWithTempBlenderUser_MixIn, unittest.TestCase):
)
)
returncode, stdout, stderr = run_blender((
returncode, stdout, _stderr = run_blender((
"-b",
"--python-expr",
# Return an `exitcode` of 64 if the module exists.
@@ -45,10 +45,10 @@ class TestPathMatch_MixIn:
if not isinstance(path_pattern, PathPatternMatch):
path_pattern = PathPatternMatch(path_pattern)
assert hasattr(path_pattern, "test_path")
for success_expected, path in expected_paths:
for _success_expected, path in expected_paths:
success_actual = path_pattern.test_path(path)
if False:
self.assertEqual(success_actual, success_expected)
# Un-comment to pin-point the exact error.
# `self.assertEqual(success_actual, success_expected)`
result.append((success_actual, path))
return result
+3 -3
View File
@@ -10,7 +10,7 @@ This module takes wheels and applies them to a "managed" destination directory.
"""
__all__ = (
"apply_action"
"apply_action",
)
import os
@@ -46,7 +46,7 @@ def _wheels_from_dir(dirpath: str) -> Tuple[
# The values are:
# Top level directories.
Dict[str, List[str]],
# Unknown path.s
# Unknown paths.
List[str],
]:
result: Dict[str, List[str]] = {}
@@ -298,7 +298,7 @@ def apply_action(
# Recursively removing all paths on the users system can be considered relatively risky
# even if this is located in a known location under the users home directory - better avoid.
# So build a list of wheel paths and only remove the unused paths from this list.
wheels_installed, paths_unknown = _wheels_from_dir(local_dir_site_packages)
wheels_installed, _paths_unknown = _wheels_from_dir(local_dir_site_packages)
# Wheels and their top level directories (which would be installed).
wheels_packages: Dict[str, List[str]] = {}
+2 -2
View File
@@ -2390,8 +2390,8 @@ class USERPREF_PT_addons(AddOnPanel, Panel):
if p
)
# collect the categories that can be filtered on
addon_modules = [mod for mod in addon_utils.modules(refresh=False)]
# Collect the categories that can be filtered on.
addon_modules = addon_utils.modules(refresh=False)
self._draw_addon_header(layout, prefs, wm)