5.2. sourceinfo.bininfo¶
This modules provides for the location of Python execution by means of the package ‘inspect’ extended by additional sources for a simple API.
The stack frame of inspect is in particular reduced to the common parameter spos, which is an abstraction of the ‘stack-position’ representing the level of history within the caller level. The value spos==0 is the function itself, whereas spos==1 is the first level caller. Consequently spos==2 is the caller of the caller, etc.
The categories of provided RTTI comprise:
packages - Python packages.
modules - Python modules - a.k.a. source files.
callers - Python functions and class/object methods.
The following definiton is applied:
A package is represented by an imported top-entity which could either be a self-contained
module, or the *__init__.py* special module as the top-entity from a set of modules within
a sub directory structure.
So physically a package is a distribution unit, which provides one or more modules. Thus the displayed result in case of packages is the module when a self-contained, the path when a multi-module package.
Where the following attributes are available:__
name(package, module, function)
OID - dotted relative path to matching item of sys.path
filename
filepathname
item of sys.path
relative path to item of sys.path
line number
Dependent on the call context, some of the attribute values may not be available. E.g. when called from within the python/ipython shell, or ‘main’.
The API is designed here as a collection of slim functions only in order to avoid any overhead for generic application.
5.2.1. Modules¶
pysourceinfo.bininfo - runtime information on compiled Python binaries.
Details see manuals.
5.2.2. Functions¶
5.2.2.1. getcaller_bin_filename¶
5.2.2.2. getcaller_bin_filepathname¶
5.2.2.3. getcaller_bin_pathname¶
5.2.2.4. getcaller_bin_pathname_rel¶
5.2.2.5. getcaller_bin_pathname_sub¶
-
sourceinfo.bininfo.
getcaller_bin_pathname_sub
(spos=1)[source]¶ sub-pathname to first matching module directory of caller. Evaluates ‘sys.path’ first, else switches to ‘inspect’.
- Parameters
spos – Caller position on the stack.
- Returns
Returns the path name to the package.
- Raises
passed through exceptions –
5.2.2.6. getmodule_bin_filename¶
5.2.2.7. getmodule_bin_filepathname¶
5.2.2.8. getmodule_bin_pathname¶
5.2.2.9. getmodule_bin_pathname_rel¶
5.2.2.10. getmodule_bin_pathname_sub¶
5.2.3. Exceptions¶
5.2.4. Resources¶
inspect Python2 - [inspect2]
inspect Python3 - [inspect3]
types Python2 - [types2]
types Python3 - [types3]
pystackinfo package; Arno-Can Uestuensoez [pystackinfo]