pytracertool


Namepytracertool JSON
Version 2.0.3 PyPI version JSON
download
home_pagehttps://github.com/DarshanLakshman/PyTracerTool.git
SummaryA versatile tool for tracing code execution, capturing variable changes, and logging print statements.
upload_time2024-03-21 20:36:10
maintainerNone
docs_urlNone
authorDarshan Lakshman
requires_pythonNone
licenseNone
keywords trace debugging tracing execution visualisation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            PyTracerTool Module
===================

Welcome to the PyTracerTool Module! This module provides a versatile
tool, PyTracerTool, for tracing the execution of Python code, capturing
variable changes, and logging print statements. PyTracerTool helps you
gain insights into the sequence of code execution, variable values, and
output generated during runtime.

Features
--------

-  Trace the execution order of Python code.
-  Capture variable changes during code execution.
-  Log print statements and associate them with line numbers.
-  Generate a formatted trace table for analysis.

Installation
------------

You can install PyTracerTool via pip:

.. code:: bash

   pip install pytracertool

To import this module, you must do ``import PyTracerTool``

Website
-------

Please have a look at a website I developed, which takes Python code as
an input and allows you to step through the program -
https://tracetableproject.pythonanywhere.com/

<<<<<<< HEAD

Python Documentation
--------------------

Help on module pytracertool:

NAME pytracertool - Welcome to the PyTracerTool Module

DESCRIPTION This module provides a versatile tool, PyTracerTool, for
tracing the execution of Python code, capturing variable changes, and
logging print statements. PyTracerTool helps you gain insights into the
sequence of code execution, variable values, and output generated during
runtime.

::

   Version: 1.0.0

   Classes:
       - OutputLogger: A utility class used for capturing and logging output produced by print statements.
       - CodeTracer: The main class that enables tracing and capturing code execution, variable changes, and print outputs.

   Usage:
       To use the PyTracerTool module, instantiate the CodeTracer class with the Python code you want to trace. You can then use
       the provided methods to capture and analyze the execution order, variable values, and print outputs.

   Author:
       Darshan Lakshman

   Disclaimer:
       This module is intended for educational purposes and code analysis. It may not cover all edge cases and situations.

CLASSES builtins.object CodeTracer OutputLogger

::

   class CodeTracer(builtins.object)
    |  CodeTracer(python_code: str)
    |  
    |  CodeTracer provides a versatile tool for tracing code execution, capturing variable changes, and logging print outputs.
    |  
    |  This class enables tracing the execution of Python code, capturing variable changes, and logging print outputs
    |  for later analysis. It offers methods to trace the execution order, capture variable values, and generate a formatted
    |  trace table that displays the sequence of code execution, variable changes, and print outputs.
    |  
    |  Methods:
    |      __init__(python_code): Initialize a new instance of CodeTracer with the provided Python code.
    |      __str__(): Returns the trace table in a string format
    |      format_code_for_tracing(): Format the Python code for tracing by encapsulating it in a main() function.
    |      capture_print_statements(): Capture print outputs during code execution and associate them with line numbers.
    |      trace_lines(): Trace and record the order in which lines are executed.
    |      variables_tracer(): Trace and record the changes in variable values during code execution.
    |      generate_trace_table(): Trace execution order, variable changes, and print outputs to generate a trace table.
    |  
    |  Attributes:
    |      code: The Python code to be traced.
    |      execution_order: A list to store the order in which lines of code are executed.
    |      tracer_info: A list to store information about variable values during execution.
    |      trace_table: A list to store a formatted trace table.
    |      calls_log: A list to log function calls during execution.
    |      output_lines: A dictionary to store captured print statement outputs.
    |      context: A dictionary to store the execution context.
    |  
    |  Methods defined here:
    |  
    |  __init__(self, python_code: str)
    |      Initialize a new instance of CodeTracer.
    |      
    |      :param python_code: The Python code to be traced.
    |      :type python_code: str
    |      
    |      :note:
    |          This constructor initializes an instance of the CodeTracer class with the provided Python code.
    |          The code will be traced to capture execution order, variable values, and print outputs.
    |  
    |  __str__(self) -> str
    |      Generate a formatted trace table for display.
    |      
    |      This method generates a formatted trace table from the captured information
    |      about code execution, variable changes, and print outputs. It uses the tabulate
    |      library to create a grid representation of the trace table and returns it as a string.
    |      
    |      :param self: The instance of the class.
    |      :return: Formatted trace table as a string.
    |      :rtype: str
    |      
    |      :Example:
    |          Suppose you have an instance of the CodeTracer class and have already
    |          generated a trace table using the generate_trace_table method:
    |      
    |          ```python
    |          example_code = '''
    |          x = 1
    |          y = 1
    |          x = x + y
    |          print(x)
    |          tracer = CodeTracer(example_code)
    |          tracer.generate_trace_table()
    |          trace_table_str = str(tracer)
    |          print(trace_table_str)
    |          ```
    |      
    |          The trace_table_str will contain a formatted table as a string, which you can print:
    |      
    |      
    |      :seealso: generate_trace_table
    |  
    |  capture_print_statements(self) -> dict
    |              Capture and associate print statements with line numbers during code execution.
    |      
    |              This method captures the output of print statements generated during the execution
    |              of the provided code. The captured output is associated with the line numbers in the
    |              code where the print statements occurred. It achieves this by temporarily redirecting
    |              the standard output stream to an instance of OutputLogger, which logs the output along
    |              with the corresponding line numbers.
    |      
    |              :param self: The instance of the class.
    |              :return: A dictionary mapping line numbers to captured output text.
    |              :rtype: dict
    |      
    |              :Example:
    |                  Capturing print statements and their associated line numbers:
    |      
    |                  ```python
    |                  example_code = "print('Hello, World!')
    |      print('Line 2 output')"
    |                  tracer = CodeTracer(example_code)
    |                  output_lines = tracer.capture_print_statements()
    |                  print(output_lines)
    |                  ```
    |      
    |                  The output_lines dictionary will contain:
    |                  ```
    |                  {
    |                      '1': 'Hello, World!',
    |                      '2': 'Line 2 output'
    |                  }
    |  
    |  format_code_for_tracing(self) -> str
    |      Formats the Python code, so that it can be traced.
    |      
    |      :param self: The instance of the class.
    |      :return: Formatted code provided by user; code provided by user placed inside a main() def
    |      :rtype: str
    |      
    |      :note:
    |          - This method puts all of the code given into a function called main(), by indenting all the lines by 1 tab
    |          - It also adds a line called _finished = True at the end of the method, because the trace functions only
    |            work until the second to last line.
    |      
    |      :example:
    |      
    |          This is an example of how to use this method:
    |      
    |              code = '''a = 1
    |              b = 1
    |              c = a + b'''
    |      
    |              python_code = CodeTracer(code)
    |              python_code.format_code_for_tracing()
    |      
    |          The result would be:
    |      
    |              def main()
    |                  a = 1
    |                  b = 1
    |                  c = a + b
    |                  _finished = True
    |  
    |  generate_trace_table(self)
    |      Trace the execution order and capture variable values and print outputs.
    |      
    |      This method traces the execution order of lines in the provided code and captures
    |      the values of variables at each step. It creates a table that displays variable values,
    |      print outputs, and the execution order.
    |      
    |      :param self: The instance of the class.
    |      
    |      :note:
    |          This method builds upon the `trace_lines` method to track the execution order
    |          and captures print outputs using `capture_print_statements`. It then prepares
    |          the code for execution by formatting it and appending a call to `main()`.
    |          The `variables_tracer` tracing mechanism is set up using `sys.settrace`, and
    |          the formatted code is executed. After execution is complete, the tracing function
    |          is unset using `sys.settrace(None)`.
    |      
    |      :return: None
    |      
    |      :Example:
    |          # Define an instance of CodeTracer and example code
    |          example_code = '''
    |          x = 10
    |          print("Value of x:", x)
    |          y = x + 5
    |          print("Value of y:", y)
    |          '''
    |          tracer = CodeTracer(example_code)
    |      
    |          # Trace variables and print captured trace table
    |          tracer.trace_variables()
    |          trace_table = tracer.trace_table
    |      
    |          # Print the formatted trace table
    |          print(tracer)
    |      
    |          Running the example will display a table with variable values, outputs, and execution order:
    |      
    |          Trace Table:
    |          +-------+----+----+-------------------+
    |          | Line  | x  | y  | OUTPUT            |
    |          +-------+----+----+-------------------+
    |          | 2     | 10 |    | Value of x: 10    |
    |          | 3     | 10 | 15 | Value of y: 15    |
    |          +-------+----+----+-------------------+
    |      
    |      :seealso: trace_lines, capture_print_statements, format_code_for_tracing, variables_tracer
    |  
    |  lines_tracer(self, frame: frame, event: str, arg: Any) -> Optional[Callable[[frame, str, Any], Optional[Callable]]]
    |      Trace function to monitor the execution order of lines.
    |      
    |      This trace function is used to monitor and record the order in which lines of code are executed.
    |      It appends the line number of each executed line to the `execution_order` list, capturing the
    |      sequential execution order for later analysis.
    |      
    |      :param self: The instance of the class.
    |      :param frame: The current frame being executed.
    |      :type frame: types.FrameType
    |      :param event: The event type, such as 'call', 'line', 'return', etc.
    |      :type event: str
    |      :param arg: Additional event information.
    |      :type arg: typing.Any
    |      :return: The next trace function to use, or None to stop tracing.
    |      :rtype: typing.Optional[typing.Callable[[types.FrameType, str, typing.Any], typing.Optional[typing.Callable]]]
    |      
    |      :Example:
    |          Tracing and recording the execution order of code lines:
    |      
    |          ```python
    |          tracer = CodeTracer(example_code)
    |          sys.settrace(tracer.lines_tracer)
    |          tracer.trace_lines()  # This populates tracer.execution_order
    |          sys.settrace(None)
    |          print(tracer.execution_order)  # Print the recorded execution order
    |          ```
    |      
    |          The `execution_order` list will contain the line numbers in the order they were executed.
    |  
    |  trace_lines(self)
    |      Gets the order in which the lines are executed
    |      
    |      :param self: The instance of the class.
    |      
    |      :note:
    |          This method sets up a tracing mechanism using `sys.settrace` to track the execution
    |          order of lines within the provided code. It populates the `execution_order` list with
    |          line numbers in the order they are executed. After tracing is complete, the tracing
    |          function is unset using `sys.settrace(None)`.
    |      
    |      :example:
    |          Suppose we have an instance of the CodeTracer class and want to trace the execution order
    |          of the following example code:
    |      
    |          ```python
    |          example_code = '''
    |          x = 10
    |          print("Value of x:", x)
    |          y = x + 5
    |          print("Value of y:", y)
    |          '''
    |      
    |          tracer = CodeTracer(example_code)
    |          tracer.trace_lines()
    |          print("Execution Order:", tracer.execution_order)
    |      
    |          The output will show the order in which the lines were executed:
    |      
    |          '''
    |          Value of x: 10
    |          Value of y: 15
    |          Execution Order: [2, 3, 4, 5]
    |          '''
    |      
    |          :return: None
    |  
    |  variables_tracer(self, frame: frame, event: str, arg: Any) -> Optional[Callable[[frame, str, Any], Optional[Callable]]]
    |      Trace function to monitor and trace the changes in variable values.
    |      
    |      This trace function is used to monitor and record the changes in variable values during code execution.
    |      It captures the values of local variables in the current frame and logs them along with the function name.
    |      The recorded information is then used to build a trace table that displays the values of variables as they
    |      change during the execution of the code.
    |      
    |      :param self: The instance of the class.
    |      :param frame: The current frame being executed.
    |      :type frame: types.FrameType
    |      :param event: The event type, such as 'call', 'line', 'return', etc.
    |      :type event: str
    |      :param arg: Additional event information.
    |      :type arg: typing.Any
    |      :return: The next trace function to use, or None to stop tracing.
    |      :rtype: typing.Optional[typing.Callable[[types.FrameType, str, typing.Any], typing.Optional[typing.Callable]]]
    |      
    |      :Example:
    |          Tracing and recording changes in variable values during code execution:
    |      
    |          ```python
    |          tracer = CodeTracer(example_code)
    |          sys.settrace(tracer.variables_tracer)
    |          tracer.trace_variables()  # This populates tracer.tracer_info with variable values
    |          sys.settrace(None)
    |          print(tracer.tracer_info)  # Print the recorded variable values
    |          ```
    |      
    |          The `tracer_info` list will contain dictionaries representing variable changes in each line.
    |  
    |  ----------------------------------------------------------------------
    |  Data descriptors defined here:
    |  
    |  __dict__
    |      dictionary for instance variables (if defined)
    |  
    |  __weakref__
    |      list of weak references to the object (if defined)

   class OutputLogger(builtins.object)
    |  OutputLogger captures and logs the output produced by print statements during code execution.
    |  
    |  This class is used to capture the output of print statements generated during the execution
    |  of the provided code. The captured output is associated with the line numbers in the code
    |  where the print statements occurred. It achieves this by temporarily redirecting the standard
    |  output stream to an instance of OutputLogger, which logs the output along with the corresponding
    |  line numbers.
    |  
    |  Methods:
    |      __init__(): Initialises an instance of OutputLogger
    |      write(text): Log the provided text along with the current line number.
    |      flush(): Placeholder method; no action is taken.
    |  
    |  Attributes:
    |      output_lines: A dictionary mapping line numbers to captured output text.
    |                    Keys represent line numbers, and values represent the corresponding output.
    |  
    |  Methods defined here:
    |  
    |  __init__(self)
    |      Initialize a new instance of OutputLogger.
    |      
    |      :param self: The instance of the class.
    |  
    |  flush(self)
    |      Placeholder method - no action is taken.
    |      
    |      :param self: The instance of the class.
    |      :return: None
    |  
    |  write(self, text: str)
    |      Log the provided text along with the current line number.
    |      
    |      :param self: The instance of the class.
    |      :param text: The text to be logged.
    |      :type text: str
    |      :return: None
    |  
    |  ----------------------------------------------------------------------
    |  Data descriptors defined here:
    |  
    |  __dict__
    |      dictionary for instance variables (if defined)
    |  
    |  __weakref__
    |      list of weak references to the object (if defined)

DATA ANY_TYPE = typing.Any Special type indicating an unconstrained
type.

::

       - Any is compatible with every type.
       - Any assumed to have all methods.
       - All values assumed to be instances of Any.
       
       Note that all the above statements are true from the point of view of
       static type checkers. At runtime, Any should not be used with instance
       or class checks.

   TRACER_RETURN_TYPE = typing.Optional[typing.Callable[[frame, str, typi...

License
-------

MIT License

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DarshanLakshman/PyTracerTool.git",
    "name": "pytracertool",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "trace, debugging, tracing, execution, visualisation",
    "author": "Darshan Lakshman",
    "author_email": "darshan.lakshman@icloud.com",
    "download_url": "https://files.pythonhosted.org/packages/d9/73/e91b809369200020a1a10e589d19ddece5edff257c12ac0567f08934ec5d/pytracertool-2.0.3.tar.gz",
    "platform": null,
    "description": "PyTracerTool Module\n===================\n\nWelcome to the PyTracerTool Module! This module provides a versatile\ntool, PyTracerTool, for tracing the execution of Python code, capturing\nvariable changes, and logging print statements. PyTracerTool helps you\ngain insights into the sequence of code execution, variable values, and\noutput generated during runtime.\n\nFeatures\n--------\n\n-  Trace the execution order of Python code.\n-  Capture variable changes during code execution.\n-  Log print statements and associate them with line numbers.\n-  Generate a formatted trace table for analysis.\n\nInstallation\n------------\n\nYou can install PyTracerTool via pip:\n\n.. code:: bash\n\n   pip install pytracertool\n\nTo import this module, you must do ``import PyTracerTool``\n\nWebsite\n-------\n\nPlease have a look at a website I developed, which takes Python code as\nan input and allows you to step through the program -\nhttps://tracetableproject.pythonanywhere.com/\n\n<<<<<<< HEAD\n\nPython Documentation\n--------------------\n\nHelp on module pytracertool:\n\nNAME pytracertool - Welcome to the PyTracerTool Module\n\nDESCRIPTION This module provides a versatile tool, PyTracerTool, for\ntracing the execution of Python code, capturing variable changes, and\nlogging print statements. PyTracerTool helps you gain insights into the\nsequence of code execution, variable values, and output generated during\nruntime.\n\n::\n\n   Version: 1.0.0\n\n   Classes:\n       - OutputLogger: A utility class used for capturing and logging output produced by print statements.\n       - CodeTracer: The main class that enables tracing and capturing code execution, variable changes, and print outputs.\n\n   Usage:\n       To use the PyTracerTool module, instantiate the CodeTracer class with the Python code you want to trace. You can then use\n       the provided methods to capture and analyze the execution order, variable values, and print outputs.\n\n   Author:\n       Darshan Lakshman\n\n   Disclaimer:\n       This module is intended for educational purposes and code analysis. It may not cover all edge cases and situations.\n\nCLASSES builtins.object CodeTracer OutputLogger\n\n::\n\n   class CodeTracer(builtins.object)\n    |  CodeTracer(python_code: str)\n    |  \n    |  CodeTracer provides a versatile tool for tracing code execution, capturing variable changes, and logging print outputs.\n    |  \n    |  This class enables tracing the execution of Python code, capturing variable changes, and logging print outputs\n    |  for later analysis. It offers methods to trace the execution order, capture variable values, and generate a formatted\n    |  trace table that displays the sequence of code execution, variable changes, and print outputs.\n    |  \n    |  Methods:\n    |      __init__(python_code): Initialize a new instance of CodeTracer with the provided Python code.\n    |      __str__(): Returns the trace table in a string format\n    |      format_code_for_tracing(): Format the Python code for tracing by encapsulating it in a main() function.\n    |      capture_print_statements(): Capture print outputs during code execution and associate them with line numbers.\n    |      trace_lines(): Trace and record the order in which lines are executed.\n    |      variables_tracer(): Trace and record the changes in variable values during code execution.\n    |      generate_trace_table(): Trace execution order, variable changes, and print outputs to generate a trace table.\n    |  \n    |  Attributes:\n    |      code: The Python code to be traced.\n    |      execution_order: A list to store the order in which lines of code are executed.\n    |      tracer_info: A list to store information about variable values during execution.\n    |      trace_table: A list to store a formatted trace table.\n    |      calls_log: A list to log function calls during execution.\n    |      output_lines: A dictionary to store captured print statement outputs.\n    |      context: A dictionary to store the execution context.\n    |  \n    |  Methods defined here:\n    |  \n    |  __init__(self, python_code: str)\n    |      Initialize a new instance of CodeTracer.\n    |      \n    |      :param python_code: The Python code to be traced.\n    |      :type python_code: str\n    |      \n    |      :note:\n    |          This constructor initializes an instance of the CodeTracer class with the provided Python code.\n    |          The code will be traced to capture execution order, variable values, and print outputs.\n    |  \n    |  __str__(self) -> str\n    |      Generate a formatted trace table for display.\n    |      \n    |      This method generates a formatted trace table from the captured information\n    |      about code execution, variable changes, and print outputs. It uses the tabulate\n    |      library to create a grid representation of the trace table and returns it as a string.\n    |      \n    |      :param self: The instance of the class.\n    |      :return: Formatted trace table as a string.\n    |      :rtype: str\n    |      \n    |      :Example:\n    |          Suppose you have an instance of the CodeTracer class and have already\n    |          generated a trace table using the generate_trace_table method:\n    |      \n    |          ```python\n    |          example_code = '''\n    |          x = 1\n    |          y = 1\n    |          x = x + y\n    |          print(x)\n    |          tracer = CodeTracer(example_code)\n    |          tracer.generate_trace_table()\n    |          trace_table_str = str(tracer)\n    |          print(trace_table_str)\n    |          ```\n    |      \n    |          The trace_table_str will contain a formatted table as a string, which you can print:\n    |      \n    |      \n    |      :seealso: generate_trace_table\n    |  \n    |  capture_print_statements(self) -> dict\n    |              Capture and associate print statements with line numbers during code execution.\n    |      \n    |              This method captures the output of print statements generated during the execution\n    |              of the provided code. The captured output is associated with the line numbers in the\n    |              code where the print statements occurred. It achieves this by temporarily redirecting\n    |              the standard output stream to an instance of OutputLogger, which logs the output along\n    |              with the corresponding line numbers.\n    |      \n    |              :param self: The instance of the class.\n    |              :return: A dictionary mapping line numbers to captured output text.\n    |              :rtype: dict\n    |      \n    |              :Example:\n    |                  Capturing print statements and their associated line numbers:\n    |      \n    |                  ```python\n    |                  example_code = \"print('Hello, World!')\n    |      print('Line 2 output')\"\n    |                  tracer = CodeTracer(example_code)\n    |                  output_lines = tracer.capture_print_statements()\n    |                  print(output_lines)\n    |                  ```\n    |      \n    |                  The output_lines dictionary will contain:\n    |                  ```\n    |                  {\n    |                      '1': 'Hello, World!',\n    |                      '2': 'Line 2 output'\n    |                  }\n    |  \n    |  format_code_for_tracing(self) -> str\n    |      Formats the Python code, so that it can be traced.\n    |      \n    |      :param self: The instance of the class.\n    |      :return: Formatted code provided by user; code provided by user placed inside a main() def\n    |      :rtype: str\n    |      \n    |      :note:\n    |          - This method puts all of the code given into a function called main(), by indenting all the lines by 1 tab\n    |          - It also adds a line called _finished = True at the end of the method, because the trace functions only\n    |            work until the second to last line.\n    |      \n    |      :example:\n    |      \n    |          This is an example of how to use this method:\n    |      \n    |              code = '''a = 1\n    |              b = 1\n    |              c = a + b'''\n    |      \n    |              python_code = CodeTracer(code)\n    |              python_code.format_code_for_tracing()\n    |      \n    |          The result would be:\n    |      \n    |              def main()\n    |                  a = 1\n    |                  b = 1\n    |                  c = a + b\n    |                  _finished = True\n    |  \n    |  generate_trace_table(self)\n    |      Trace the execution order and capture variable values and print outputs.\n    |      \n    |      This method traces the execution order of lines in the provided code and captures\n    |      the values of variables at each step. It creates a table that displays variable values,\n    |      print outputs, and the execution order.\n    |      \n    |      :param self: The instance of the class.\n    |      \n    |      :note:\n    |          This method builds upon the `trace_lines` method to track the execution order\n    |          and captures print outputs using `capture_print_statements`. It then prepares\n    |          the code for execution by formatting it and appending a call to `main()`.\n    |          The `variables_tracer` tracing mechanism is set up using `sys.settrace`, and\n    |          the formatted code is executed. After execution is complete, the tracing function\n    |          is unset using `sys.settrace(None)`.\n    |      \n    |      :return: None\n    |      \n    |      :Example:\n    |          # Define an instance of CodeTracer and example code\n    |          example_code = '''\n    |          x = 10\n    |          print(\"Value of x:\", x)\n    |          y = x + 5\n    |          print(\"Value of y:\", y)\n    |          '''\n    |          tracer = CodeTracer(example_code)\n    |      \n    |          # Trace variables and print captured trace table\n    |          tracer.trace_variables()\n    |          trace_table = tracer.trace_table\n    |      \n    |          # Print the formatted trace table\n    |          print(tracer)\n    |      \n    |          Running the example will display a table with variable values, outputs, and execution order:\n    |      \n    |          Trace Table:\n    |          +-------+----+----+-------------------+\n    |          | Line  | x  | y  | OUTPUT            |\n    |          +-------+----+----+-------------------+\n    |          | 2     | 10 |    | Value of x: 10    |\n    |          | 3     | 10 | 15 | Value of y: 15    |\n    |          +-------+----+----+-------------------+\n    |      \n    |      :seealso: trace_lines, capture_print_statements, format_code_for_tracing, variables_tracer\n    |  \n    |  lines_tracer(self, frame: frame, event: str, arg: Any) -> Optional[Callable[[frame, str, Any], Optional[Callable]]]\n    |      Trace function to monitor the execution order of lines.\n    |      \n    |      This trace function is used to monitor and record the order in which lines of code are executed.\n    |      It appends the line number of each executed line to the `execution_order` list, capturing the\n    |      sequential execution order for later analysis.\n    |      \n    |      :param self: The instance of the class.\n    |      :param frame: The current frame being executed.\n    |      :type frame: types.FrameType\n    |      :param event: The event type, such as 'call', 'line', 'return', etc.\n    |      :type event: str\n    |      :param arg: Additional event information.\n    |      :type arg: typing.Any\n    |      :return: The next trace function to use, or None to stop tracing.\n    |      :rtype: typing.Optional[typing.Callable[[types.FrameType, str, typing.Any], typing.Optional[typing.Callable]]]\n    |      \n    |      :Example:\n    |          Tracing and recording the execution order of code lines:\n    |      \n    |          ```python\n    |          tracer = CodeTracer(example_code)\n    |          sys.settrace(tracer.lines_tracer)\n    |          tracer.trace_lines()  # This populates tracer.execution_order\n    |          sys.settrace(None)\n    |          print(tracer.execution_order)  # Print the recorded execution order\n    |          ```\n    |      \n    |          The `execution_order` list will contain the line numbers in the order they were executed.\n    |  \n    |  trace_lines(self)\n    |      Gets the order in which the lines are executed\n    |      \n    |      :param self: The instance of the class.\n    |      \n    |      :note:\n    |          This method sets up a tracing mechanism using `sys.settrace` to track the execution\n    |          order of lines within the provided code. It populates the `execution_order` list with\n    |          line numbers in the order they are executed. After tracing is complete, the tracing\n    |          function is unset using `sys.settrace(None)`.\n    |      \n    |      :example:\n    |          Suppose we have an instance of the CodeTracer class and want to trace the execution order\n    |          of the following example code:\n    |      \n    |          ```python\n    |          example_code = '''\n    |          x = 10\n    |          print(\"Value of x:\", x)\n    |          y = x + 5\n    |          print(\"Value of y:\", y)\n    |          '''\n    |      \n    |          tracer = CodeTracer(example_code)\n    |          tracer.trace_lines()\n    |          print(\"Execution Order:\", tracer.execution_order)\n    |      \n    |          The output will show the order in which the lines were executed:\n    |      \n    |          '''\n    |          Value of x: 10\n    |          Value of y: 15\n    |          Execution Order: [2, 3, 4, 5]\n    |          '''\n    |      \n    |          :return: None\n    |  \n    |  variables_tracer(self, frame: frame, event: str, arg: Any) -> Optional[Callable[[frame, str, Any], Optional[Callable]]]\n    |      Trace function to monitor and trace the changes in variable values.\n    |      \n    |      This trace function is used to monitor and record the changes in variable values during code execution.\n    |      It captures the values of local variables in the current frame and logs them along with the function name.\n    |      The recorded information is then used to build a trace table that displays the values of variables as they\n    |      change during the execution of the code.\n    |      \n    |      :param self: The instance of the class.\n    |      :param frame: The current frame being executed.\n    |      :type frame: types.FrameType\n    |      :param event: The event type, such as 'call', 'line', 'return', etc.\n    |      :type event: str\n    |      :param arg: Additional event information.\n    |      :type arg: typing.Any\n    |      :return: The next trace function to use, or None to stop tracing.\n    |      :rtype: typing.Optional[typing.Callable[[types.FrameType, str, typing.Any], typing.Optional[typing.Callable]]]\n    |      \n    |      :Example:\n    |          Tracing and recording changes in variable values during code execution:\n    |      \n    |          ```python\n    |          tracer = CodeTracer(example_code)\n    |          sys.settrace(tracer.variables_tracer)\n    |          tracer.trace_variables()  # This populates tracer.tracer_info with variable values\n    |          sys.settrace(None)\n    |          print(tracer.tracer_info)  # Print the recorded variable values\n    |          ```\n    |      \n    |          The `tracer_info` list will contain dictionaries representing variable changes in each line.\n    |  \n    |  ----------------------------------------------------------------------\n    |  Data descriptors defined here:\n    |  \n    |  __dict__\n    |      dictionary for instance variables (if defined)\n    |  \n    |  __weakref__\n    |      list of weak references to the object (if defined)\n\n   class OutputLogger(builtins.object)\n    |  OutputLogger captures and logs the output produced by print statements during code execution.\n    |  \n    |  This class is used to capture the output of print statements generated during the execution\n    |  of the provided code. The captured output is associated with the line numbers in the code\n    |  where the print statements occurred. It achieves this by temporarily redirecting the standard\n    |  output stream to an instance of OutputLogger, which logs the output along with the corresponding\n    |  line numbers.\n    |  \n    |  Methods:\n    |      __init__(): Initialises an instance of OutputLogger\n    |      write(text): Log the provided text along with the current line number.\n    |      flush(): Placeholder method; no action is taken.\n    |  \n    |  Attributes:\n    |      output_lines: A dictionary mapping line numbers to captured output text.\n    |                    Keys represent line numbers, and values represent the corresponding output.\n    |  \n    |  Methods defined here:\n    |  \n    |  __init__(self)\n    |      Initialize a new instance of OutputLogger.\n    |      \n    |      :param self: The instance of the class.\n    |  \n    |  flush(self)\n    |      Placeholder method - no action is taken.\n    |      \n    |      :param self: The instance of the class.\n    |      :return: None\n    |  \n    |  write(self, text: str)\n    |      Log the provided text along with the current line number.\n    |      \n    |      :param self: The instance of the class.\n    |      :param text: The text to be logged.\n    |      :type text: str\n    |      :return: None\n    |  \n    |  ----------------------------------------------------------------------\n    |  Data descriptors defined here:\n    |  \n    |  __dict__\n    |      dictionary for instance variables (if defined)\n    |  \n    |  __weakref__\n    |      list of weak references to the object (if defined)\n\nDATA ANY_TYPE = typing.Any Special type indicating an unconstrained\ntype.\n\n::\n\n       - Any is compatible with every type.\n       - Any assumed to have all methods.\n       - All values assumed to be instances of Any.\n       \n       Note that all the above statements are true from the point of view of\n       static type checkers. At runtime, Any should not be used with instance\n       or class checks.\n\n   TRACER_RETURN_TYPE = typing.Optional[typing.Callable[[frame, str, typi...\n\nLicense\n-------\n\nMIT License\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A versatile tool for tracing code execution, capturing variable changes, and logging print statements.",
    "version": "2.0.3",
    "project_urls": {
        "Homepage": "https://github.com/DarshanLakshman/PyTracerTool.git"
    },
    "split_keywords": [
        "trace",
        " debugging",
        " tracing",
        " execution",
        " visualisation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa89c1cfef63ea4dea9094a3b4a2fbd161899ae763e46b43556f5489d8cde4f4",
                "md5": "8797d28e7744aded68dc66ed2b1a3afc",
                "sha256": "1ffdb8ffcfcd2202c69221ce18c0b89b85ba7472dc13d06df30812634e21c1a2"
            },
            "downloads": -1,
            "filename": "pytracertool-2.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8797d28e7744aded68dc66ed2b1a3afc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10799,
            "upload_time": "2024-03-21T20:36:07",
            "upload_time_iso_8601": "2024-03-21T20:36:07.883463Z",
            "url": "https://files.pythonhosted.org/packages/fa/89/c1cfef63ea4dea9094a3b4a2fbd161899ae763e46b43556f5489d8cde4f4/pytracertool-2.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d973e91b809369200020a1a10e589d19ddece5edff257c12ac0567f08934ec5d",
                "md5": "cb9fd10b1dd92dad66d22e01c5acc0be",
                "sha256": "e4e69b600a80917a35bdc39cbae8b54acff0997d7014781a17c0cf86e60b5724"
            },
            "downloads": -1,
            "filename": "pytracertool-2.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "cb9fd10b1dd92dad66d22e01c5acc0be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11569,
            "upload_time": "2024-03-21T20:36:10",
            "upload_time_iso_8601": "2024-03-21T20:36:10.132311Z",
            "url": "https://files.pythonhosted.org/packages/d9/73/e91b809369200020a1a10e589d19ddece5edff257c12ac0567f08934ec5d/pytracertool-2.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-21 20:36:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DarshanLakshman",
    "github_project": "PyTracerTool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytracertool"
}
        
Elapsed time: 0.22540s