qutil icon indicating copy to clipboard operation
qutil copied to clipboard

init.q optional in one-file package

Open danielkrizian opened this issue 3 years ago • 1 comments

In a lean package with just a single file, there is no need for the boilerplate overhead of init.q. At least, init.q should be optional, not mandatory.

$ ls $QPATH/my-1.0.0
my.q
$ cat $QPATH/my-1.0.0/my.q
\d .my

This conditional statement: https://github.com/nugend/qutil/blob/2bce9deb5585f7166052bfb81012b8d897fedeeb/lib/bootstrap.q#L17

will resolve to false even for single-file directory:

q) key pkgInfo`file 
,my.q
q) not 11h ~ type key pkgInfo`file
0b

Was it intended?

I propose changing the line to:

file:` sv f,$[f~k:key f:pkgInfo`file;();1=count k;first k;`init.q];

That will nicely cover all scenarios:

q).utl.require"my/my.q"    / file loading scenario
q).utl.require"my"         / dir loading scenario; supports single-file dir with or without init.q

danielkrizian avatar Dec 05 '20 13:12 danielkrizian

Hm. You know I don't know if I completely remember the reasoning for doing it just this way. I think I was just emulating what Python packages did since I like most of how namespace resolution works in Python 3.

Could you file a PR with a test?

nugend avatar Aug 12 '21 05:08 nugend