Tcl - how to find the package download path?

In tcl how do I know the package download path?

 % tclsh % package require csv 

I want to know the path from which csv was downloaded.

In python, find the module path using

 >>> import os >>> print os.__file__ '/a/b/python2.2.1/linux26_x86_64/lib/python2.2/os.pyc' 

I am looking for a similar command in tcl

+4
source share
3 answers

It's not that simple: a package in Tcl looks more abstract than in Python.

Firstly, there are two types of packages: “classic” and “modules” , which have different basic mechanisms for finding what to load in response to the package require ... command.

Then both types of packages can do whatever they want to ensure their functionality. This means that they can (but not limited to):

  • Pure Tcl, source 'packages are just one Tcl file or any number of files.
  • Packages implemented in C or another compiled language, which are in the form of a dynamic library that receives load ed when a package is required.
  • The combination above when there is a C library and a Tcl code layer (usually providing helper / convenience commands).

Therefore, the question in itself has little meaning, since only the modules are represented by exactly one stand-alone file, but the “classic” packages are free to implement on their own.

On the other hand, each package usually provides (using one or another) certain information in the package subsystem, which can be restored (and analyzed) using the package ifneeded . For example, on my Windows system with ActiveState Tcl 8.5.x, I have:

 % package require csv 0.7.2 % package ifneeded csv 0.7.2 package provide csv 0.7.2;source -encoding utf-8 {C:/Program Files/Tcl/lib/teapot/package/tcl/teapot/tcl8/8.3/csv-0.7.2.tm} 

Note that what package ifneeded returns is just a Tcl script that must be eval uated to load the package, so parsing this information is inevitably inherent ad-hoc and fragile.

+15
source

For Tcl packages, you can view a list of all downloadable paths with the command:

 join $::auto_path \n 
+2
source

This guide discusses auto_path variables and other loadable library variables: https://www.systutorials.com/docs/linux/man/n-auto_path/ The search directory for a new or missing downloadable package can be added to tclsh: lappend auto_path / new_directoty.

0
source

Source: https://habr.com/ru/post/1415204/


All Articles