Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions code/+matbox/+setup/+internal/installFexPackage.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
function packageTargetFolder = installFexPackage(toolboxIdentifier, installLocation, options)
function [packageTargetFolder, installationMethod] = installFexPackage(toolboxIdentifier, installLocation, options)
% installFexPackage - Install a FileExchange package
%
% This function installs a package from FileExchange. If the package is
% already present, it is added to the path, otherwise it is downloaded.
%
% installFexPackage(toolboxIdentifier, installLocation)
% [folder, method] = installFexPackage(toolboxIdentifier, installLocation)
%
% Output:
% packageTargetFolder - Path to the installed package folder, or
% string(missing) for mltbx packages (managed by MATLAB)
% installationMethod - "folder" for zip-extracted packages,
% "mltbx" for MATLAB toolbox packages
Comment on lines +9 to +13
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says packageTargetFolder is string(missing) for mltbx packages, but when the add-on is already installed you return toolboxFolder (which can be "" if the internal lookup fails). This makes the output contract inconsistent across the two mltbx paths; consider either always returning string(missing) for mltbx, or updating the docs and normalizing toolboxFolder=="" to string(missing) before returning.

Copilot uses AI. Check for mistakes.

% Todo:
% [ ] Separate method for downloading
Expand All @@ -22,10 +28,12 @@
end

% Check if toolbox is installed
[isInstalled, version] = matbox.setup.internal.fex.isToolboxInstalled(toolboxIdentifier, options.Version);
[isInstalled, version, toolboxFolder] = matbox.setup.internal.fex.isToolboxInstalled(toolboxIdentifier, options.Version);

if isInstalled
matlab.addons.enableAddon(toolboxIdentifier, version)
packageTargetFolder = toolboxFolder;
installationMethod = "mltbx";
Comment on lines 33 to +36
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When isInstalled is true, the function assigns outputs but never applies the ~nargout/nargout==1 clearing logic used in the download path. This leads to inconsistent behavior when calling installFexPackage(...) without output arguments (e.g., it may return/echo values in the already-installed case). Consider moving the nargout handling to a single place at the end of the function so it applies to both branches.

Copilot uses AI. Check for mistakes.
if options.Verbose
fprintf('Requirement "%s" is already installed. Skipping...\n', options.Title)
end
Expand Down Expand Up @@ -80,6 +88,7 @@
[tempFilepath, C] = matbox.setup.internal.utility.tempsave(addonUrl, [toolboxIdentifier, '_temp.zip']);

packageTargetFolder = fullfile(installLocation, toolboxName);
installationMethod = "folder";
if ~isfolder(packageTargetFolder); mkdir(packageTargetFolder); end
unzip(tempFilepath, packageTargetFolder);
if options.AddToPath
Expand All @@ -97,7 +106,8 @@
fprintf(newline)
error('Failed to install "%s"...', toolboxName)
end
packageTargetFolder = 'n/a'; % todo
packageTargetFolder = string(missing);
installationMethod = "mltbx";
end

delete(C)
Expand All @@ -106,7 +116,9 @@
end

if ~nargout
clear packageTargetFolder
clear packageTargetFolder installationMethod
elseif nargout == 1
clear installationMethod
end
end
end
Expand Down
Loading