Skip to main content

Logs all imported packages and their version

Project description

ReadTheDocs Coveralls PyPI-Server

Border-Patrol

Border-Patrol logs all imported packages and their version to support you during debugging. In 95% of all cases when something suddenly breaks in production it is due to some different version in one of your requirements. Pinning down the versions of all your dependencies and dependencies of dependencies inside a virtual environments helps you to overcome this problem but is quite cumbersome and thus this method is not always applied in practice.

With Border-Patrol you can easily find the culprit by looking in the logs of the last working versions and compare it to the failing one since Border-Patrol will list all imported packages and their corresponding version right at the end of your program.

Usage

Border-Patrol is really simple to use, just install it with pip install border-patrol and import it before any other package, e.g.:

from border_patrol import with_print

import numpy as np
import scipy as sp
import sklearn

If you run those lines in a script, you will get the a similar output to this one:

Python version is 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
Following modules were imported:
PACKAGE         VERSION                         PATH                                                                                     
border_patrol   0.0.post0.dev1+g32fe77c.dirty   /Users/fwilhelm/Sources/border_patrol/src/border_patrol                                  
numpy           1.15.1                          /Users/fwilhelm/anaconda/envs/recsys_data/lib/python3.6/site-packages/numpy/__init__.py  
scipy           1.1.0                           /Users/fwilhelm/anaconda/envs/recsys_data/lib/python3.6/site-packages/scipy/__init__.py  
sklearn         0.19.2                          /Users/fwilhelm/anaconda/envs/recsys_data/lib/python3.6/site-packages/sklearn/__init__.py

If you import with_print, Border-Patrol will use print as output function. Since most production applications will rather use the logging module, you can tell Border-Patrol to use it by importing with_log_{error|warning|info|debug}. For instance from border_patrol import with_log_info will log the final report by using the INFO logging level.

If you want even more fine grained control you can import the BorderPatrol class directly from the border_patrol package and use the register() and unregister() method to activate and deactivate it, respectively.

How does it work?

Border-Patrol is actually quite simple. It overwrites the __import__ function in Python's builtins package to track every imported package. Additionally it registers an atexit handler to be called when your application finishes and reports all imported modules. To avoid any problem registering these things more than once, Border-Patrol is implemented as Singleton and thus it is not thread-safe.

Note

This project has been set up using PyScaffold 3.1. For details and usage information on PyScaffold see https://pyscaffold.org/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

border-patrol-0.1rc2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

border_patrol-0.1rc2-py2.py3-none-any.whl (6.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file border-patrol-0.1rc2.tar.gz.

File metadata

  • Download URL: border-patrol-0.1rc2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

File hashes

Hashes for border-patrol-0.1rc2.tar.gz
Algorithm Hash digest
SHA256 7d364e638fb08d2ab656e06942ac8135aa730a64ee75693ffed0489f7da7beb1
MD5 769afeb7b1e54261cd4859e9d4f843c4
BLAKE2b-256 d1178b776b1e835a100ad929a0eedceb5c0795c2d37e7c2911cb101ea2c65023

See more details on using hashes here.

File details

Details for the file border_patrol-0.1rc2-py2.py3-none-any.whl.

File metadata

  • Download URL: border_patrol-0.1rc2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

File hashes

Hashes for border_patrol-0.1rc2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ebc34057e0dfe1a7374fedadd672921992af27096c9c9bc30d9cb179e9be01ab
MD5 e36b641022767db415c7f82d113c363c
BLAKE2b-256 7d32b0e132b33b9407b81df32598d9aabfcb89af81cd416e02c477a4230577fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page