Quick tool to log import statements
Project description
Import Logger
This was a terrible, quickly slapped together, package designed as a quick debugging tool.
Over the past few years, it has proved to be incredibly useful.
what this does
This package is used to override calls to import
, wrapping every import with
a call to psutil
which measures memory.
The outputs are written to a versioned file as csv
compatible text files --
one for "successful" imports, another for "failures"".
The output files are written to an __imports_logged
directory and stored under
an incremental __imports_logged/runs
subfolder.
This is rough and can be customized. This should NEVER NEVER NEVER be used on production code. This is a quick debugging tool.
DANGER DANGER DANGER
DO NOT RUN THIS IN PRODUCTION
DANGER DANGER DANGER
SERIOUSLY, DO NOT RUN THIS IN PRODUCTION
Why not? This library saves the loaded information in a versioned format - so every time you start/restart your applications, more disk space will be consumed.
so why would I use this?
There are two main use-cases:
-
The outputs can be processed and analyzed (even imported to Excel!) to determine where the biggest imports are, and what causes them.
-
Knowing import errors is useful in two situations: refactoring your own code, and finding what libraries are conditionally importing other 3rd party tools.
requirements
psutil
usage
try running the demo.py script
it is just...
# at the top of your script
import imports_logger
imports_logger.setup_logger()
# your code here
import re
# this should have created a folder named `__imports_logged/runs/001`
the text in runs 001 should look like
import|re.None,demo.py,0,12664832,12664832
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file imports_logger-1.0.1.tar.gz
.
File metadata
- Download URL: imports_logger-1.0.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83bfc84ed88f8af844b54c21bdf79ff1dcf19945589b8d571ddc2d8895a338bc |
|
MD5 | 499617b1831d028adb746488277bb4ba |
|
BLAKE2b-256 | 670882df2a9f04bc1369da04ce9b3e6b0b7a176f12446837a0793be58e1c3ccc |