5.4. sourceinfo.helper

pysourceinfo.helper - miscellaneous utilities - details see manuals

The provided interfaces are foreseen for the bottom layer of the software stack, thus provide basic handling only. This includes special cases of the file system parameters. For more advanced file system path processing refer to filesysobjects.

5.4.1. Functions

5.4.1.1. getfilepathname_type

sourceinfo.helper.getfilepathname_type(fpath)[source]

Type for stored module as defined by imp. :param fpath: Module path.

Returns

Returns the type of the file.

result := (
      C_BUILTIN
    | C_EXTENSION
    | PKG_DIRECTORY
    | PY_COMPILED
    | PY_FROZEN
    | PY_SOURCE
)

Raises

pass-through

5.4.1.2. getpythonpath

sourceinfo.helper.getpythonpath(pname, plist=None, **kw)[source]

Matches prefix from sys.path. Foreseen to be used for canonical base references in unit tests. This enables in particular for generic tests of file system positions where originally absolute pathnames were required.

Parameters
  • pname – Path name to be searched an appropriate pythonpath prefix for, either absolute or relative to an item of plist.

  • plist

    List of possible python paths. Alternative to sys.path.

    default := sys.path

  • kw

    ispre:

    If True adds a postfix path separator.

    presolve:

    Defines the path resolution strategy:

    presolve := (
          P_FIRST
        | P_LAST
        | P_LONGEST
        | P_SHORTEST
        )
    

    The default is stored in:

    sourceinfo.presolve = P_FIRST
    
    verify:

    Verify against the filesystem, else no checks are done.

    default := True

Returns

Returns the first matching path prefix from sys.path, as ‘normpath’. Else:

ispre == True: returns empty str - ''
else:          returns None

Raises

5.4.1.3. getpythonpath_rel

sourceinfo.helper.getpythonpath_rel(pname, plist=None, **kw)[source]

Verifies an absolute or relative path name to be reachable as a relative path to one item of the search list plist.

Parameters
  • pname – Path name of a path searched for relative to an item of plist. Absolute is cut, relative is searched literally.

  • plist

    Search path alternative to sys.path.

    default := sys.path

  • kargs

    presolve:

    The type of path resolution:

    pname is relative:
    
        presolve := (
            P_FIRST
        )
    
    pname is absolute:
    
       presolve := (
            P_FIRST
          | P_LAST
          | P_LONGEST
          | P_SHORTEST
       )
    

    default := pysourceinfo.presolve(P_FIRST)

    raw:

    If True suppresses the call of ‘os.path.normpath()’:

    raw := (
          True   # keep e.g. multiple and trailing *os.sep*
        | False  # apply os.path.normpath()
    )
    default := False
    
    normpath:

    The method to be called for the normalization of the provided input path. This is in particular required when cross-platform path strings are provided. These are by default processed internally with the os.sep of the current platform only.

    The API is as defined by ‘os.path.normpath’:

    normapth := (
          <custom-call>
        | <default-call>
    )
    custom-call := (
          ntpath
        | posixpath
        | <any-compatible-api>
    )
    default-call := os.path.normpath
    
    verify:

    Verify against the file system, else no checks are done.

    default := True

Returns

First matched path from sys.path as normalized path. Else:

if PYTHONPATH[i] == pname:   returns empty str - ''
else:
    if verify:               raise SourceInfoError
    else:                    returns None

Raises

5.4.1.4. getpythonpath_rel_oid

sourceinfo.helper.getpythonpath_rel_oid(pname, plist=None, **kw)[source]

Calls getpythonpath_rel, returns the relative path as dotted OID relative to the search path.

Parameters
  • interface parameters refer to:: (For) – sourceinfo.helper.getpythonpath_rel()

  • kargs

    For remaining parameters refer to getpythonpath_rel.

    restype:

    Result type:

    restype = (
          OID_STR    # OID as dottedt string representation
        | OID_TUPLE  # OID as tuple
        | OID_LIST   # OID as list
    )
    
    default := OID_STR
    
    sepin:

    The path separator:

    default := os.sep
    

    The function internally checks the presence of the provided path. This is not cross-converted, thus requires native separator characters. While the NT file system supports multiple separators, the posix based file systems support regularly the slash ‘/’ only. Thus these fail when other separator characters are provided. For advanced cross-capabilities refer to filesysobjects.

    sepout:

    The path separator:

    default := '.'
    

Returns

Returns the provided result by getpythonpath_rel in accordance to the requested result type - see restype.

Raises

5.4.1.5. getstack_frame

sourceinfo.helper.getstack_frame(spos=1, fromtop=False)[source]

List of current mem-addresses on stack frames.

Parameters
  • spos – Stack position.

  • fromtop – Start on top, default from bottom.

Returns

Returns the specified frame.

Raises

passed through exceptions

5.4.1.6. getstack_len

sourceinfo.helper.getstack_len()[source]

Length of current stack.

Parameters

none.

Returns

Returns the length of current stack.

Raises

pass-through

5.4.1.7. matchpath

sourceinfo.helper.matchpath(path, pathlist=None, pmatch=1)[source]

Match a file pathname of pathname on a pathlist.

Parameters
  • path – Path to be searched in pathlist.

  • pathlist

    Search path for a given path.

    default := sys.path

  • pmatch

    Match criteria for search.

    pmatch := (
        P_FIRST, P_LAST, P_SHORTEST,
        P_LONGEST, P_IGNORE0
     )
    

    default := P_FIRST

Returns

Returns the matched pathname from pathlist.

Raises

pass-through