From 7015ee8b6b4eeb4203fb839a265f76cb686e6501 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Tue, 30 Apr 2024 16:29:29 +0100 Subject: [PATCH 1/3] Save mpi_library_path inside the catch-block --- .../shared/add_dependencies_to_project.jl | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/machines/shared/add_dependencies_to_project.jl b/machines/shared/add_dependencies_to_project.jl index 117d2f502..eb42d5dab 100644 --- a/machines/shared/add_dependencies_to_project.jl +++ b/machines/shared/add_dependencies_to_project.jl @@ -110,20 +110,25 @@ elseif Sys.isapple() end MPIPreferences.use_system_binary(library_names=mpi_library_path) - end - # Just got the value for the setting, now write it to LocalPreferences.toml - mk_preferences["mpi_library_path"] = mpi_library_path - open(local_preferences_filename, "w") do io - TOML.print(io, local_preferences, sorted=true) + # Just got the value for the setting, now write it to LocalPreferences.toml + mk_preferences["mpi_library_path"] = mpi_library_path + open(local_preferences_filename, "w") do io + TOML.print(io, local_preferences, sorted=true) + end + # Re-read local_preferences file, so we can modify it again below, keeping the + # changes here + local_preferences = TOML.parsefile(local_preferences_filename) + mk_preferences = local_preferences["moment_kinetics"] end - # Re-read local_preferences file, so we can modify it again below, keeping the - # changes here - local_preferences = TOML.parsefile(local_preferences_filename) - mk_preferences = local_preferences["moment_kinetics"] else - mpi_library_path = mk_preferences["mpi_library_path"] - MPIPreferences.use_system_binary(library_names=mpi_library_path) + if "mpi_library_path" ∈ keys(mk_preferences) + mpi_library_path = mk_preferences["mpi_library_path"] + MPIPreferences.use_system_binary(library_names=mpi_library_path) + else + # Must have auto-detected MPI library before, so do the same here + MPIPreferences.use_system_binary() + end end else # If settings for MPI library are not given explicitly, then auto-detection by From bcfd62a3a4e64b4e91c8ce521156650ff57f944a Mon Sep 17 00:00:00 2001 From: John Omotani Date: Tue, 30 Apr 2024 16:29:46 +0100 Subject: [PATCH 2/3] When adding `using Revise` to startup.jl, guard with try-catch --- machines/shared/machine_setup.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/machines/shared/machine_setup.jl b/machines/shared/machine_setup.jl index 51bb48ee9..d8c228969 100644 --- a/machines/shared/machine_setup.jl +++ b/machines/shared/machine_setup.jl @@ -262,8 +262,15 @@ function machine_setup_moment_kinetics(machine::String; no_force_exit::Bool=fals result = run(`grep "using Revise" $startup_path`, wait=false) if !success(result) println("Adding `using Revise` to $startup_path") + # When initialising a new copy of the repo, if Revise is not installed yet + # having just `using Revise` in the startup.jl would cause an error, so + # guard it with a try/catch. open(startup_path, "a") do io - println(io, "\nusing Revise") + println(io, "\ntry") + println(io, " using Revise") + println(io, "catch") + println(io, " println(\"Warning: failed to load Revise\")") + println(io, "end") end end end From e6379a21cad33842778fa9807026afedb8150626 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Tue, 30 Apr 2024 16:58:41 +0100 Subject: [PATCH 3/3] Explicitly declare some local/global variables to avoid warnings/errors --- machines/shared/add_dependencies_to_project.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/machines/shared/add_dependencies_to_project.jl b/machines/shared/add_dependencies_to_project.jl index eb42d5dab..80a24ee13 100644 --- a/machines/shared/add_dependencies_to_project.jl +++ b/machines/shared/add_dependencies_to_project.jl @@ -101,6 +101,9 @@ elseif Sys.isapple() MPIPreferences.use_system_binary() catch println("Failed to auto-detect path of MPI library...") + + local mpi_library_path + default_mpi_library_path = get(mk_preferences, "mpi_library_path", "") mpi_library_path = get_input_with_path_completion( "\nEnter the full path to your MPI library (e.g. something like " @@ -111,6 +114,8 @@ elseif Sys.isapple() MPIPreferences.use_system_binary(library_names=mpi_library_path) + global mk_preferences, local_preferences + # Just got the value for the setting, now write it to LocalPreferences.toml mk_preferences["mpi_library_path"] = mpi_library_path open(local_preferences_filename, "w") do io