# Mathematica package manager

I want to bundle up a Mathematica package that I've written and distribute it as open source. It has a couple of dependencies that I'd like to automatically download independently from my package as well.

Is there any sort of established Mathematica package manager and package distribution site? (I'm thinking along the lines of pip for Python, gem for Ruby, nuget for .NET, hackage for Haskell, that sort of thing.)

I've seen Wolfram MathSource, and as near as I can tell its aim seems to be to collect various contributed packages from around the web into a central place, but it doesn't feel very active (maybe I'm wrong?).

-

Why don't we make one? Here's a start -- feel free to try it at home :)

ClearAll[mfvonh, HelloWorld];
Import["http://mfvonh.me/mma/install", "Text"] // ToExpression;
mfvonh[Install, {"Testing", "HelloWorld"}];
HelloWorld[]

Hello, world! -mfvonh

You can distribute any kind of content (definitions, data, docs, etc.) this way. Here's how it works:

I run a webserver at mfvonh.me, and /mma is just a directory containing whatever I need to transfer (text files with definitions, data, etc.). The "install" file looks like this:

Import["http://mfvonh.me/mma/install", "Text"]

=

ClearAll[mfvonh];
mfvonh[dir_, args___] :=
Module[{
BaseURI = "http://mfvonh.me/mma",
ValidDirQ := MatchQ[dir, _Symbol],
ValidArgsQ = MatchQ[{args}, {} | {{__String} .., ___Rule}],
FromMFVONH = Import[#, "Text"] &,
Exec = ToExpression[#] &},
Switch[dir,
Install,
Exec /@ FromMFVONH /@ (StringJoin[Riffle[{BaseURI, ##}, "/"]] & @@@
Cases[{args}, _List])
] /; ValidDirQ && ValidArgsQ
]

So in the example {"Testing", "HellWorld"} is resolved to the corresponding path on the server, which is also just a file:

Import["http://mfvonh.me/mma/Testing/HelloWorld", "Text"]

=

SetDelayed[HelloWorld[],Print["Hello, world! -mfvonh"]]

The simple way to define dependencies would be to include a reference to them in the install script, and a generic check to see if a package has already been loaded. It would be pretty easy to build out all the features of a decent package manager. Obviously executing code off the internet introduces some security considerations.

I would be willing to take this on as a project if people would use it.

-
Talk to Leonid in chat, he's been working on one. –  Szabolcs May 28 '14 at 23:51
I also have a start at github.com/mathematica-packages/mpg, and have been sort of waiting to see whether there was even enough interest in the idea to justify more effort. Starting to look like there might be enough interest for this to work. You use mine by saying Import["https://j.mp/needs-mpg"], or if Mpg is already installed, by saying Needs[Mpg]. It doesn't really do much yet, but I'm really proud of the bootstrap story. –  sblom May 28 '14 at 23:52
@sblom If you have a chance would you please share here? Yours has some functionality that my prototype does not. –  mfvonh Jun 4 '14 at 16:12

I'm not aware of any existing package manager. As to activity of Wolfram MathSource, let's ask Mathematica:

Select[
Import[
"http://library.wolfram.com/infocenter/search/?page=1;search_results=1;search_item_type=19&pages_count=100000",
],
StringMatchQ[#, RegularExpression[".*library.*"]] &
];

dates =
Function[{ll},
Cases[Import[ll,"Data"],
_String?(StringMatchQ[#,DatePattern[{"Year", "Month", "Day"}]] &),
Infinity]