Function Repository Resource:

Pacletize

Source Notebook

Create a paclet layout from a collection of files, symbols and contexts

Contributed by: Bob Sandheinrich

ResourceFunction["Pacletize"][name,content]

creates a Wolfram Language paclet from the specified content and returns the directory name.

ResourceFunction["Pacletize"][name, content, location]

stores the paclet in the specified directory.

Details and Options

The follow types of content are supported in a list:
File[]local file or directory containing code package files
"context`"context with symbol definitions
"name"symbol name with definitions
Contexts and symbols are included as in DumpSave.
ResourceFunction["Pacletize"][name,content] uses CreateDirectory[] to determine the paclet location.
The paclet can be activated temporarily using PacletManager`PacletDirectoryAdd and installed permanently with PacletManager`PacletInstall.
Symbols included directly in the content list will be turned into autoloading symbols.
By default, using Get or Needs on name` or any included contexts will load the paclet once it is added with PacletManager`PacletDirectoryAdd.
ResourceFunction["Pacletize"] only supports the "Kernel" paclet extension. Other extensions, like "FrontEnd", are not supported.
When location is given, it must not already exist. Any intermediate directories are created automatically.
The paclet created by ResourceFunction["Pacletize"] uses DumpSave to produce "MX" files. As such, there can be platform dependencies.

Examples

Basic Examples (2) 

Create a paclet from a function:

In[1]:=
HalfSquared[x_] := (x/2)^2
dir = ResourceFunction["Pacletize"]["HalfSquare", {"HalfSquared"}]
Out[1]=

Clear the local function definition and add register the paclet:

In[2]:=
Clear[HalfSquared];
PacletManager`PacletDirectoryAdd[dir];

The function will autoload the paclet and work:

In[3]:=
HalfSquared[10]
Out[3]=

Create a paclet layout in a specific location:

In[4]:=
DoubleSpooky[x_] := Nest[ResourceFunction["Spookify"], SpeechSynthesize[x], 2]
dir = ResourceFunction["Pacletize"]["DoubleSpooky", "DoubleSpooky", "ScaryStuff/SpookyPaclet"]
Out[4]=
In[5]:=
PacletDirectoryAdd[dir];

I made this on the spookiest day:

In[6]:=
Today -> DoubleSpooky@
  DateString[Today, {"DayName", " the " , "Day", "th"}]
Out[6]=

Scope (7) 

Using Contexts (5) 

Paclets can be defined for a context. First define symbols in a new context:

In[7]:=
AnimalConversations`BirdScream[str_String] := ResourceFunction["BirdSay"][Style[ToUpperCase[str <> "!!!"], 24]];
AnimalConversations`BirdWolfChat[l : {_String ...}] := Column@Flatten@Transpose[
      {ResourceFunction["BirdSay"] /@ #1,
       ResourceFunction["WolfieSay"] /@ #2}] & @@ Transpose[Partition[l, 2, 2, 1, ""]]

Create the paclet directory:

In[8]:=
dir = ResourceFunction["Pacletize"]["AnimalConversations", "AnimalConversations`"]
Out[8]=

Clear the local definitions and add the paclet:

In[9]:=
ClearAll["AnimalConversations`*"];
PacletManager`PacletDirectoryAdd[dir];

Getting the context will load the paclet:

In[10]:=
<< AnimalConversations`;

The code is defined:

In[11]:=
AnimalConversations`BirdScream["squawk"]
Out[11]=
In[12]:=
AnimalConversations`BirdWolfChat[{"Hi Wolfie", "Good day Birdnardo, howl are you?", "Cool as can be", "Huzzah!"}]
Out[12]=

Using Files and Directories (2) 

Store some code and data in a package file:

In[13]:=
bostondata = Normal@ResourceData["Sample Data: Boston Homes"];
BostonOldHomeCount[age_] := Length[Select[bostondata, #AGE > age &]];
DumpSave["bostonstuff.wl", {BostonOldHomeCount, bostondata}];

Create a paclet directory including that file:

In[14]:=
dir = ResourceFunction["Pacletize"][
   "BostonHouses", {File["bostonstuff.wl"]}];

Clear the definitions and add the paclet directory:

In[15]:=
Clear[bostondata, BostonOldHomeCount];
PacletManager`PacletDirectoryAdd[dir];

Load the paclet context:

In[16]:=
<< BostonHouses`
In[17]:=
BostonOldHomeCount[90]
Out[17]=

Create a directory with many code files:

In[18]:=
codedir = CreateDirectory[];
In[19]:=
With[{symb = Symbol[#]},
   symb[] = RandomReal[];
   DumpSave[FileNameJoin[{codedir, # <> ".mx"}], symb]] & /@ {"a", "b", "c", "d", "e"}
Out[19]=

Create a paclet directory including those files:

In[20]:=
dir = ResourceFunction["Pacletize"]["LetterFuncs", {File[codedir]}];

Clear the definitions and add the paclet directory:

In[21]:=
Clear[a, b, c, d, e];
PacletManager`PacletDirectoryAdd[dir];

Load the paclet context:

In[22]:=
<< LetterFuncs`
In[23]:=
{a[], b[], c[], d[], e[]}
Out[23]=

Properties and Relations (1) 

The created paclet directory contains several files:

In[24]:=
TwiceSquared[x_] := (2 x)^2
dir = ResourceFunction["Pacletize"]["TwiceSquared", {"TwiceSquared"}, FileNameJoin[{"mypaclets", "basedir"}]];
FileNames["*", dir, Infinity]
Out[24]=

Version History

  • 1.0.0 – 26 September 2019

Related Resources

License Information