Skip to content

meta: remotes_sync can reuse code when moved to cruizlib #290

@markfinal

Description

@markfinal

This diff should be possible with more code moved to cruizlib

diff --git a/src/cruiz/commands/metarequestconaninvocation.py b/src/cruiz/commands/metarequestconaninvocation.py
index 0fc2779..0a6ed09 100755
--- a/src/cruiz/commands/metarequestconaninvocation.py
+++ b/src/cruiz/commands/metarequestconaninvocation.py
@@ -109,6 +109,17 @@ class MetaRequestConanInvocation(QtCore.QObject):
         logger.critical("Conan has leaked into cruiz")
         sys.exit(1)

+    @staticmethod
+    def encode_request(
+        request: typing.Any, params: typing.Optional[typing.Dict[str, typing.Any]]
+    ) -> str:
+        """Encode a request string and any parameters."""
+        return (
+            f"{request}?{urllib.parse.urlencode(params, doseq=True)}"
+            if params
+            else request
+        )
+
     def request_data(
         self,
         request: typing.Any,
@@ -119,11 +130,7 @@ class MetaRequestConanInvocation(QtCore.QObject):

         Reply is a tuple, with result and exception.
         """
-        meta_request = (
-            f"{request}?{urllib.parse.urlencode(params, doseq=True)}"
-            if params
-            else request
-        )
+        meta_request = MetaRequestConanInvocation.encode_request(request, params)
         logger.debug("* Requesting %s", meta_request)
         self._request_queue.put(meta_request)
         self.active = True
diff --git a/tests/workers/test_meta.py b/tests/workers/test_meta.py
index f8e36b4..209dcd1 100644
--- a/tests/workers/test_meta.py
+++ b/tests/workers/test_meta.py
@@ -4,7 +4,8 @@ from __future__ import annotations

 import logging
 import typing
-import urllib.parse
+
+from cruiz.commands.metarequestconaninvocation import MetaRequestConanInvocation

 from cruizlib.globals import CONAN_FULL_VERSION, CONAN_MAJOR_VERSION
 from cruizlib.interop.message import (
@@ -124,9 +125,8 @@ def test_meta_remotes_sync(
             ConanRemote("ARemote", "http://a.remote.com", True),
             ConanRemote("BRemote", "http://b.remote.com", False),
         ]
-        payload = {"remotes": new_remotes}
-        remotes_sync_request = (
-            f"remotes_sync?{urllib.parse.urlencode(payload, doseq=True)}"
+        remotes_sync_request = MetaRequestConanInvocation.encode_request(
+            "remotes_sync", {"remotes": new_remotes}
         )

         request_queue.put(remotes_sync_request)

However, as it stands, there's a dependency on GUI PySide because of other parts of cruiz that comes in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions