Package Usage and Development » Paclet Development
We can distribute paclets in either of two ways. We can distribute a packed .paclet file directly or distribute via a server.
Whichever route we go, though, we'll first need the .paclet file.
Creating a .paclet File
To create a .paclet file we use the
PackPaclet function in the
"PacletManager`" context. We can call it one of two ways:
PackPaclet[dir]— creates a packed .paclet file from
dirand places it in
PackPaclet[dir, dest]— creates a packed .paclet file from
dirand places it in
Say, for the sake of argument, that I am Etienne Bernard and write the Machine Learning functionality packaged into Mathematica. I can find my paclet directory like
dir = PacletFind["MachineLearning"][]["Location"]
Then this can be packed into a .paclet file like:
paclet = PackPaclet[dir, $TemporaryDirectory]
And now this can be distributed
Once a paclet is packed it can be distributed directly as it. For instance, I can put this in on my Wolfram Cloud account:
CopyFile[ paclet, CloudObject["user:b3m2a1.testing/MachineLearning.paclet", Permissions->"Public"] ]//Most
And now anyone could come along and install this with:
Often we want something a little more sophisticated, though.
Paclet servers exist to make it easy to serve many paclets from the same location. The
PacletManager indexes all the paclet servers available to it and figures out where to install paclets from if simply provided with a name. Therefore it's useful for us to be able to set up our own servers.
To do this we simply need to add a
Paclets directory to our server and provide a compressed metadata file
PacletSite.mz . Overall our server will look like:
Server PacletSite.mz Paclets Paclet1-version1.paclet Paclet1-version2.paclet Paclet2-version1.paclet ...
The paclet manager indexes the paclets on the server by looking at
PacletSite.mz , which is much like a
PacletInfo.m file, except instead of containing a single
Paclet expression it contains a
PacletSite expression that bundles up a bunch of different
In all it'll look like:
PacletSite[ Paclet[ Name->"MyPaclet1", ... ], Paclet[ Name->"MyPaclet2", ... ], ... ]
Then this gets written to a file as an expression and ZIP compressed.
In general we don't need to handle this ourselves, though, as there's a function in the
PacletManager that does this. If we call
PacletManager`Package`BuildPacletSiteFiles on our target directory it will do this for us.
For instance, I could call:
And all of the files in the
Paclets sub-folder will get indexed into a
Setting Up a Paclet Server
Once the construction is done locally, the server should be served over HTTP if possible. Older versions of the
PacletManager failed to deal appropriately with HTTPS content.
I tend to serve mine via the Wolfram Cloud or GitHub.