Is there a MATLAB package manager?

65 visualizaciones (últimos 30 días)
James Bland
James Bland el 25 de Mayo de 2021
Comentada: Daniel el 16 de Nov. de 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 comentarios
Matt Cooper
Matt Cooper el 30 de Sept. de 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 el 25 de Oct. de 2022
hi Matt,
Thanks for your clear answer, although i still feel that this is code i shouldnt have to reinvent myself

Iniciar sesión para comentar.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 10 de Jun. de 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 comentarios
James Bland
James Bland el 22 de Jun. de 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 el 19 de En. de 2022
@James Bland there is no such thing. Hope this helps

Iniciar sesión para comentar.

Más respuestas (1)

Rob Campbell
Rob Campbell el 26 de Mayo de 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 comentarios
Walter Roberson
Walter Roberson el 26 de Oct. de 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 el 16 de Nov. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Manage Products en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by