Background: A while back, I decided to rewrite the entire modules program in
pure TCL, since it seemed easy enough. In fact, it took about a day or two to
get something that worked. To my surprise, the pure TCL implementation runs
several times faster than the C-version that most people are using. Also,
because it is pure TCL, there is no porting involved in getting to run on
different machines, nor is there a need to have different versions for
different machines (we have linux, solaris, cygwin, hp-ux and irix machines on
our network!). Once you look at the TCL code, you realize how simple it is,
compared to the C-code. The TCL source code is roughly 1% the size of the C
source code!
Because not all the features are implemented, I have not pushed to replace the
current C version. However, one user (Dan Wandeler) has done some work to add
things like arbitrarily deep modulefiles (this hasn't been merged with my code
yet though). Implementing the remaining features would not be very difficult.
It is much easier to do string manipulations and hash lookups in TCL than in C.
However, before doing any new work on the C-version, I think it is worth
the developers time to fix up the TCL version instead and say good-bye to the
C-version.
The current version of the TCL implementation is only available via CVS on the
modules sourceforge site. I don't know enough about sourceforge to make it
available otherwise. It's in the tcl/ subdirectory. I will attach the
distribution in a separate mail, since it is less than 10K.
Now to answer Leo's questions:
> I'm not sure what you mean by those instructions above. I
> put modulecmd.tcl in a random place and set a new alias to
> it:
>
> % alias module '`eval /home/lbutler/bin/modulecmd.tcl tcsh \!*`'
>
> Any reason that wouldn't work? I don't see that it uses any
> of the old init files from the C version.
That should work, although you won't have $MODULEPATH defined to some default.
Also, there might be problems if you have $histchars or $prompt set to
something funky. I would like to avoid the init scripts, but the tcsh shell is
nasty enough that it is worth having.
> Today, the Tcl version doesn't have all of the functionality
> we use here in the C version. I think we traded some emails
> on this awhile back. I have not tackled making all of the
> updates necessary to get the features in there. The ones I
> recall are:
>
> 1. $env hash gets updated immediately during module unload,
> (when a setenv is undone) so any lines that use the value
> of the env var will cause an error. I was able to fix
> this by just removing the "unset env($var)" in the setenv
> proc; no side-effects that I know of thus far. Would
> there be any as far as you know?
Hmm, I suppose that would work. It sort of breaks the symmetry between setting
and unsetting variables, but maybe that is ok.
> 2. During a module switch, the position of env vars is not
> the same as it was before (desirable in PATH). The Tcl
> just does an unload then a load for the switch command.
yeah, it's not implemented yet, but in principle would be easy enough. If you
treat the modulepath as a "stack", you could just pop off all the modules until
you got to the desired module, reload the desired module, and then push all
the modules back on. that should preserve the order of $PATH settings.
that is left as an exercise for later...
> 3. Some modules just don't load although the command returns
> with no errors reported. I'll need more time to dig into
> this one.
yeah, there a few robustness things going on. the problem you are seeing can
happen if you try to load the same module twice, but the environment is
fiddled-with in between. the TCL version does not load a module if it thinks it
is loaded already.
> There may be more, but that was enough to prevent me from
> switching without fixing these and doing more testing.
> The first one is probably easy enough to fix, but the other
> ones I'm not sure. My Tcl coding skills are clearly not as
> good as yours.
tcl is pretty easy to learn! :) i'm not a tcl programmer either, but i picked
it up pretty quickly. its simpler than perl.
I just checked in my latest version of modulecmd.tcl and changes to the init
files.
-Mark
|