From 0f74788f0b57e4b937c3aaf4dc0f02af9e9a4317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= Date: Mon, 7 Oct 2024 11:49:47 +0200 Subject: [PATCH 1/2] Update getUserDirectory to work on any operating system --- toolbox/internal/getUserDirectory.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/toolbox/internal/getUserDirectory.m b/toolbox/internal/getUserDirectory.m index 94179ac..d5c11c2 100644 --- a/toolbox/internal/getUserDirectory.m +++ b/toolbox/internal/getUserDirectory.m @@ -1,11 +1,19 @@ function directory = getUserDirectory() -%GETUSERDIRECTORY Get the current user directory +%GETUSERDIRECTORY Get the current user directory, works on Windows, macOS, and Linux % Copyright 2021 The MathWorks, Inc. - [status, directory] = system("echo %HOMEPATH%"); + if ispc + % For Windows, use HOMEPATH + [status, directory] = system("echo %HOMEDRIVE%%HOMEPATH%"); + else + % For macOS/Linux, use HOME + [status, directory] = system("echo $HOME"); + end + if status ~= 0 - error("userDirectory:couldNotGetUserDirectory","Could not retrieve user directory") + error("userDirectory:couldNotGetUserDirectory", "Could not retrieve user directory"); end + + % Trim any whitespace and convert to string directory = strtrim(string(directory)); end - From 97078cf591afd1eec14e59924eb3f1da2713fbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Nussbaumer?= Date: Mon, 7 Oct 2024 12:02:15 +0200 Subject: [PATCH 2/2] Fix the check for python package and install --- toolbox/internal/setupCDSAPIIfNeeded.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolbox/internal/setupCDSAPIIfNeeded.m b/toolbox/internal/setupCDSAPIIfNeeded.m index b0aabeb..57c9a6a 100644 --- a/toolbox/internal/setupCDSAPIIfNeeded.m +++ b/toolbox/internal/setupCDSAPIIfNeeded.m @@ -15,10 +15,10 @@ function setupCDSAPIIfNeeded(promptForCredentials) end % Call PIP to see if cdsapi is installed - [result, ~] = system(fullfile(pythonInfo.Home,"Scripts","pip3")+" show cdsapi"); + [result, ~] = system(pythonInfo.Executable+" -m pip show cdsapi"); if result ~= 0 % it's not installed - [result, ~] = system(fullfile(pythonInfo.Home,"Scripts","pip3")+" install cdsapi"); + [result, ~] = system(pythonInfo.Executable+" -m pip install cdsapi"); if result ~= 0 error("climateDataStore:unableToInstallCSAPI","Could not use PIP3 to install CDSAPI") end