border_patrol package

Submodules

border_patrol.with_log_debug module

Import this module to let Border-Patrol use logging with level DEBUG

border_patrol.with_log_error module

Import this module to let Border-Patrol use logging with level ERROR

border_patrol.with_log_info module

Import this module to let Border-Patrol use logging with level INFO

border_patrol.with_log_warning module

Import this module to let Border-Patrol use logging with level WARNING

border_patrol.with_print_stderr module

Import this module to let Border-Patrol use plain print on stderr

border_patrol.with_print_stdout module

Import this module to let Border-Patrol use plain print

Module contents

Main module holding the actual functionality of Border-Patrol

class border_patrol.BorderPatrol(report_fun=None, ignore_std_lib=None, report_py=None)[source]

Bases: object

Border-Patrol singleton class to track imports of packages.

Since BorderPatrol is a singleton, passing None for a value will keep the currently set value while passing a value will update the corresponding parameter.

Parameters:
  • report_fun (callable) – output function for reporting imports
  • ignore_std_lib (bool) – ignore imports of Python’s stdlib, default True
  • report_py (bool) – also report the Python runtime version, default True
template

str – string template for the report

at_exit()[source]

Handler to be called at exit

register()[source]

Registers/activates Border Patrol

Returns:Border-Patrol instance
Return type:self
report()[source]

Reports currently imported libraries

Returns:list of package’s (name, version, path)
Return type:list
track(module)[source]

Tracks packages for later reporting

Parameters:module – module instance
unregister()[source]

UnRegisters/deactivates Border Patrol

Returns:Border-Patrol instance
Return type:self
class border_patrol.IdentityDict[source]

Bases: dict

Dictionary returning key by default

border_patrol.get_package(module)[source]

Gets package part of module

Parameters:module – module instance
Returns:name of module’s package
Return type:str
border_patrol.get_pkg_to_dist_map()[source]

Generates mapping of packages to distributions

Returns:mapping of packages to distributions
Return type:dict
border_patrol.package_path(package)[source]

Retrieves path of package

Parameters:package – module instance of package
Returns:path of package
Return type:str
border_patrol.package_version(package, pkg_to_dist_map=None)[source]

Retrieves version string of package

Parameters:
  • package (module) – package as module instance
  • pkg_to_dist_map (dict) – mapping of packages to their distributions. Avoids recalculation if passed. (optional)
Returns:

version string of package

Return type:

str