From 5c21cf07080c9e176718777a6f48541ef2002897 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 28 May 2024 15:58:48 +0200 Subject: [PATCH 1/3] WIP: Extensions: New status message when checking for update - Sync repo: {remote_url} + Checking repository "{remote_name}" for updates... - Sync downloading remote data + Refreshing extensions list for "{remote_name}"... - sync: invalid manifest ({error_msg}) reading {remote_url}!" + Repository error: invalid manifest ({error_msg}) for repository "{remote_name}"! - Sync complete: {:s}".format(remote_url) + Extensions list for "{remote_name}" updated --- Note, this is working as expected (from Blender anyways), however I can't test test_cli.py at the moment here. --- .../addons_core/bl_pkg/bl_extension_notify.py | 1 + .../addons_core/bl_pkg/bl_extension_ops.py | 2 ++ .../addons_core/bl_pkg/bl_extension_utils.py | 2 ++ scripts/addons_core/bl_pkg/cli/blender_ext.py | 26 ++++++++++++++++--- scripts/addons_core/bl_pkg/tests/test_cli.py | 6 ++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/scripts/addons_core/bl_pkg/bl_extension_notify.py b/scripts/addons_core/bl_pkg/bl_extension_notify.py index ea7578af0cc..93f545acea9 100644 --- a/scripts/addons_core/bl_pkg/bl_extension_notify.py +++ b/scripts/addons_core/bl_pkg/bl_extension_notify.py @@ -168,6 +168,7 @@ def sync_status_generator(repos_notify): cmd_batch_partial.append(partial( bl_extension_utils.repo_sync, directory=repo_item.directory, + remote_name=repo_item.name, remote_url=bl_extension_ops.url_params_append_defaults(repo_item.remote_url), online_user_agent=bl_extension_ops.online_user_agent_from_blender(), access_token=repo_item.access_token if repo_item.use_access_token else "", diff --git a/scripts/addons_core/bl_pkg/bl_extension_ops.py b/scripts/addons_core/bl_pkg/bl_extension_ops.py index f9b02ef4327..45de7f2e476 100644 --- a/scripts/addons_core/bl_pkg/bl_extension_ops.py +++ b/scripts/addons_core/bl_pkg/bl_extension_ops.py @@ -1007,6 +1007,7 @@ class BlPkgRepoSync(Operator, _BlPkgCmdMixIn): partial( bl_extension_utils.repo_sync, directory=directory, + remote_name=repo_item.name, remote_url=url_params_append_defaults(repo_item.remote_url), online_user_agent=online_user_agent_from_blender(), access_token=repo_item.access_token, @@ -1084,6 +1085,7 @@ class BlPkgRepoSyncAll(Operator, _BlPkgCmdMixIn): cmd_batch.append(partial( bl_extension_utils.repo_sync, directory=repo_item.directory, + remote_name=repo_item.name, remote_url=url_params_append_defaults(repo_item.remote_url), online_user_agent=online_user_agent_from_blender(), access_token=repo_item.access_token, diff --git a/scripts/addons_core/bl_pkg/bl_extension_utils.py b/scripts/addons_core/bl_pkg/bl_extension_utils.py index fcb07feb108..29aa646e7ac 100644 --- a/scripts/addons_core/bl_pkg/bl_extension_utils.py +++ b/scripts/addons_core/bl_pkg/bl_extension_utils.py @@ -350,6 +350,7 @@ def url_params_append_for_blender(url: str, blender_version: Tuple[int, int, int def repo_sync( *, directory: str, + remote_name: str, remote_url: str, online_user_agent: str, access_token: str, @@ -364,6 +365,7 @@ def repo_sync( yield from command_output_from_json_0([ "sync", "--local-dir", directory, + "--remote-name", remote_name, "--remote-url", remote_url, "--online-user-agent", online_user_agent, "--access-token", access_token, diff --git a/scripts/addons_core/bl_pkg/cli/blender_ext.py b/scripts/addons_core/bl_pkg/cli/blender_ext.py index bb02f7dcebb..a35e261908a 100755 --- a/scripts/addons_core/bl_pkg/cli/blender_ext.py +++ b/scripts/addons_core/bl_pkg/cli/blender_ext.py @@ -1645,6 +1645,7 @@ def repo_local_private_dir_ensure_with_subdir(*, local_dir: str, subdir: str) -> def repo_sync_from_remote( *, msg_fn: MessageFn, + remote_name: str, remote_url: str, local_dir: str, online_user_agent: str, @@ -1656,7 +1657,7 @@ def repo_sync_from_remote( Load package information into the local path. """ request_exit = False - request_exit |= message_status(msg_fn, "Sync repo: {:s}".format(remote_url)) + request_exit |= message_status(msg_fn, f'Checking repository "{remote_name}" for updates...') if request_exit: return False @@ -1675,7 +1676,7 @@ def repo_sync_from_remote( with CleanupPathsContext(files=(local_json_path_temp,), directories=()): # TODO: time-out. - request_exit |= message_status(msg_fn, "Sync downloading remote data") + request_exit |= message_status(msg_fn, f'Refreshing extensions list for "{remote_name}"...') if request_exit: return False @@ -1706,11 +1707,11 @@ def repo_sync_from_remote( error_msg = repo_json_is_valid_or_error(local_json_path_temp) if error_msg is not None: - message_error(msg_fn, "sync: invalid manifest ({:s}) reading {!r}!".format(error_msg, remote_url)) + message_error(msg_fn, f'Repository error: invalid manifest ({error_msg}) for repository "{remote_name}"!') return False del error_msg - request_exit |= message_status(msg_fn, "Sync complete: {:s}".format(remote_url)) + request_exit |= message_status(msg_fn, f'Extensions list for "{remote_name}" updated') if request_exit: return False @@ -1838,6 +1839,19 @@ def generic_arg_repo_dir(subparse: argparse.ArgumentParser) -> None: ) +def generic_arg_remote_name(subparse: argparse.ArgumentParser) -> None: + subparse.add_argument( + "--remote-name", + dest="remote_name", + type=str, + help=( + "The remote repository name." + ), + default="", + required=False, + ) + + def generic_arg_remote_url(subparse: argparse.ArgumentParser) -> None: subparse.add_argument( "--remote-url", @@ -2167,6 +2181,7 @@ class subcmd_client: msg_fn: MessageFn, *, remote_url: str, + remote_name: str, local_dir: str, online_user_agent: str, access_token: str, @@ -2179,6 +2194,7 @@ class subcmd_client: success = repo_sync_from_remote( msg_fn=msg_fn, + remote_name=remote_name, remote_url=remote_url, local_dir=local_dir, online_user_agent=online_user_agent, @@ -3022,6 +3038,7 @@ def argparse_create_client_sync(subparsers: "argparse._SubParsersAction[argparse ) generic_arg_remote_url(subparse) + generic_arg_remote_name(subparse) generic_arg_local_dir(subparse) generic_arg_online_user_agent(subparse) generic_arg_access_token(subparse) @@ -3035,6 +3052,7 @@ def argparse_create_client_sync(subparsers: "argparse._SubParsersAction[argparse func=lambda args: subcmd_client.sync( msg_fn_from_args(args), remote_url=args.remote_url, + remote_name=args.remote_name if args.remote_name else args.remote_url, local_dir=args.local_dir, online_user_agent=args.online_user_agent, access_token=args.access_token, diff --git a/scripts/addons_core/bl_pkg/tests/test_cli.py b/scripts/addons_core/bl_pkg/tests/test_cli.py index 82c3b2d6639..b4d8c800a55 100644 --- a/scripts/addons_core/bl_pkg/tests/test_cli.py +++ b/scripts/addons_core/bl_pkg/tests/test_cli.py @@ -352,9 +352,9 @@ class TestCLI_WithRepo(unittest.TestCase): ], exclude_types={"PROGRESS"}) self.assertEqual( output_json, [ - ('STATUS', 'Sync repo: ' + self.dirpath_url), - ('STATUS', 'Sync downloading remote data'), - ('STATUS', 'Sync complete: ' + self.dirpath_url), + ('STATUS', f'Checking repository "{self.dirpath_url}" for updates...'), + ('STATUS', f'Refreshing extensions list for "{self.dirpath_url}"...'), + ('STATUS', f'Extensions list for "{self.dirpath_url}" updated'), ] ) -- 2.30.2 From dd4da7748fca230d2d9c38c1eac4d0023d15ef9f Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 28 May 2024 18:26:05 +0200 Subject: [PATCH 2/3] From review: Use format() instead of f-strings --- scripts/addons_core/bl_pkg/cli/blender_ext.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/addons_core/bl_pkg/cli/blender_ext.py b/scripts/addons_core/bl_pkg/cli/blender_ext.py index a35e261908a..ce5e1b49a55 100755 --- a/scripts/addons_core/bl_pkg/cli/blender_ext.py +++ b/scripts/addons_core/bl_pkg/cli/blender_ext.py @@ -1657,7 +1657,7 @@ def repo_sync_from_remote( Load package information into the local path. """ request_exit = False - request_exit |= message_status(msg_fn, f'Checking repository "{remote_name}" for updates...') + request_exit |= message_status(msg_fn, "Checking repository \"{:s}\" for updates...".format(remote_name)) if request_exit: return False @@ -1676,7 +1676,7 @@ def repo_sync_from_remote( with CleanupPathsContext(files=(local_json_path_temp,), directories=()): # TODO: time-out. - request_exit |= message_status(msg_fn, f'Refreshing extensions list for "{remote_name}"...') + request_exit |= message_status(msg_fn, "Refreshing extensions list for \"{:s}\"...".format(remote_name)) if request_exit: return False @@ -1707,11 +1707,15 @@ def repo_sync_from_remote( error_msg = repo_json_is_valid_or_error(local_json_path_temp) if error_msg is not None: - message_error(msg_fn, f'Repository error: invalid manifest ({error_msg}) for repository "{remote_name}"!') + message_error( + msg_fn, + "Repository error: invalid manifest ({:s}) for repository \"{:s}\"!".format( + error_msg, + remote_name)) return False del error_msg - request_exit |= message_status(msg_fn, f'Extensions list for "{remote_name}" updated') + request_exit |= message_status(msg_fn, "Extensions list for \"{:s}\" updated".format(remote_name)) if request_exit: return False -- 2.30.2 From 656c41c49000f3c11b9b74752836ce0111aebc6a Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Tue, 28 May 2024 18:35:04 +0200 Subject: [PATCH 3/3] From review: use the stripped url as fallback Note: I had to copy the util function to tests. To be fixed later. --- scripts/addons_core/bl_pkg/cli/blender_ext.py | 2 +- scripts/addons_core/bl_pkg/tests/test_cli.py | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/addons_core/bl_pkg/cli/blender_ext.py b/scripts/addons_core/bl_pkg/cli/blender_ext.py index ce5e1b49a55..d000c142077 100755 --- a/scripts/addons_core/bl_pkg/cli/blender_ext.py +++ b/scripts/addons_core/bl_pkg/cli/blender_ext.py @@ -3056,7 +3056,7 @@ def argparse_create_client_sync(subparsers: "argparse._SubParsersAction[argparse func=lambda args: subcmd_client.sync( msg_fn_from_args(args), remote_url=args.remote_url, - remote_name=args.remote_name if args.remote_name else args.remote_url, + remote_name=args.remote_name if args.remote_name else remote_url_params_strip(args.remote_url), local_dir=args.local_dir, online_user_agent=args.online_user_agent, access_token=args.access_token, diff --git a/scripts/addons_core/bl_pkg/tests/test_cli.py b/scripts/addons_core/bl_pkg/tests/test_cli.py index b4d8c800a55..445c6b95d82 100644 --- a/scripts/addons_core/bl_pkg/tests/test_cli.py +++ b/scripts/addons_core/bl_pkg/tests/test_cli.py @@ -79,6 +79,23 @@ STATUS_NON_ERROR = {'STATUS', 'PROGRESS'} # Generic Utilities # +def remote_url_params_strip(url: str) -> str: + import urllib + # Parse the URL to get its scheme, domain, and query parameters. + parsed_url = urllib.parse.urlparse(url) + + # Combine the scheme, netloc, path without any other parameters, stripping the URL. + new_url = urllib.parse.urlunparse(( + parsed_url.scheme, + parsed_url.netloc, + parsed_url.path, + None, # `parsed_url.params,` + None, # `parsed_url.query,` + None, # `parsed_url.fragment,` + )) + + return new_url + def path_to_url(path: str) -> str: from urllib.parse import urljoin from urllib.request import pathname2url @@ -341,6 +358,7 @@ class TestCLI_WithRepo(unittest.TestCase): ) def test_client_install_and_uninstall(self) -> None: + stripped_url = remote_url_params_strip(self.dirpath_url) with tempfile.TemporaryDirectory(dir=TEMP_DIR_LOCAL) as temp_dir_local: # TODO: only run once. self.test_server_generate() @@ -352,9 +370,9 @@ class TestCLI_WithRepo(unittest.TestCase): ], exclude_types={"PROGRESS"}) self.assertEqual( output_json, [ - ('STATUS', f'Checking repository "{self.dirpath_url}" for updates...'), - ('STATUS', f'Refreshing extensions list for "{self.dirpath_url}"...'), - ('STATUS', f'Extensions list for "{self.dirpath_url}" updated'), + ('STATUS', "Checking repository \"{:s}\" for updates...".format(stripped_url)), + ('STATUS', "Refreshing extensions list for \"{:s}\"...".format(stripped_url)), + ('STATUS', "Extensions list for \"{:s}\" updated".format(stripped_url)), ] ) -- 2.30.2