Message Boards Message Boards

0
|
7384 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Native InstallPackage Function in Mathematica

Posted 8 years ago

It would be nice if Mathematica had a native InstallPackage function, similar to what R does. Today I see packages like https://github.com/zbjornson/MongoDBLink, that needs commands like:

tmp = URLSave["https://github.com/zbjornson/MongoDBLink/archive/master.zip"];
dest = FileNameJoin[{$AddOnsDirectory, "Applications"}];
ExtractArchive[tmp, dest];
RenameDirectory[FileNameJoin[{dest, "MongoDBLink-master"}], FileNameJoin[{dest, "MongoDBLink"}]];
DeleteFile[tmp];
Print["Installed MongoDBLink to " <> dest]

to be installed. It would be nice to have something like:

InstallPackage["https://github.com/zbjornson/MongoDBLink/"]

to do that Job, together with an official Wolfram Package specification with best design practices to work with the function.

The function do not need to be specific to GitHub, Git could be just the first overload. I could use Wolfram Cloud as another option. It would be a cool way to exchange code.

POSTED BY: Rodrigo Murta
8 Replies

I think you made some good points Rodrigo. Here is my attempt at a routine along that line.

InstallMathematicaApplication::usage = 
  "InstallMathematicaApplication[\"URL\"] will download and install \
the application zip file located at the URL address into your \
$UserBaseDirectory/Applications folder. The installation path to the \
first item installed, which will usually be the application folder, \
is printed.";
SyntaxInformation[
   InstallMathematicaApplication] = {"ArgumentsPattern" -> {_}};
InstallMathematicaApplication[URLLink_String] :=
 Module[{modifiedURL, tempFile, application},
  modifiedURL = StringReplace[URLLink, "?dl=0" -> "?dl=1"];
  tempFile = URLSave[modifiedURL,
    FileNameJoin[{$UserBaseDirectory, "Applications", 
      "ApplicationDownload.zip"}]];
  application = 
   ExtractArchive[tempFile, 
     FileNameJoin[{$UserBaseDirectory, "Applications"}]][[1]];
  DeleteFile[tempFile];
  Print["Application installed at: ", application]
  ]

It is specialized to installing zip files into the `$UserBaseDirectory/Applications folder. But there is one problem with the ExtractArchive command. It will fail if any existing files exist. So one can't use it to update. As far as I'm concerned WRI should fix that, perhaps using an option. Right now I'm supplying my packages from Dropbox. If one creates a user link for a zip file, Dropbox ends it with ?dl=0. ExtractArchive will not work on that. So I change it to ?dl=1 in the routine.

Here is a test case you can try. It contains a rather worthless stub application I abandoned. So you could delete it after the test.

InstallMathematicaApplication["https://www.dropbox.com/s/\
kin3ajodnys92n8/ConicSections.zip?dl=0"]

`

That is not hard to code. Check out e.g.

Import["https://raw.githubusercontent.com/FeynCalc/feyncalc/master/install.m"]
InstallFeynCalc[]

or

Import["http://www.mertig.com/shortcuts.m"]

But yes, of course WRI should provide some native way of doing this. And more. Like an improved WorkBench with debugger and profiler and installer and so on.

POSTED BY: Rolf Mertig

Wolfram Research has set up a quite adequate method for writing and using packages or applications, but they have done a poor job of communicating it.

These should probably be called 'applications' rather than 'packages' because an application may contain several or no packages, and it can contain other components besides packages, such as documentation, style sheets, palettes and application notebooks. It is very easy for a potential user to install an application. Just send them a zip file that they unzip directly into their $UserBaseDirectory/Applications folder. That's it. Unzip and immediately use it.

I've written an extensive tutorial on writing applications at A Mathematica Style.

Hi David, tks for share your material,

I believe the main point is to simplify this operation, like what R does. Today in Mathematica as you stated, you have to:

  • 1 - Go to a website to download the file
  • 2 - Put in the right place
  • 3 - Unzip if necessary

or create your own functions to do that, that is not a simple thing for new users, or for install a package for 30 students in a class.

This could be simplified for: InstallPackage["https://github.com/zbjornson/MongoDBLink/"]

It's would be very convenient if you have to install a lot of packages, or batch update for a new version.

I would go even further and suggest a Wolfram Application Repository (WAR). So, you could submit your Package/Application to it, and install with a simples: InstallPackage["myApplication"], just like what R does.

POSTED BY: Rodrigo Murta

One issue is that some Mathematica applications are free, while others are proprietary. Thus a single "Wolfram Application Repository" could not cover all the applications one might one to use.

Another issue is that some applications, particularly some older ones, were not designed for such straightforward "plug-and'play": some were designed as single .m files that are supposed to be dumped directly into the root $UserBaseDirectory/Applications folder; for others, the context name might not match the name of the folder you get when you unzip the download.

There's a fairly standard way of handling such applications. Say the (main) package begins BeginPackage["MyApp`"].

  • Name the .m package file MyApp.m
  • Name MyApp the folder into which everything for the application gets placed
  • Create a subfolder MyApp/Kernel
  • In that subfolder place a file init.m containing just: Get["MyApp`MyApp`"]

That procedure allows loading the application with a simple <<MyApp`

Of course some applications that involve many packages must use a somewhat more complicated scheme, but that shows the basic idea.

POSTED BY: Murray Eisenberg

Community software masses up my post. I'll try later

I believe that you can already do this within Wolfram Language. All you need to do is to build (or find) a package (a .m or .wl file) and save it to the appropriate directory. On the desktop, there is the $UserBaseDirectory that will work, although saving into the Applications folder/directory inside this directory is probably better. For the Cloud, there must be an analogous place to store packages.

You could probably write your own function, installPackage[], that will do exactly what you want to do.

I know I can create a package to do that, but the suggestion is to simplify this operation in a native way. R is very famous for it simple way to install a new package, I use it, and I miss something equivalent in WL.

POSTED BY: Rodrigo Murta
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract