Is there a MATLAB package manager?

61 vues (au cours des 30 derniers jours)
James Bland
James Bland le 25 Mai 2021
Commenté : Daniel le 16 Nov 2023
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 commentaires
Matt Cooper
Matt Cooper le 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.
James Bland
James Bland le 25 Oct 2022
hi Matt,
Thanks for your clear answer, although i still feel that this is code i shouldnt have to reinvent myself

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 10 Juin 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 commentaires
James Bland
James Bland le 22 Juin 2021
hi sean,
thanks for your answer. If you could point me to any good examples of matlab workflows/ code organisation that would be appreciated!
Stephen
Stephen le 19 Jan 2022
@James Bland there is no such thing. Hope this helps

Connectez-vous pour commenter.

Plus de réponses (1)

Rob Campbell
Rob Campbell le 26 Mai 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 commentaires
Walter Roberson
Walter Roberson le 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
Daniel le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Manage Products dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by