Wolfram Research

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.
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

Create a paclet from a function:

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

Clear the local function definition and add register the paclet:

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

The function will autoload the paclet and work:

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

Create a paclet layout in a specific location:

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

I made this on the spookiest day:

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

Scope

Using Contexts

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

In[9]:=
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[10]:=
dir = ResourceFunction["Pacletize"]["AnimalConversations", "AnimalConversations`"]
Out[10]=

Clear the local definitions and add the paclet:

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

Getting the context will load the paclet:

In[12]:=
<< AnimalConversations`;

The code is defined:

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

Using Files and Directories

Store some code and data in a package file:

In[15]:=
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[16]:=
dir = ResourceFunction["Pacletize"][
   "BostonHouses", {File["bostonstuff.wl"]}];

Clear the definitions and add the paclet directory:

Load the paclet context:

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

Create a directory with many code files:

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

Create a paclet directory including those files:

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

Clear the definitions and add the paclet directory:

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

Load the paclet context:

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

Properties and Relations

The created paclet directory contains several files:

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

Resource History

Related Resources

License Information