From 9a0a25c68c8e237556b74baf4e9150cf94cc0a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Thu, 29 Feb 2024 12:27:27 +0100 Subject: [PATCH] Add Kino.recompile/0 (#399) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/kino.ex | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/kino.ex b/lib/kino.ex index a3e244d6..ffbe6fd6 100644 --- a/lib/kino.ex +++ b/lib/kino.ex @@ -528,4 +528,33 @@ defmodule Kino do {:error, _} -> nil end end + + @doc """ + Recompiles dependenies. + + Once you have installed dependencies with `Mix.install/1`, this will + recompile any outdated path dependencies declared during the install. + + > #### Reproducability {: .warning} + > + > Keep in mind that recompiling dependency modules is **not** going + > to mark any cells as stale. This means that the given notebook + > state may no longer be reproducable. This function is meant as a + > utility when prototyping alongside a Mix project. + """ + @spec recompile() :: :ok + def recompile() do + unless Mix.installed?() do + raise "trying to call Kino.recompile/0, but Mix.install/2 was never called" + end + + elixir_version = System.version() + + if Version.compare(elixir_version, "1.16.2") == :lt do + raise "Kino.recompile/0 requires Elixir 1.16.2 or newer to work, but you are using #{elixir_version}" + end + + IEx.Helpers.recompile() + :ok + end end