Is there a MATLAB package manager?
68 views (last 30 days)
Show older comments
I cannot find any MathWorks endorsed package managers. The user-built solutions I have found do not seem to be popular (PackMan, DepMat, mpm) or regularly maintained. What do people recommend? Is there a reason for the lack of package manager in comparison to pip (python), npm (JavaScript)? How does MathWorks recommend I organise seperate but interdependent code?
5 Comments
Matt Cooper
on 30 Sep 2022
mpm looks promising but here is how to roll your own: install matlab source code (file exchange, github, etc) into a "toolboxes" folder, and manage projects in a "projects" folder. Use setenv() to define these paths in startup.m. Write a function that uses getenv() and dir() to list all subdirectories in these folders and (optionally) save it as a registry. Write a function called activate.m that accepts as input the name of a toolbox or project, reads the registry or uses dir() on the fly, addpath() to 'activate' the toolbox or (for a project) cd into it. Write a function called deactivate.m that does the opposite. Pro tip: put a functionSignatures.json file with activate.m and deactivate.m and populate the 'choices={}' field with the toolbox and project names. Now you have autocomplete, simply type activate <toolboxname> and viola. You can add utilities that integrate with remote source control, like mpm provides, but activate/deactivate will solve 99% of your daily need to navigate from project to project with a clean namespace and a centralized registry of available source code.
Accepted Answer
Sean de Wolski
on 10 Jun 2021
Right now there is no package manager like the ones you listed in that everything in MATLAB is tied to the path. Using MATLAB Add-ons with the File Exchange and MATLAB Projects with reference projects are the two best current solutions. You can minimize namespace collisions with namespace packages in MATLAB (note the terminology here does not imply package like in other languages).
2 Comments
More Answers (1)
Rob Campbell
on 26 May 2023
The fact that this still does not exist is not only real pain but it's arguably holding back the whole MATLAB ecosystem. The lack of a package manager disourages teams of people from building interconnected projects and so makes MATLAB a less attractive platform for serious development.
7 Comments
Walter Roberson
on 26 Oct 2023
Suppose you have package MiddleEarth with subpackage Wizards with function Gandalf . Then you can
import MiddleEarth.Wizards.*
inside a function.
However, there is nothing similar to
import(CurrentPackage, 'Wizards', '*')
so if you change the name of the package from MiddleEarth to Arda then you need to edit every reference in the code to hard-code the new package name.
Daniel
on 16 Nov 2023
Hard agree, @Rob Campbell, but it's unfortunately quite clear that writing even halfway decent software simply isn't in Mathworks DNA. The most recent facepalming example of MATLAB's utter inability to keep up with expected features in every real programming language was when I realized loadenv was introduced in 2023a... I think the most productive thing to do is start working paths to migrate away from MATLAB where possible.
See Also
Categories
Find more on Manage Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!