Unverified Commit d34f46d8 authored by dotlambda's avatar dotlambda Committed by GitHub
Browse files

python3Packages.rclone-python: hardcode path to rclone executable and run tests (#425213)

parents 62c26067 e6dce4ad
Loading
Loading
Loading
Loading
+31 −3
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  pytestCheckHook,
  replaceVars,
  setuptools,
  rich,
  rclone,
  writableTmpDirAsHomeHook,
}:

buildPythonPackage rec {
@@ -19,15 +22,40 @@ buildPythonPackage rec {
    hash = "sha256-vvsiXS3uI0TcL+X8+75BQmycrF+EGIgQE1dmGef35rI=";
  };

  patches = [
    (replaceVars ./hardcode-rclone-path.patch {
      rclone = lib.getExe rclone;
    })
  ];

  build-system = [ setuptools ];

  dependencies = [
    rclone
    rich
  ];

  # tests require working internet connection
  doCheck = false;
  nativeCheckInputs = [
    pytestCheckHook
    writableTmpDirAsHomeHook
  ];

  preCheck = ''
    # Unlike upstream we don't actually run an S3 server for testing.
    # See https://github.com/Johannes11833/rclone_python/blob/master/launch_test_server.sh
    mkdir -p "$HOME/.config/rclone"
    cat > "$HOME/.config/rclone/rclone.conf" <<EOF
    [test_server_s3]
    type = combine
    upstreams = "testdir=$(mktemp -d)"
    EOF
  '';

  disabledTestPaths = [
    # test requires a remote that supports public links
    "tests/test_link.py"
    # test looks up latest version on rclone.org
    "tests/test_version.py"
  ];

  pythonImportsCheck = [ "rclone_python" ];

+129 −0
Original line number Diff line number Diff line
diff --git a/rclone_python/rclone.py b/rclone_python/rclone.py
index da399b4..e05365a 100644
--- a/rclone_python/rclone.py
+++ b/rclone_python/rclone.py
@@ -43,7 +43,7 @@ def is_installed() -> bool:
     """
     :return: True if rclone is correctly installed on the system.
     """
-    return which("rclone") is not None
+    return True
 
 
 @__check_installed
@@ -199,7 +199,7 @@ def copy(
         in_path,
         out_path,
         ignore_existing=ignore_existing,
-        command="rclone copy",
+        command="@rclone@ copy",
         command_descr="Copying",
         show_progress=show_progress,
         listener=listener,
@@ -234,7 +234,7 @@ def copyto(
         in_path,
         out_path,
         ignore_existing=ignore_existing,
-        command="rclone copyto",
+        command="@rclone@ copyto",
         command_descr="Copying",
         show_progress=show_progress,
         listener=listener,
@@ -269,7 +269,7 @@ def move(
         in_path,
         out_path,
         ignore_existing=ignore_existing,
-        command="rclone move",
+        command="@rclone@ move",
         command_descr="Moving",
         show_progress=show_progress,
         listener=listener,
@@ -304,7 +304,7 @@ def moveto(
         in_path,
         out_path,
         ignore_existing=ignore_existing,
-        command="rclone moveto",
+        command="@rclone@ moveto",
         command_descr="Moving",
         show_progress=show_progress,
         listener=listener,
@@ -336,7 +336,7 @@ def sync(
     _rclone_transfer_operation(
         src_path,
         dest_path,
-        command="rclone sync",
+        command="@rclone@ sync",
         command_descr="Syncing",
         show_progress=show_progress,
         listener=listener,
diff --git a/rclone_python/scripts/get_version.py b/rclone_python/scripts/get_version.py
index b1d30fd..bc00cad 100644
--- a/rclone_python/scripts/get_version.py
+++ b/rclone_python/scripts/get_version.py
@@ -2,6 +2,6 @@ from subprocess import check_output
 
 
 def get_version():
-    stdout = check_output("rclone version", shell=True, encoding="utf8")
+    stdout = check_output("@rclone@ version", shell=True, encoding="utf8")
 
     return stdout.split("\n")[0].replace("rclone ", "")
diff --git a/rclone_python/scripts/update_hash_types.py b/rclone_python/scripts/update_hash_types.py
index 92fbd0a..ef963cf 100644
--- a/rclone_python/scripts/update_hash_types.py
+++ b/rclone_python/scripts/update_hash_types.py
@@ -14,7 +14,7 @@ def update_hashes(output_path: str):
     """
 
     # get all supported backends
-    rclone_output = sp.check_output("rclone hashsum", shell=True, encoding="utf8")
+    rclone_output = sp.check_output("@rclone@ hashsum", shell=True, encoding="utf8")
     lines = rclone_output.splitlines()
 
     hashes = []
diff --git a/rclone_python/utils.py b/rclone_python/utils.py
index d4a8413..1b29bd8 100644
--- a/rclone_python/utils.py
+++ b/rclone_python/utils.py
@@ -66,9 +66,9 @@ def run_rclone_cmd(
     # otherwise the default rclone config path is used:
     config = Config()
     if config.config_path is not None:
-        base_command = f"rclone --config={config.config_path}"
+        base_command = f"@rclone@ --config={config.config_path}"
     else:
-        base_command = "rclone"
+        base_command = "@rclone@"
 
     # add optional arguments and flags to the command
     args_str = args2string(args)
diff --git a/tests/test_copy.py b/tests/test_copy.py
index 4ded5fa..1cae53b 100644
--- a/tests/test_copy.py
+++ b/tests/test_copy.py
@@ -45,11 +45,11 @@ def create_local_file(
 @pytest.mark.parametrize(
     "wrapper_command,rclone_command",
     [
-        (rclone.copy, "rclone copy"),
-        (rclone.copyto, "rclone copyto"),
-        (rclone.sync, "rclone sync"),
-        (rclone.move, "rclone move"),
-        (rclone.moveto, "rclone moveto"),
+        (rclone.copy, "@rclone@ copy"),
+        (rclone.copyto, "@rclone@ copyto"),
+        (rclone.sync, "@rclone@ sync"),
+        (rclone.move, "@rclone@ move"),
+        (rclone.moveto, "@rclone@ moveto"),
     ],
 )
 def test_rclone_command_called(wrapper_command: Callable, rclone_command: str):
@@ -62,7 +62,7 @@ def test_rclone_command_called(wrapper_command: Callable, rclone_command: str):
         rclone.utils.subprocess,
         "Popen",
         return_value=subprocess.Popen(
-            "rclone help", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
+            "@rclone@ help", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
         ),
     ) as mock:
         wrapper_command("nothing/not_a.file", "fake_remote:unicorn/folder")