Importing a Namespace Failing to Import Namespace?? 
Author Message
 Importing a Namespace Failing to Import Namespace??

Ok, this is driving me nuts maybe someone can help me where to look.

I've got a package i have written, really simple at this point in time.
The package properly imports into an interactive wish interpreter with
the addtion of set auto_path [linsert $auto_path 0 .] in the .wishrc to
include the working directory.  namespace import properly pulls the one
exported command into the global namespace so I can access it without
qualifying it.

This all works, until I import the package in a script.  If I include the
auto_path line in the script, it will find the package in working directory,
but the namespace import wizard::* fails silently.  When it reaches the
unqalified wizard command, it dies with an "invalid command name
'wizard'".  The script functions just fine with the qualified name of the
exported command, wizard::wizard.  

So ... what am I missing, where should I look, what do I need to post in
order to make my self clear?  

As an aside, I am trying to write a wizard widget, and not using Tix or
Itcl (learning curve and time constraints) or any other OOP extensions,
which this seems to desperately cry out for.  Anyone know of any pure TCL
implementations out there that I might be able to use as a reference?

TIA
Matt

--
Matthew Micene
Systems Development Manager
Express Search Inc.
www.ExpressSearch.com



Tue, 08 Apr 2003 03:00:00 GMT  
 Importing a Namespace Failing to Import Namespace??

Quote:

> Ok, this is driving me nuts maybe someone can help me where to look.

> I've got a package i have written, really simple at this point in time.
> The package properly imports into an interactive wish interpreter with
> the addtion of set auto_path [linsert $auto_path 0 .] in the .wishrc to
> include the working directory.  namespace import properly pulls the one
> exported command into the global namespace so I can access it without
> qualifying it.

> This all works, until I import the package in a script.  If I include the
> auto_path line in the script, it will find the package in working directory,
> but the namespace import wizard::* fails silently.  When it reaches the
> unqalified wizard command, it dies with an "invalid command name
> 'wizard'".  The script functions just fine with the qualified name of the
> exported command, wizard::wizard.

The namespace import isn't really failing silently.  I believe what is
happening is that your package is loading lazily.  That means when you
first package require it, it tell the auto_load mechanism where the
procs can be found - but it doesn't actually define them until first
use.  namespace import doesn't actually use them, so when you call it,
those procs don't yet exist.

The solution is to make sure you use -direct when making the package
(this was made the default in 8.3.1 I believe).

--
   Jeffrey Hobbs                     The Tcl Guy
   hobbs at ajubasolutions.com       Ajuba Solutions (ne Scriptics)



Sat, 19 Apr 2003 07:53:25 GMT  
 Importing a Namespace Failing to Import Namespace??

Quote:


>> Ok, this is driving me nuts maybe someone can help me where to look.
>> I've got a package i have written, really simple at this point in
>> time.  ...
>> This all works, until I import the package in a script.  If I
>> include the auto_path line in the script, it will find the package
>> in working directory, but the namespace import wizard::* fails
>> silently.  When it reaches the unqalified wizard command, it dies
>> with an "invalid command name 'wizard'".  The script functions just
>> fine with the qualified name of the exported command,
>> wizard::wizard.
> The namespace import isn't really failing silently.  I believe what
> is happening is that your package is loading lazily.  That means
> when you first package require it, it tell the auto_load mechanism
> where the procs can be found - but it doesn't actually define them
> until first use.  namespace import doesn't actually use them, so
> when you call it, those procs don't yet exist.

I remember that some of the newer versions of the core handle this
situation. When doing a namespace import they also look into the
auto_path/auto_index and load any files defining commands matching the
import pattern.

This is definitely part of 8.4, see generic/tclNamesp.c, line 1069ff
(Tcl_Import), but I believe it was introduced sometime earlier.

/*
 *----------------------------------------------------------------------
 *
 * Tcl_Import --
 *
 *      Imports all of the commands matching a pattern into the namespace
 *      specified ...
 *
 *      If matching commands are on the autoload path but haven't been
 *      loaded yet, this command forces them to be loaded, then creates
 *      the links to them.
...
 */

Quote:
> The solution is to make sure you use -direct when making the package
> (this was made the default in 8.3.1 I believe).

The system uses the 'auto_import' command in the tcl library to do
this. This also means that it is possible to extend this mechanism to
cope with other special situations if there is a need.

--
Sincerely,

                <http://www.purl.org/NET/akupries/>
-------------------------------------------------------------------------------



Tue, 22 Apr 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TIP #261: Return Imported Commands from [namespace import]

2. Access to main namespace from imported module?

3. How to access a module's namespace within the module at import

4. import namespace issues

5. Importing into 'containers' namespace

6. import into global namespace

7. execfile(), import and namespaces

8. Separate namespaces, PyRun_String, and imports

9. Execution traces on imported namespace commands

10. namespace import without arguments

11. Determining what gets namespace imported

12. Finding the namespace from an imported command

 

 
Powered by phpBB® Forum Software