Message Boards Message Boards

0
|
8092 Views
|
7 Replies
|
6 Total Likes
View groups...
Share
Share this post:

[Solved] Function to access paclet resources?

Posted 3 years ago

Hello all,

So I have a sizeable paclet built. In my PacletInfo.m, I have created a Resource that points to a file in the Resources directory of my paclet. The resource extension looks like this:

Extensions -> 
    {
        {"Resource", 
            Resources->{{"FilePaths","Filepaths.txt"}}
        }
    }

I've seen various places on-line that I should be able to use a function called PacletResource["PacletName","FilePaths"] to access and open that file. However, that function seems to be missing. Mathematica doesn't recognize it and I can't find anything like it in the help system.

I have Mathematica 12.1 and the Paclet is installed in my user specific Paclets\Repository. I can use the Paclet and it works fine. I've tried loading "PacletManager'" and that function doesn't seem to be in there.

What am I missing?

Thanks

POSTED BY: Jeffery Henning
7 Replies

You can use

PacletManager`PacleResource["PacletName", "FilePaths"]

or the newer form

pObj["AssetLocation", "FilePaths"]

where pObj is the appropriate PacletObject representing the paclet.

POSTED BY: Ilian Gachevski

@Ilian Gachevski Thanks for that.

However, although the first form gives me no errors (that's better than I've been able to do on my own!), but it also gives no output.

In[6]:= PacletManager`PacletResource["PackletName", "FilePaths"]
(* No output here*)

In[7]:= FileExistsQ[PacletManager`PacletResource["PacletName", "FilePaths"]]

Out[7]= False

The second option doesn't do any better. I can correctly create the PacletObject, and get its information, but getting "AssetLocation" just repeats the command, like it is an unknown command.

In[7]:= PObj["AssetLocation", "FilePaths"]

Out[7]= PObj["AssetLocation", "FilePaths"]

Is this documented somewhere, or have I stepped into the outer limits? I can't find any documentation on PacletManager or it's functions.

I did manage to get this to work:

In[94]:= hString = Quiet@Import["PacletName\\Resources\\Filepaths.txt"]

Out[94]= "Contents of Filespatths.txt"

As long as

hString != $Failed

I think this will work. Would be nice to know why that paclet resource isn't working, though.

Thanks!

POSTED BY: Jeffery Henning

To clarify, by pObj, I meant the result of pObj = PacletObject["PacletName"] or, equivalently pObj = First[PacletFind["PacletName"]].

Getting Null for the PacletResource / AssetLocation means the asset does not exist in the paclet.

A possible reason for that is that the default asset Root is ., but in your case the file is placed in a subdirectory called Resources.

POSTED BY: Ilian Gachevski

@Ilian Gachevski

Got it. I was trying everything you said and it still wasn't working. Mathematica simply couldn't find my resource.

Turns out that Workbench (the latest version available to us mere mortals) is not keeping up with the current Mathematica paclet technology and wasn't properly installing the paclet (or registering the resources?).

I created a paclet archive and then did an "official" PacletInstall. Now both methods you gave me work perfectly.

Thank you!

POSTED BY: Jeffery Henning

By the way, a useful command to keep in mind is

https://reference.wolfram.com/language/ref/PacletDataRebuild.html

POSTED BY: Ilian Gachevski

I just wrote a function that will look for changes in paclets. It is very basic. The first time through, it makes a'reference' file of paclets on the system. Each subsequent time, it will look to see if there are any changes.

Eventually, I will have the function make a log, but for right now, I use BBEdit (on a mac -- similar apps on Windows or Linux) to do a diff.

Interestingly, the paclets on my MacBook Pro 16 are different from those on my new M1 MacBook Air. The installers for Mathematica were downloaded at different times, though. Since Mathematica on the MacBook Air is running using Rosetta, I thought that the paclets should be the same.

Attachments:

This works well. Thanks.

I found that if not deployed, I have to manually search the eclipse-workspace directory for this resource file when using Workbench in the Eclipse environment.

If I deploy to the App Data\RoamingMathematica\paclets\repository directory (Workbench wants to use the packages directory) then I can pick up the resources as well.

Thanks for the assistance!

POSTED BY: Jeffery Henning
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