tcl

How to check if package is loaded from local dir, not system in Tcl


The question is - I have local copies of some packages from tcllib, and I have tcllib installed globally in /usr/lib/tcllib2.0. How to make sure that my program loads local packages instead of packages from /usr/lib/tcllib2.0? The only way to check that for now is to remove tcllib from the system and append auto_path with my local path (or alter auto_path). But maybe there is way to check the packages that were loaded are actually loaded from my local folder. Thank you in advance, George.

Upd. the only way I found is a manual checking location of loaded library: [lindex [split [package ifneeded math 1.2.6]] 1]


Solution

  • If you don't want to use globally installed packages, either set the TCLLIBPATH environment before starting Tcl, or alter the auto_path global variable before doing the first package require (with a few exceptions that are built into Tcl directly). That environment variable is used to initialise that global variable.

    Tcl does not have a policy of favouring one path over another especially, except for walking the auto_path linearly when searching for package index files. (The index files publish descriptions of how to load specific versions of a package).

    Alternatively, publish your alternate versions locally with a special version number that you know is never used elsewhere, and then package require -exact that specific version. If you are specific, you'll get exactly what you expect. The language runtime assumes that if you are that specific, you know what you are doing and can deal with whatever the consequences are.