CreatePackageCache / AutoloadPackage
CreatePackageCache
is called as
Package`CreatePackageCache[
pkgContext,
pkgDir,
Package`AutloadPackage->boolean]
Where pkgContext
is a package context declared in the new-style (so that it's possible to find via PackageInformation
).
What this does is dumps what is presumably the package data to a .mx file in the pkgDir
. If AutoloadPackage
is specified it seems to load the package before dumping.
DeclareLoad / ActivateLoad / HiddenImport / ExportedContexts
Package`DeclareLoad
is called as
Package`DeclareLoad[
{symbols},
context,
Package`HiddenImport->boolean,
Path->pathspec,
Package`ExportedContexts->{contexts}]
it configures autoloading by setting
Package`ActivateLoad[
symbol,
{symbols},
context,
{Package`HiddenImport->boolean, Path->pathspec}
]
on each symbol
in symbols
, which in turn clears the OwnValues
(and maybe the other *Values
) of all the symbols
and then loads the context by a Get
like mechanism, searching in Path
. Note that Package`ActivateLoad
can be called on its own.
Still working out what happens to Package`ExportedContexts
...
PackageInformation / LoadPackage / ForceLoad
Package`PackageInformation
is used to get package information for packages declared in the new style. Package`ForceLoad
is used by Package`PackageInformation
to specify whether to load the package or not.
Package`LoadPackage
loads these new-style packages, but not old-style one.
Spelunking Updates
Long Form
Update 5
PackageImport
, PackageScope
, and PackageExport
all live in the PackageDirectives
context which is presumable initialized by LoadPackage
Update 4
Figured out how to use CreatePackageCache
based on knowing there are new-style declarations. Note that there must be PackageInformation
for pkgContext
otherwise your kernel will crash (or at least it has for me).
One oddity is that even though it creates the .mx file, it doesn't seem to be exporting the definitions for my symbols... Need to check this out.
Update 3
There is another symbol, PackageImport
which works like PackageExport
except it imports the package. One thing worth noting about these new-style packages is that it seems their init files always call BeginPackage
and EndPackage
still.
Update 2
By running PackageInformation/@Contexts[]
I found that there is a new package declaration style as visible in the Macros`
, Iconize`
, and TextSearch`
packages.
I made my a package stub in this style:
Package["TestPKG`"]
PackageScope["blumpf"]
PackageExport["Blah"]
PackageExport["Blah2"]
And by saving this so somewhere included in $Path
I could use PackageInformation
on this too (although I had to allow ForceLoad
. It also works with LoadPackage
in a way that packages declared in the old style do not.
PackageExport
puts the symbol into toplevel usage. PackageScope
is the new Private
. We can find more symbols like this by searching for Names["*`PackageScope`*"]
after running Get/@Contexts[]
Need to do more searching for the symbols, but I think I'll start in these contexts.
Update 1
Package`DeclareLoad
seems to be the main usage function. It takes a set of symbols that are prepped to autoload a set of packages. The loads can be "hidden" via Package`HiddenImport
which just means the contexts don't get added to the $ContextPath
it seems.
It can also take extra contexts to export via Package`ExportedContexts
and a path to look for the package on (default Automatic
).
This just configures Package`ActivateLoad
in the OwnValues
of the symbols, which simply acts as a fancy Get
mechanism.
It looks like:
Package`ActivateLoad[loadMyTools,
{loadMyTools},
"MyTools`",
{Package`HiddenImport -> True, Path -> Automatic}]
for example. The second argument are all the other symbols declared in the same DeclareLoad
the third is the set of packages, etc. Pretty clear.
Here are the places I've searched so far, so that others can look through them too:
$InstallationDirectory/SystemFiles/Components/MXNetLink/*.m
$InstallationDirectory/SystemFiles/Components/NeuralNetworks/*.m
$InstallationDirectory/SystemFiles/Components/Iconize/*.m
$InstallationDirectory/SystemFiles/Components/Macros/*.m
$InstallationDirectory/AddOns/Applications/Parallel/Kernel/sysload.m
$InstallationDirectory/SystemFiles/Autoload/PacletManager/Kernel/Documentation.m
$InstallationDirectory/SystemFiles/Autoload/PacletManager/Kernel/Manager.m
$InstallationDirectory/SystemFiles/Kernel/SystemResources/MacOSX-x86-64/sysinit.m