Is there a MATLAB package manager?

61 ビュー (過去 30 日間)
James Bland
James Bland 2021 年 5 月 25 日
コメント済み: Daniel 2023 年 11 月 16 日
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
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.
James Bland
James Bland 2022 年 10 月 25 日
hi Matt,
Thanks for your clear answer, although i still feel that this is code i shouldnt have to reinvent myself

サインインしてコメントする。

採用された回答

Sean de Wolski
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 件のコメント
James Bland
James Bland 2021 年 6 月 22 日
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 2022 年 1 月 19 日
@James Bland there is no such thing. Hope this helps

サインインしてコメントする。

その他の回答 (1 件)

Rob Campbell
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.
  7 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 26 日
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 2023 年 11 月 16 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeManage Products についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by