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

sourceinfo.bininfo.getcaller_bin_filename(spos=1)[source]

Filename of binary caller module.

Parameters

spos – Caller position on the stack.

Returns

Returns the filename.

Raises

pass-through

5.2.2.2. getcaller_bin_filepathname

sourceinfo.bininfo.getcaller_bin_filepathname(spos=1)[source]

File pathname of caller module.

Parameters

spos – Caller position on the stack.

Returns

Returns the file pathname.

Raises

pass-through

5.2.2.3. getcaller_bin_pathname

sourceinfo.bininfo.getcaller_bin_pathname(spos=1)[source]

pathname of caller source file.

Parameters

spos – Caller position on the stack.

Returns

Returns the filename.

Raises

passed through exceptions

5.2.2.4. getcaller_bin_pathname_rel

sourceinfo.bininfo.getcaller_bin_pathname_rel(spos=1)[source]

Relative pathname to first matching package 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

pass-through

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

sourceinfo.bininfo.getmodule_bin_filename(mod)[source]

Basename of file for loaded module mod.

Parameters

mod – Reference to a loaded module.

Returns

Returns the basename of the loaded module.

Raises

passed through exceptions

5.2.2.7. getmodule_bin_filepathname

sourceinfo.bininfo.getmodule_bin_filepathname(mod)[source]

File pathname of loaded module mod.

Parameters

mod – Reference to a loaded module.

Returns

Returns the file pathname of the loaded module.

Raises

pass-through

5.2.2.8. getmodule_bin_pathname

sourceinfo.bininfo.getmodule_bin_pathname(mod)[source]

Path name of loaded module.

Parameters

mod – Reference to a loaded module.

Returns

Returns the pathname of the loaded module.

Raises

pass-through

5.2.2.9. getmodule_bin_pathname_rel

sourceinfo.bininfo.getmodule_bin_pathname_rel(mod, plist=None)[source]

Relative path name to PYTHONPATH for loaded module.

Parameters

mod – Reference to a loaded module.

Returns

Returns the relative pathname of the loaded module.

Raises

pass-through

5.2.2.10. getmodule_bin_pathname_sub

sourceinfo.bininfo.getmodule_bin_pathname_sub(mod, plist=None)[source]

Path name for loaded module, relative to package path.

Parameters

mod – Reference to a loaded module.

Returns

Returns the sub pathname of the loaded module.

Raises

passed through exceptions

5.2.3. Exceptions

5.2.4. Resources