From 67f6a17d6836255ceaed19abfea937b0f74eb3ed Mon Sep 17 00:00:00 2001 From: yixing Date: Thu, 29 Aug 2024 16:18:57 +0100 Subject: [PATCH] add test to make sure all dependencies work in initCobrarrow --- src/cobrarrow/initCobrarrow.m | 46 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/cobrarrow/initCobrarrow.m b/src/cobrarrow/initCobrarrow.m index afb5e6d76e..a903ab2173 100644 --- a/src/cobrarrow/initCobrarrow.m +++ b/src/cobrarrow/initCobrarrow.m @@ -14,31 +14,35 @@ function initCobrarrow() fprintf('Python Executable: \n'); disp(pyEnvInfo.Executable); + % test Python version compatibility try - py.math.sqrt(16); % test Python version compatibility - - % Get the current directory where the MATLAB script is located - currentFile = mfilename('fullpath'); - currentDir = fileparts(currentFile); - - % Construct the full path to the requirements.txt file - requirementsPath = fullfile(currentDir, 'requirements.txt'); - - % Use python -m pip install to ensure pip is invoked correctly - cmd = sprintf('"%s" -m pip install -r "%s"', pyEnvInfo.Executable, requirementsPath); - status = system(cmd); - - if status == 0 - disp('Packages installed successfully.'); - else - disp('Failed to install packages.'); - end - - fprintf("\nNow you can use the COBRArrow API in MATLAB.\n\n"); + py.math.sqrt(16); catch ME showInstruction(); - error('Failed to use Python. Please check the Python installation.\n'); + rethrow(ME); end + + % Get the current directory where the MATLAB script is located + currentFile = mfilename('fullpath'); + currentDir = fileparts(currentFile); + + % Construct the full path to the requirements.txt file + requirementsPath = fullfile(currentDir, 'requirements.txt'); + + % Use python -m pip install to ensure pip is invoked correctly + cmd = sprintf('"%s" -m pip install -r "%s"', pyEnvInfo.Executable, requirementsPath); + status = system(cmd); + + if status == 0 + % test if pyarrow package works + py.pyarrow.table(py.dict(pyargs('column1', {1, 2, 3, 4}))); + disp('Python package pyarrow installed successfully.'); + else + error('Failed to install packages.'); + end + + fprintf("\nNow you can use the COBRArrow API in MATLAB.\n\n"); + end end