From ef45f119f623fbc1e79f36fa08886e7206e506ee Mon Sep 17 00:00:00 2001 From: Aleksei Magusev Date: Tue, 12 Dec 2023 02:20:47 -0800 Subject: [PATCH] Handle local archives without requiring network tooling --- lib/xla.ex | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/xla.ex b/lib/xla.ex index c2d0025..9da440b 100644 --- a/lib/xla.ex +++ b/lib/xla.ex @@ -176,7 +176,7 @@ defmodule XLA do end defp download_external!(url, archive_path) do - assert_network_tool!() + unless local_archive(url), do: assert_network_tool!() Logger.info("Downloading XLA archive from #{url}") download_archive!(url, archive_path) end @@ -242,6 +242,14 @@ defmodule XLA do end defp download(url, dest) do + if local_path = local_archive(url) do + File.cp!(local_path, dest) + else + download_remote(url, dest) + end + end + + defp download_remote(url, dest) do command = case network_tool() do :curl -> "curl --fail -L -o #{dest} #{curl_options()} #{url}" @@ -296,4 +304,15 @@ defmodule XLA do headers = http_headers() Enum.map_join(headers, " ", &"--header='#{&1}'") end + + defp local_archive("file:" <> rest) do + case rest do + "//localhost/" <> path -> "/" <> path + "///" <> path -> "/" <> path + "/" <> path when binary_part(path, 0, 1) != "/" -> rest + _ -> nil + end + end + + defp local_archive(_), do: nil end