Is there a MATLAB package manager?
조회 수: 42 (최근 30일)
이전 댓글 표시
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
Matt Cooper
2022년 9월 30일
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.
채택된 답변
Sean de Wolski
2021년 6월 10일
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
추가 답변 (2개)
Rob Campbell
2023년 5월 26일
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.
댓글 수: 9
Jan Kappen
2024년 10월 29일 17:46
There is a package manager now, see Organize and Distribute Code Using MATLAB Package Manager - MATLAB & Simulink
Ashley Trowell
2024년 11월 1일 3:51
@Rob Campbell 1 year late, but... You asked if imports solve the namespace issues.
I think Walter's example shows the main reason imports are weak. I can think of two otheres.
A) Walter's example, changing package names and organization is tedious and error prone. Put another way, there are changes which are conceptually simple, eg. nest a package in another package, which may take hours to implement and bug test, because of all the different kinds of labels which may need to be modified, and the fact that an interpreted language won't error until you've followed every path. In a large project, you are almost guaranteed to introduce bugs performing an entirely deterministic operation. (Folks have argued that this is acceptable to prevent people from reorganizing too frequently. No.)
B) Goto Function Definition breaks (At least in previous versions, not sure about 2024.)
Imports broke the functionality of right clicking on a function and saying Go to Definition. You had to decide between the two. I feel that "Goto definition" is critical for languages which are weakly typed and have first class functions. My compromise was to create anonymous functions in a function where I needed an import, because that doesn't break "Goto definition". So inside my function, instead of saying
import signal_tools.visuals.plot_spectrum
I would instead say
plot_spectrum = @signal_tools_visuals.plot_spectrum;
C) Small functions get bloated with imports
Jan Kappen
2024년 10월 29일 17:46
There's a package manager now, see Organize and Distribute Code Using MATLAB Package Manager - MATLAB & Simulink
댓글 수: 2
Ashley Trowell
2024년 10월 31일 18:36
Jan,
Very good news. Thank you for taking the time to share. This looks like an improvement to one of MATLAB's biggest weakness. Give that team a bonus.
Proverbs 25:25 "Like cold water to a weary soul is good news from a distant land."
Jan Kappen
2024년 11월 3일 17:02
@Ashley Trowell I fully agree. And there are livescripts in plain text, i.e. text format now - also an awesome step into the right direction.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!