mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 21:16:26 +08:00
Show an error when an unexpected version of Pythonx is installed
This commit is contained in:
parent
793e683338
commit
db307dc88a
3 changed files with 26 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -1053,21 +1053,35 @@ defmodule Livebook.Runtime.Evaluator do
|
|||
end
|
||||
|
||||
defp ensure_pythonx() do
|
||||
if Code.ensure_loaded?(Pythonx) do
|
||||
:ok
|
||||
else
|
||||
message =
|
||||
"""
|
||||
Pythonx is missing, make sure to add it as a dependency:
|
||||
pythonx_requirement = Livebook.Runtime.Definitions.pythonx_requirement()
|
||||
|
||||
#{Macro.to_string(Livebook.Runtime.Definitions.pythonx_dependency().dep)}
|
||||
"""
|
||||
cond do
|
||||
not Code.ensure_loaded?(Pythonx) ->
|
||||
message =
|
||||
"""
|
||||
Pythonx is missing, make sure to add it as a dependency:
|
||||
|
||||
exception = RuntimeError.exception(message)
|
||||
{{:error, :error, exception, []}, []}
|
||||
#{Macro.to_string(Livebook.Runtime.Definitions.pythonx_dependency().dep)}
|
||||
"""
|
||||
|
||||
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 = %{}
|
||||
|
|
|
@ -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)}
|
||||
|
|
Loading…
Add table
Reference in a new issue