PKG_ADD and package loading state when called

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

PKG_ADD and package loading state when called

apjanke-floss
Hi, Octave maintainers,

I'm working on adding a PKG_ADD file to one of my packages.

I notice that when the PKG_ADD file is called, the architecture-specific
directory of the package has been added to the Octave path, but the main
package directory has not. So PKG_ADD can't call any non-octfile
functions in the package. Is this expected?

I'm doing the detection by putting this in my PKG_ADD:

disp('Adding chrono package');
fprintf('pwd = %s\n', pwd);
disp('pkg list:')
pkg list
disp('Path:')
path


And my results:

octave:7> pkg load chrono
Adding chrono package
pwd = /Users/janke
pkg list:
Package Name   | Version | Installation directory
---------------+---------+-----------------------
        chrono *|   0.1.0 | /Users/janke/octave/chrono-0.1.0
generate_html  |   0.3.1 | /Users/janke/octave/generate_html-0.3.1
Path:

Octave's search path contains the following directories:

/Users/janke/octave/chrono-0.1.0/x86_64-apple-darwin17.7.0-api-v52
.
/Users/janke/Dropbox/computer/data/Documents/octave
/usr/local/Cellar/octave/4.4.1_5/share/octave/site/m
/usr/local/Cellar/octave/4.4.1_5/share/octave/site/m/startup
/usr/local/Cellar/octave/4.4.1_5/lib/octave/4.4.1/oct/x86_64-apple-darwin17.7.0
/usr/local/Cellar/octave/4.4.1_5/share/octave/4.4.1/m
[...]


After the package is loaded, both dirs are on the path:

octave:8> path

Octave's search path contains the following directories:

.
/Users/janke/octave/chrono-0.1.0
/Users/janke/octave/chrono-0.1.0/x86_64-apple-darwin17.7.0-api-v52
/Users/janke/Dropbox/computer/data/Documents/octave
/usr/local/Cellar/octave/4.4.1_5/share/octave/site/m
[...]



The documentation for PKG_ADD doesn't specify what the package loading
state will be when PKG_ADD and PKG_DEL are called.
https://octave.org/doc/v4.4.1/Creating-Packages.html#Creating-Packages.
Could that be added?

This is on Octave 4.4.1 on macOS 10.13.6.

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: PKG_ADD and package loading state when called

Mike Miller-4
On Fri, Jan 18, 2019 at 15:21:59 -0500, Andrew Janke wrote:
> I notice that when the PKG_ADD file is called, the architecture-specific
> directory of the package has been added to the Octave path, but the main
> package directory has not. So PKG_ADD can't call any non-octfile functions
> in the package. Is this expected?

Have you tried adding a PKG_ADD file to the "inst" directory?

I agree it's not very clearly documented, but PKG_ADD can exist in any
directory that gets added to the load path.

It's more of an implementation detail of both the 'pkg load' command and
the addpath function that the arch-specific directory is added to the
path first, followed by the arch-independent directory.

The ordering comes from the way that load_packages_and_dependencies
passes package dirs into the addpath function.

> The documentation for PKG_ADD doesn't specify what the package loading state
> will be when PKG_ADD and PKG_DEL are called.
> https://octave.org/doc/v4.4.1/Creating-Packages.html#Creating-Packages.
> Could that be added?

We could document that the arch-specific directory is added to the load
path first, followed by the arch-indep directory, and turn that detail
into an explicit documented design decision.

--
mike

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: PKG_ADD and package loading state when called

apjanke-floss


On 1/18/19 4:18 PM, Mike Miller wrote:
> On Fri, Jan 18, 2019 at 15:21:59 -0500, Andrew Janke wrote:
>> I notice that when the PKG_ADD file is called, the architecture-specific
>> directory of the package has been added to the Octave path, but the main
>> package directory has not. So PKG_ADD can't call any non-octfile functions
>> in the package. Is this expected?
>
> Have you tried adding a PKG_ADD file to the "inst" directory?

That worked. Thanks!

https://github.com/apjanke/octave-addons-chrono/commit/a94887230d24a418690f14efdc095aa03e0f5266

> I agree it's not very clearly documented, but PKG_ADD can exist in any
> directory that gets added to the load path.
>
> It's more of an implementation detail of both the 'pkg load' command and
> the addpath function that the arch-specific directory is added to the
> path first, followed by the arch-independent directory.
>
> The ordering comes from the way that load_packages_and_dependencies
> passes package dirs into the addpath function.
>
>> The documentation for PKG_ADD doesn't specify what the package loading state
>> will be when PKG_ADD and PKG_DEL are called.
>> https://octave.org/doc/v4.4.1/Creating-Packages.html#Creating-Packages.
>> Could that be added?
>
> We could document that the arch-specific directory is added to the load
> path first, followed by the arch-indep directory, and turn that detail
> into an explicit documented design decision.
>

This sounds like a good idea, since the PKG_ADD side effects are
dependent on it. If I find some time, I'll make a patch to add it to the
docs.

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: PKG_ADD and package loading state when called

Andreas Weber-6
In reply to this post by apjanke-floss
Am 18.01.19 um 21:21 schrieb Andrew Janke:
> I'm working on adding a PKG_ADD file to one of my packages.

Btw, almost all octave-forge packages don't provide their own separate
PKG_ADD file but use the PKG_ADD directive in their sourcode and let pkg
create the PKG_ADD on installation.

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: PKG_ADD and package loading state when called

apjanke-floss


On 1/19/19 5:36 AM, Andreas Weber wrote:
> Am 18.01.19 um 21:21 schrieb Andrew Janke:
>> I'm working on adding a PKG_ADD file to one of my packages.
>
> Btw, almost all octave-forge packages don't provide their own separate
> PKG_ADD file but use the PKG_ADD directive in their sourcode and let pkg
> create the PKG_ADD on installation.
>
> -- Andy
>

Thanks. I'll take a look at that, especially how their ordering works.
My PKG_ADD is big and gross, though -
https://github.com/apjanke/octave-addons-chrono/blob/ba95626d4f8eb12dd25b40792e1c722d1e0a3750/inst/PKG_ADD 
- so it'd either have to be standalone or wrapped up in a helper function.

Cheers,
Andrew