Message Boards Message Boards

Create and deploy your own paclets in the Workbench

References

enter image description here

Eclipse work flow

If necessary, install the Wolfram WorkBench Plugin for Eclipse.

http://support.wolfram.com/kb/27221

In Windows - Preferences - Wolfram - Special make the following changes

enter image description here

Apply and press OK. Then re-open preferences and go to Paclet Development. Enable function paclet support.

enter image description here

Create a new application project

enter image description here

enter image description here

Open the PacletInfo.m file and useful buttons now appear.

enter image description here

Also edit your project properties or the nice buttons may vanish after a build or when you close the project.

enter image description here

Build

Build your project and documentation as usual and then create your Paclet file and deploy.

Install

You can install from a local file path, http or ftp as print definitions reveals.

PacletInstall[filepath]
Needs["GeneralUtilities`"]
PrintDefinitions["PacletInstall"]
PrintDefinitions["PacletManager`Manager`Private`installPacletFromFileOrURL"]

There is no current support for https but this can be patched or you can easily call PacletInstall after downloading and creating a new file name for the download. This could be handy if you wanted to install from GitHub.

POSTED BY: Emerson Willard
10 Replies

Thank you for this tutorial.

.paclet files can also be created without using the Workbench. While GUI tools can be convenient, it is often useful to understand what they do exactly. Scripts and configuration files provide a level of reproducibility that GUIs cannot. All the following information is from inspecting GitLink, and I am going to demonstrate it using MaTeX (which I'm using to experiment with these things). This is far from the complete story, but it's sufficient to package up application as a paclet.


Also posted on Mathematica.SE.


Introduction

.paclet files appear to be simply zip files that can contain a Mathematica package or other extensions to Mathematica, along with some metadata in a PacletInfo.m. The metadata makes it possible to manage installation, uninstallation and update automatically.

How to add the required metadata?

First make sure that your package is following the standard directory structure.

Then create a PacletInfo.m file in the package root with a minimum amount of metadata. Make sure the Name and Version are present. For MaTeX I could start e.g. with this:

Paclet[
    Name -> "MaTeX",
    Version -> "1.6.2",
    MathematicaVersion -> "10.0+",
    Description -> "Create LaTeX-typeset labels within Mathematica.",
    Creator -> "Szabolcs Horvát"
]

This is sufficient to make it possible to pack and install a paclet. But it is not sufficient for making it loadable with Needs. For that we need to add the "Kernel" extension:

Paclet[
    Name -> "MaTeX",
    Version -> "1.6.2",
    MathematicaVersion -> "10.0+",
    Description -> "Create LaTeX-typeset labels within Mathematica.",
    Creator -> "Szabolcs Horvát",
    Extensions -> 
        {
            {"Kernel", Root -> ".", Context -> "MaTeX`"}
        }
]

The two critical arguments to the `"Kernel"`` extension are:

  • Context sets the context of the package. Whatever you put here will be recognized by Needs and FindFile, but ideally it should also be compatible with the package name and the standard file name resolution.

  • Root sets the application root. FindFile seems to resolve the context to a path through this, but also following the standard rules.

Of course you can also add the "Documentation" extension to integrate with the Documentation Centre, but that is not required for the functionality I describe here.

How to bundle a package into a .paclet file?

Simple use the PackPaclet function on the application directory. It will use the information from PacletInfo.m. It is a good idea to remove any junk files and hidden files to avoid them from getting packed up.

Warning: Before doing this, make a copy of the application directory. Don't accidentally delete any files used by your version control system.

After making a copy of the package directory, in my case called MaTeX I did this:

Make sure we're in the parent directory of the application directory:

In[2]:= FileNames[]
Out[2]= {".DS_Store", "MaTeX"}

Delete any junk files like `.DS_Store (which macOS likes to create):

In[4]:= DeleteFile /@ FileNames["*.", "MaTeX", Infinity]

Create .paclet file:

In[5]:= PackPaclet["MaTeX"]
Out[5]= "/Users/szhorvat/Desktop/pacletbuild/MaTeX-1.6.2.paclet"

Install it permanently:

In[6]:= PacletInstall[%]
Out[6]= PacletManager`Paclet[
"Name" -> "MaTeX", "Version" -> "1.6.2", 
 "MathematicaVersion" -> "10.0+", 
 "Description" -> "Create LaTeX-typeset labels within Mathematica.", 
 "Creator" -> "Szabolcs Horvát", 
 "Extensions" -> {{"Kernel", "Root" -> ".", "Context" -> "MaTeX`"}}, 
 "Location" -> "/Users/szhorvat/Library/Mathematica/Paclets/Repository/MaTeX-1.6.2"]

Multiple versions may be installed at the same time. Finds all installed versions using:

In[7]:= PacletFind["MaTeX"]
Out[7]= {
PacletManager`Paclet[
 "Name" -> "MaTeX", "Version" -> "1.6.2", 
  "MathematicaVersion" -> "10.0+", 
  "Description" -> "Create LaTeX-typeset labels within Mathematica.", 
  "Creator" -> "Szabolcs Horvát", 
  "Extensions" -> {{"Kernel", "Root" -> ".", "Context" -> "MaTeX`"}}, 
  "Location" -> "/Users/szhorvat/Library/Mathematica/Paclets/Repository/MaTeX-1.6.2"]}

FindFile (and therefore also Needs) will always resolve to the latest version:

In[8]:= FindFile["MaTeX`"]
Out[8]= "/Users/szhorvat/Library/Mathematica/Paclets/Repository/MaTeX-1.6.2/Kernel/init.m"

Uninstall all versions:

In[9]:= PacletUninstall /@ PacletFind["MaTeX"]
Out[9]= {Null}

How to work with paclets during development

During development we don't want to pack the paclet and install it after every change. It is much more convenient to be able to load it directly from the development directory.

I can do this by adding the parent directory of the application directory (i.e. MaTeX in the above example) as a paclet directory. Since I keep the development version of MaTeX in ~/Repos/MaTeX-wb/MaTeX, I can simply use

PacletDirectoryAdd["~/Repos/MaTeX-wb"]

After this Needs["MaTeX`"] will load the dev version.

POSTED BY: Szabolcs Horvát

I started a community project at StackExchange to document what can go into PacletInfo.m. I see that you are also interested in the same topic. All contributions will be most welcome! Please feel free to edit the community wiki answer there.

POSTED BY: Szabolcs Horvát

Thanks

POSTED BY: Emerson Willard

@Emerson Willard Thanks for this tutorial. I followed your steps, and the documentation installs properly... but MMA isn't finding my package:

enter image description here

I'd rather not have to do this manually:

enter image description here

So is there some missing step?

Here's what the project looks like (it's just the template application project) setup:

enter image description here

POSTED BY: Michael Sollami

You'd need to show your PacletInfo.m file for people to be able to comment.

POSTED BY: Szabolcs Horvát

@Szabolcs Horvát Thanks, just updated it.

POSTED BY: Michael Sollami

Make sure your Kernel extension look like this:

{"Kernel", Root -> ".", Context -> "pacman`"}
POSTED BY: Szabolcs Horvát

I added that and updated my screenshot (above), and clicked "create paclet"... @Szabolcs Horvát

enter image description here

but still same behavior (can't find it) when I load:

enter image description here

The documentation does work though, although a restart of Mathematica is necessary.

POSTED BY: Michael Sollami

I'm not sure why, but I can see that you changed several things compared to what I described on StackExchange. Why don't you try to follow the instructions there exactly for now, and without using the Workbench for the moment, and try a minimal package?

I don't know what kind of package structure the Workbench created for you. There's a link in that post to the standard package structure.

POSTED BY: Szabolcs Horvát

@Szabolcs Horvát Thanks for your response, I got it working by studying your Matex package and duplicating the structure there.

POSTED BY: Michael Sollami
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