NOTE: This project was created as a part of my internship at RazorThink, Inc., primarily for internal use, and is no longer maintained. It is made public here for your perusal with the permission of the company.
This library attempts to extract the minimum required amount of code for a given class/function to run properly.
Clone the repository and run the following command in the project root.
pip install -e .
The library provides two helper methods, pretty_print
and dump
.
code_dumper.dump()
takes only one argument, which is a reference to the
target function or class.
from code_dumper import dump
global_variable = 3
def unused_func(): pass
def global_func():
return global_variable
class Test:
def __init__(self):
print(global_func())
print(dump(Test))
code_dumper.pretty_print()
has one required argument, the object to be
dumped. In addition, it takes four optional arguments.
Argument | Includes |
---|---|
with_source | source code |
with_vars | found variables |
with_result | the final result |
with_logs | debug logs |
from code_dumper import pretty_print
global_variable = 3
def unused_func(): pass
def global_func():
return global_variable
class Test:
def __init__(self):
print(global_func())
pretty_print(Test,
with_source=True, with_vars=True,
with_result=True, with_logs=False)
You can see debug logs by adding to the top of your file.
import logging
logging.basicConfig(level=logging.DEBUG)
Also, if you're using a debugger, adding a breakpoint right before returning
from CodeDumper.dump()
tends to help, since you can see the final processed
state.