Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A question regarding pkg_mkIndex and namespace imports

57 views
Skip to first unread message

Gerhard Reithofer

unread,
Mar 27, 2017, 5:38:27 PM3/27/17
to
Hi TCLers,
I think I did not have this problem in older versions but I'm sure about
that.

I have a standard development package with tools (like debug routines,
etc.) called AppUtil. It is required in all development projects.

In scan_code.tcl I have the statements:

package require AppUtil
namespace import AppUtil::Debug AppUtil::GetConfig AppUtil::SetConfig
package provide ScanLib 0.1

namespace eval ScanLib {
variable ResultBuffer
...
proc do_di_scan {dev_name} {
...
}

}

No I faced the problem that I can't create a package index if I try to
import my AppUtil::* functions, I get the following error message (it is
called warning here):

% pkg_mkIndex -verbose lib/modules *.tcl
warning: error while sourcing scan_code.tcl: unknown namespace in import pattern "AppUtil::Debug"

... and the scan_code.tcl package is NOT included into the package
index.

If I remove the "namespace import AppUtil::Debug" all works as expected.

% pkg_mkIndex -verbose lib/modules *.tcl
successful sourcing of scan_code.tcl
packages provided were {ScanLibrary 0.1}
processed scan_code.tcl

I can add again the namespace import after creating the package index
and everything works without problems either.

$ tclsh
% package require ScanLibrary
0.1
% AppUtil::SetConfig
wrong # args: should be "AppUtil::SetConfig key ?arg ...?"

The last error message shows that the AppUtill package is sourced
correctly.

Now my questions are:
1. Is this an inteded behavior?
2. What am I doing wrong?
3. How to circumvent this problem (maybe answered with 2.)

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(engine) = Tcl
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
tcl_platform(osVersion) = 4.9.0-2-amd64
tcl_platform(pathSeparator) = :
tcl_platform(platform) = unix
tcl_platform(pointerSize) = 8
tcl_platform(threaded) = 1
tcl_platform(user) = gerhard
tcl_platform(wordSize) = 8
% info patchlevel
8.6.6

Bye,
Gerhard

--
Gerhard Reithofer - Techn. EDV Reithofer - http://www.tech-edv.co.at

Robert Heller

unread,
Mar 27, 2017, 6:31:52 PM3/27/17
to
I think so.

> 2. What am I doing wrong?

Nothing obvious.

> 3. How to circumvent this problem (maybe answered with 2.)

A) Put a catch around the namespace import
OR
B) Include this line just before the namespace import:

namespace eval AppUtil {}

>
> % parray tcl_platform
> tcl_platform(byteOrder) = littleEndian
> tcl_platform(engine) = Tcl
> tcl_platform(machine) = x86_64
> tcl_platform(os) = Linux
> tcl_platform(osVersion) = 4.9.0-2-amd64
> tcl_platform(pathSeparator) = :
> tcl_platform(platform) = unix
> tcl_platform(pointerSize) = 8
> tcl_platform(threaded) = 1
> tcl_platform(user) = gerhard
> tcl_platform(wordSize) = 8
> % info patchlevel
> 8.6.6
>
> Bye,
> Gerhard
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Matthew Hiles

unread,
Mar 28, 2017, 8:23:06 AM3/28/17
to
Are the procs you're trying to import exported? I believe you can only import exported procs.

Relevant man page excerpt for namespace import:

"All the commands that match a pattern string and which are currently exported from their namespace are added to the current namespace."

Robert Heller

unread,
Mar 28, 2017, 9:27:36 AM3/28/17
to
The error message is that the *namespace does not exist*. pkg_mkIndex sources
the Tcl file, but does not actually evaluate the package require -- the
AppUtil code does not actually get loaded. This means that the AppUtil
namespace does not get created. pkg_mkIndex simularly will barf on any Tk
code when pkg_mkIndex is run from bare tclsh. You need to put catches around
that or else *manually* create the pkgIndex.tcl file. This also applies to
certail sorts of binary extensions. The OP can either put a catch around the
namespace import OR create the namespace using an empty namespace eval.

>
> Relevant man page excerpt for namespace import:
>
> "All the commands that match a pattern string and which are currently
> exported from their namespace are added to the current namespace."
>

Yes, but this won't actually raise an error if the commands are not exported.

Don Porter

unread,
Mar 28, 2017, 10:03:02 AM3/28/17
to
On 03/28/2017 09:27 AM, Robert Heller wrote:
> The error message is that the *namespace does not exist*. pkg_mkIndex sources
> the Tcl file, but does not actually evaluate the package require -- the
> AppUtil code does not actually get loaded. This means that the AppUtil
> namespace does not get created. pkg_mkIndex simularly will barf on any Tk
> code when pkg_mkIndex is run from bare tclsh.

This situation is what the "-load" option of the [pkg_mkIndex] command
is for. For indexing Tk, start in an interp that already has Tk loaded.
Either wish, or tclsh after a successful [package require Tk]. Then

pkg_mkIndex -load Tk ...

so that the Tk package is also in the custom interpreter that
does the indexing.

> You need to put catches around
> that or else *manually* create the pkgIndex.tcl file.

Honestly this is almost always the best plan. [pkg_mkIndex] only works
at all in simply structured packages, and in such simple cases, just
writing the index script yourself (or via autoconf substitution) is
a more direct, effective solution. This is a case where the tool gets
in the way more often than it helps.

--
| Don Porter Applied and Computational Mathematics Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Gerhard Reithofer

unread,
Mar 28, 2017, 7:03:14 PM3/28/17
to
Hi Robert,

On Mon, 27 Mar 2017, Robert Heller wrote:

> At Mon, 27 Mar 2017 23:37:15 +0200 Gerhard Reithofer <gerhard....@tech-edv.co.at> wrote:

...

> > No I faced the problem that I can't create a package index if I try to
> > import my AppUtil::* functions, I get the following error message (it is
> > called warning here):
> >
> > % pkg_mkIndex -verbose lib/modules *.tcl
> > warning: error while sourcing scan_code.tcl: unknown namespace in import pattern "AppUtil::Debug"
> >
> > ... and the scan_code.tcl package is NOT included into the package
> > index.

...

> > Now my questions are:
> > 1. Is this an inteded behavior?
>
> I think so.

at least it looks strange to me.
The command "warns" and refuses the requested functionality. I
personally would call this an error and display an "error message".

> > 2. What am I doing wrong?
>
> Nothing obvious.
>
> > 3. How to circumvent this problem (maybe answered with 2.)
>
> A) Put a catch around the namespace import
> OR
> B) Include this line just before the namespace import:
>
> namespace eval AppUtil {}

Thanks, both work :-)

Gerhard Reithofer

unread,
Mar 28, 2017, 7:03:14 PM3/28/17
to
Hi Robert,

On Tue, 28 Mar 2017, Robert Heller wrote:
> At Tue, 28 Mar 2017 05:23:01 -0700 (PDT) Matthew Hiles <matthe...@gmail.com> wrote:
> >
> > On Monday, March 27, 2017 at 5:38:27 PM UTC-4, Gerhard Reithofer wrote:

...

> The error message is that the *namespace does not exist*. pkg_mkIndex sources
> the Tcl file, but does not actually evaluate the package require -- the
> AppUtil code does not actually get loaded. This means that the AppUtil

...

Are you sure?
The error message: wrong # args: should be "AppUtil::SetConfig key ?arg
...?" seem to prove that the package is loaded.

$ tclsh
% AppUtil::SetConfig
invalid command name "AppUtil::SetConfig"
% package require ScanLibrary
can't find package ScanLibrary
0.1
% AppUtil::SetConfig
wrong # args: should be "AppUtil::SetConfig key ?arg ...?"

"Someone" loads the package and the only executed command is "package
require ScanLib".

> namespace does not get created. pkg_mkIndex simularly will barf on any Tk
> code when pkg_mkIndex is run from bare tclsh. You need to put catches around
> that or else *manually* create the pkgIndex.tcl file. This also applies to
> certail sorts of binary extensions. The OP can either put a catch around the
> namespace import OR create the namespace using an empty namespace eval.

catch and namespace eval works as confirmed in my previous mail.

Gerhard Reithofer

unread,
Mar 29, 2017, 6:08:06 AM3/29/17
to
Hi,
sorry too late :-(

On Wed, 29 Mar 2017, Gerhard Reithofer wrote:

> Hi Robert,
>
> On Tue, 28 Mar 2017, Robert Heller wrote:
> > At Tue, 28 Mar 2017 05:23:01 -0700 (PDT) Matthew Hiles <matthe...@gmail.com> wrote:
> > >
> > > On Monday, March 27, 2017 at 5:38:27 PM UTC-4, Gerhard Reithofer wrote:

...

> $ tclsh
> % AppUtil::SetConfig
> invalid command name "AppUtil::SetConfig"
> % package require ScanLibrary

... the following wrong line should be removed

> can't find package ScanLibrary

...

> 0.1
> % AppUtil::SetConfig
> wrong # args: should be "AppUtil::SetConfig key ?arg ...?"
>
> "Someone" loads the package and the only executed command is "package
> require ScanLib".

Bye,
Gerhard
0 new messages