Skip to content

Commit 505bd4d

Browse files
committed
[RMS] Add check for the correct conda environment
Initialize Julia environment before installing RMS Add extra debug info
1 parent fc9d125 commit 505bd4d

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ env:
5555
# RMS branch to use for ReactionMechanismSimulator installation
5656
RMS_BRANCH: for_rmg
5757
# Use standard RMS installation mode for install_rms.sh
58-
RMS_MODE: standard
58+
RMS_MODE: CI
5959
# julia parallel pre-compilation leads to race conditions and hangs, so we limit it to run in serial
6060
JULIA_NUM_PRECOMPILE_TASKS: 1
6161

install_rms.sh

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,25 @@ echo "Julia 1.10 binary path: $julia_path"
3939

4040
# Get current conda environment name
4141
current_env=$(conda info --envs | grep '\*' | awk '{print $1}')
42-
echo "Current conda environment: $current_env"
42+
43+
# Ask the user to confirm RMS is being installed in the correct
44+
# conda environemnt. Skip if this is run under CI.
45+
if [ "$RMS_MODE" != "CI" ]; then
46+
echo " Please confirm that you want to install RMS into the current conda environment: '$current_env'"
47+
echo " If this is not correct, abort and activate the correct environment before rerunning."
48+
read -p "Proceed with installation in '$current_env'? (y/N): " confirm
49+
case "$confirm" in
50+
[yY][eE][sS]|[yY])
51+
echo "✅ Proceeding with installation in '$current_env'"
52+
;;
53+
*)
54+
echo "❌ Aborted. Please activate the correct conda environment and try again."
55+
exit 1
56+
;;
57+
esac
58+
else
59+
echo "Current conda environment: $current_env"
60+
fi
4361

4462
# Set environment variables for the current environment, for future uses
4563
# https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#If-you-already-have-Python-and-required-Python-packages-installed
@@ -89,28 +107,84 @@ if [ "$RMS_MODE" = "dev" ]; then
89107
echo "Using local RMS path: $RMS_PATH"
90108
fi
91109

92-
if [ "$RMS_MODE" = "standard" ]; then
110+
# Initialize the Julia environment from Python using juliacall
111+
python << EOF
112+
import sys
113+
try:
114+
from juliacall import Main
115+
Main.seval('println("Active Julia environment: ", Base.active_project())')
116+
Main.seval('println("Julia load path: ", Base.load_path())')
117+
Main.seval('using Pkg')
118+
Main.seval('Pkg.status()')
119+
except Exception as e:
120+
print("❌ Error while initialize Julia environment:")
121+
print(e)
122+
sys.exit(1)
123+
EOF
124+
125+
# Install RMS
126+
if [ "$RMS_MODE" = "standard" ] || [ "$RMS_MODE" = "CI" ]; then
93127
echo "Installing RMS from branch: $RMS_BRANCH"
94128
julia << EOF || echo "RMS standard install error - continuing anyway ¯\\_(ツ)_/¯"
95129
using Pkg
96130
Pkg.activate(ENV["PYTHON_JULIAPKG_PROJECT"])
97131
Pkg.add(Pkg.PackageSpec(name="ReactionMechanismSimulator", url="https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl.git", rev="$RMS_BRANCH"))
98132
Pkg.instantiate()
99-
using ReactionMechanismSimulator
133+
try
134+
@info "Loading RMS"
135+
using ReactionMechanismSimulator
136+
@info "RMS loaded successfully!"
137+
catch err
138+
@error "Failed to load RMS" exception=err
139+
Base.show_backtrace(stderr, catch_backtrace())
140+
exit(1)
141+
end
100142
EOF
101143
elif [ "$RMS_MODE" = "dev" ]; then
102144
echo "Installing RMS in developer mode from path: $RMS_PATH"
103145
julia << EOF || echo "RMS developer install error - continuing anyway ¯\\_(ツ)_/¯"
104146
using Pkg
147+
println(ENV["PYTHON_JULIAPKG_PROJECT"])
105148
Pkg.activate(ENV["PYTHON_JULIAPKG_PROJECT"])
106149
Pkg.develop(path="$RMS_PATH")
107150
Pkg.instantiate()
108-
using ReactionMechanismSimulator
151+
try
152+
@info "Loading RMS"
153+
using ReactionMechanismSimulator
154+
@info "RMS loaded successfully!"
155+
catch err
156+
@error "Failed to load RMS" exception=err
157+
Base.show_backtrace(stderr, catch_backtrace())
158+
exit(1)
159+
end
109160
EOF
110161
else
111162
echo "Unknown RMS_MODE: $RMS_MODE. Must be either 'standard' or 'dev'."
112163
exit 1
113164
fi
114165

166+
julia_status=$?
167+
if [ $julia_status -ne 0 ]; then
168+
echo "RMS installation failed!"
169+
exit $julia_status
170+
fi
171+
115172
echo "Checking if ReactionMechanismSimulator is installed in the current conda environment for Python usage..."
116-
python -c "from juliacall import Main; import sys; sys.exit(0 if Main.seval('Base.identify_package(\"ReactionMechanismSimulator\") !== nothing') and print('ReactionMechanismSimulator is installed in $current_env') is None else 1)"
173+
174+
python << EOF
175+
import sys
176+
try:
177+
from juliacall import Main
178+
RMS_Pkg = Main.seval('Base.identify_package("ReactionMechanismSimulator")')
179+
print("Package identify result: ", RMS_Pkg)
180+
if RMS_Pkg is Main.nothing:
181+
print("❌ ReactionMechanismSimulator is NOT installed correctly.")
182+
sys.exit(1)
183+
else:
184+
print("✅ ReactionMechanismSimulator is succesfully installed!")
185+
sys.exit(0)
186+
except Exception as e:
187+
print("❌ Error while checking ReactionMechanismSimulator installation:")
188+
print(e)
189+
sys.exit(1)
190+
EOF

0 commit comments

Comments
 (0)