Show an error when an unexpected version of Pythonx is installed

This commit is contained in:
Jonatan Kłosko 2025-02-22 01:53:24 +09:00
parent 793e683338
commit db307dc88a
3 changed files with 26 additions and 19 deletions

View file

@ -508,4 +508,6 @@ defmodule Livebook.Runtime.Definitions do
def pythonx_dependency() do
%{dep: {:pythonx, "~> 0.4.0"}, config: []}
end
def pythonx_requirement(), do: "~> 0.4.0"
end

View file

@ -1053,9 +1053,10 @@ defmodule Livebook.Runtime.Evaluator do
end
defp ensure_pythonx() do
if Code.ensure_loaded?(Pythonx) do
:ok
else
pythonx_requirement = Livebook.Runtime.Definitions.pythonx_requirement()
cond do
not Code.ensure_loaded?(Pythonx) ->
message =
"""
Pythonx is missing, make sure to add it as a dependency:
@ -1065,9 +1066,22 @@ defmodule Livebook.Runtime.Evaluator do
exception = RuntimeError.exception(message)
{{:error, :error, exception, []}, []}
not Version.match?(pythonx_version(), pythonx_requirement) ->
message =
"this Livebook version requires Pythonx #{pythonx_requirement}," <>
" but #{pythonx_version()} is installed, please update the dependency"
exception = RuntimeError.exception(message)
{{:error, :error, exception, []}, []}
true ->
:ok
end
end
defp pythonx_version(), do: List.to_string(Application.spec(:pythonx)[:vsn])
defp identifier_dependencies(context, tracer_info, prev_context) do
identifiers_used = MapSet.new()
identifiers_defined = %{}

View file

@ -85,15 +85,6 @@ defmodule Livebook.Runtime.Evaluator.Formatter do
%{type: :terminal_text, text: "Ok", chunk: false}
end
def format_result(:"pyproject.toml", {:error, _kind, _error, _stacktrace}) do
formatted =
"Error, see the output above for details"
|> error_color()
|> IO.iodata_to_binary()
%{type: :error, message: formatted, context: nil}
end
def format_result(_language, {:error, kind, error, stacktrace}) do
formatted = format_error(kind, error, stacktrace)
%{type: :error, message: formatted, context: error_context(error)}