### Start Output Process Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Initializes variables after the initial configuration has been set. This method is intended to be overridden by subclasses. ```python def start(self): '''Initialise variables after initial configuration.' ''' pass ``` -------------------------------- ### Install Python Call Graph Source: https://lewiscowles1986.github.io/py-call-graph/index.html Use pip to install the python-call-graph package. This is the first step before using the library. ```bash pip install python-call-graph ``` -------------------------------- ### Generate Graphviz Call Graph with Options Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/command_line_usage.rst.txt Generates a call graph for a Python installation script, saving it as 'setup.png' and passing specific arguments to the script. ```bash pycallgraph graphviz --output-file=setup.png -- setup.py --dry-run install ``` -------------------------------- ### Starting a Trace Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Begins a trace, optionally resetting previous trace data. Raises an exception if no outputs are declared. ```python def start(self, reset=True): """Begins a trace. Setting reset to True will reset all previously recorded trace data. """ if not self.output: raise PyCallGraphException( 'No outputs declared. Please see the ' 'examples in the online documentation.' ) if reset: self.reset() for output in self.output: output.start() self.tracer.start() ``` -------------------------------- ### Context Manager for Tracing Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Implements the context manager protocol for easy start and stop of tracing using 'with' statements. ```python def __enter__(self): self.start() def __exit__(self, type, value, traceback): self.done() ``` -------------------------------- ### Class for Demonstrating Filtering Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/filtering.rst.txt This class is used in examples to demonstrate filtering capabilities. It includes methods that can be targeted by filters. ```python class Banana: def eat(self): print("Eating the banana") def peel(self): print("Peeling the banana") def __init__(self): self.secret_function() def secret_function(self): print("This is a secret") ``` -------------------------------- ### Define a Banana Class Source: https://lewiscowles1986.github.io/py-call-graph/guide/filtering.html This class is used as an example to demonstrate filtering. It includes methods that will be called during the measurement. ```python import time class Banana: def __init__(self): pass def eat(self): self.secret_function() self.chew() self.swallow() def secret_function(self): time.sleep(0.2) def chew(self): pass def swallow(self): pass ``` -------------------------------- ### Run Python Call Graph from Command Line Source: https://lewiscowles1986.github.io/py-call-graph/index.html Execute pycallgraph from the command line to generate a visualization of your Python script. Ensure Graphviz is installed as it's used for output. ```bash pycallgraph graphviz -- ./mypythonscript.py ``` -------------------------------- ### Basic API Usage of Python Call Graph Source: https://lewiscowles1986.github.io/py-call-graph/index.html A simple example of using the PyCallGraph API to profile a piece of code. This requires importing PyCallGraph and an outputter like GraphvizOutput. The profiling is done within a 'with' statement. ```python from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput with PyCallGraph(output=GraphvizOutput()): code_to_profile() ``` -------------------------------- ### Generate Call Graph with PyCallGraph Source: https://lewiscowles1986.github.io/py-call-graph/examples/basic.html Use this snippet to generate a call graph image from a Python script. Ensure Graphviz is installed and configured for output. ```python #!/usr/bin/env python ''' This example demonstrates a simple use of pycallgraph. ''' from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput class Banana: def eat(self): pass class Person: def __init__(self): self.no_bananas() def no_bananas(self): self.bananas = [] def add_banana(self, banana): self.bananas.append(banana) def eat_bananas(self): [banana.eat() for banana in self.bananas] self.no_bananas() def main(): graphviz = GraphvizOutput() graphviz.output_file = 'basic.png' with PyCallGraph(output=graphviz): person = Person() for a in range(10): person.add_banana(Banana()) person.eat_bananas() if __name__ == '__main__': main() ``` -------------------------------- ### Resetting Trace Statistics Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Resets all collected statistics and initializes a new tracer instance. This is called automatically on initialization and by start(reset=True). ```python def reset(self): """Resets all collected statistics. This is run automatically by start(reset=True) and when the class is initialized. """ self.tracer = self.get_tracer_class()(self.output, config=self.config) for output in self.output: self.prepare_output(output) ``` -------------------------------- ### Run Regular Expression Analysis (Ungrouped) Source: https://lewiscowles1986.github.io/py-call-graph/examples/regexp_ungrouped.html This script analyzes words from a dictionary to find those starting and ending with the same letter and containing consecutive identical letters. It uses PyCallGraph to visualize the process without grouping. ```python #!/usr/bin/env python ''' Runs a regular expression over the first few hundred words in a dictionary to find if any words start and end with the same letter, and having two of the same letters in a row. ''' import argparse import re from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph.output import GraphvizOutput class RegExp(object): def main(self): parser = argparse.ArgumentParser() parser.add_argument('--grouped', action='store_true') conf = parser.parse_args() if conf.grouped: self.run('regexp_grouped.png', Config(groups=True)) else: self.run('regexp_ungrouped.png', Config(groups=False)) def run(self, output, config): graphviz = GraphvizOutput() graphviz.output_file = output self.expression = r'^([^s]).*(.)\2.*\1$' with PyCallGraph(config=config, output=graphviz): self.precompiled() self.onthefly() def words(self): a = 200 for word in open('/usr/share/dict/words'): yield word.strip() a -= 1 if not a: return def precompiled(self): reo = re.compile(self.expression) for word in self.words(): reo.match(word) def onthefly(self): for word in self.words(): re.match(self.expression, word) if __name__ == '__main__': RegExp().main() ``` -------------------------------- ### Exclude Functions from Call Graph Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/filtering.rst.txt This example uses a GlobbingFilter to exclude specific functions, such as 'secret_function' and internal 'pycallgraph' functions, from the generated call graph. Configure this using the 'trace_filter' option. ```python from pycallgraph import PyCallGraph from pycallgraph.reporter import GraphvizReporter from pycallgraph.filter import GlobbingFilter reporter = GraphvizReporter() # Exclude secret_function and pycallgraph internals filter_ = GlobbingFilter(exclude=['secret_function', 'pycallgraph.*']) with PyCallGraph(reporter=reporter, trace_filter=filter_): banana = Banana() banana.eat() banana.peel() ``` -------------------------------- ### Generate Call Graph with Output File and Script Arguments Source: https://lewiscowles1986.github.io/py-call-graph/guide/command_line_usage.html This command generates a call graph image named 'setup.png' for a Python script 'setup.py', passing along command-line arguments to the script itself. ```bash pycallgraph graphviz --output-file=setup.png -- setup.py --dry-run install ``` -------------------------------- ### Initialize Output Class Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Initializes the Output class, setting default functions for node and edge coloring/labeling, and updating them with any provided keyword arguments. ```python class Output(object): '''Base class for all outputters.' def __init__(self, **kwargs): self.node_color_func = self.node_color self.edge_color_func = self.edge_color self.node_label_func = self.node_label self.edge_label_func = self.edge_label # Update the defaults with anything from kwargs [setattr(self, k, v) for k, v in list(kwargs.items())] ``` -------------------------------- ### Prepare Output File Stream Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Opens the specified output file in binary write mode ('wb') if it hasn't been opened already. It normalizes the path before opening. ```python def prepare_output_file(self): if self.fp is None: self.output_file = self.normalize_path(self.output_file) self.fp = open(self.output_file, 'wb') ``` -------------------------------- ### PyCallGraph Class Initialization Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Initializes the PyCallGraph object with optional output and configuration. It sets up the tracer and prepares the outputters. ```python import locale from .output import Output from .config import Config from .tracer import AsyncronousTracer, SyncronousTracer from .exceptions import PyCallGraphException [docs] class PyCallGraph(object): def __init__(self, output=None, config=None): """output can be a single Output instance or an iterable with many of them. Example usage: PyCallGraph(output=GraphvizOutput(), config=Config()) """ locale.setlocale(locale.LC_ALL, '') if output is None: self.output = [] elif isinstance(output, Output): self.output = [output] else: self.output = output self.config = config or Config() configured_ouput = self.config.get_output() if configured_ouput: self.output.append(configured_ouput) self.reset() ``` -------------------------------- ### Set Configuration for Output Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Applies configuration settings from a given config object to the output module. It iterates through the config's attributes and sets them on the output instance, skipping methods. ```python def set_config(self, config): ''' This is a quick hack to move the config variables set in Config into the output module config variables. ''' for k, v in list(config.__dict__.items()): if hasattr(self, k) and \ callable(getattr(self, k)): continue setattr(self, k, v) ``` -------------------------------- ### Preparing Outputters Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Performs sanity checks, sets the processor, and resets an outputter before it is used. ```python def prepare_output(self, output): output.sanity_check() output.set_processor(self.tracer.processor) output.reset() ``` -------------------------------- ### Trace Django Core Modules with Verbose Output Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/command_line_usage.rst.txt Runs Django's 'manage.py' script, including standard library calls and filtering to trace only 'django.core.*' modules. Verbose mode is enabled to show processing information. ```bash pycallgraph -v --stdlib --include "django.core.*" graphviz -- ./manage.py syncdb --noinput ``` -------------------------------- ### Ensure Required Binary is Available Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Checks if a specified command-line command is available in the system's PATH. If not, it raises a PyCallGraphException indicating the missing command and optional package. ```python def ensure_binary(self, cmd: str, pkg: Optional[str] = None): if which(cmd): return pkg_str = f" from {pkg}" if pkg else "" raise PyCallGraphException( f'The command "{cmd}"{pkg_str} is required to be in your path.' ) ``` -------------------------------- ### Python Regular Expression Grouping and Matching Source: https://lewiscowles1986.github.io/py-call-graph/_sources/examples/regexp_grouped.rst.txt This snippet illustrates the construction and matching of a regular expression with groups. It also compares the performance of compiling the regex once versus creating a new regex object in each iteration. ```python import re text = "The quick brown fox jumps over the lazy dog." # Pre-compile the regex for efficiency regex_compiled = re.compile(r"(quick) (brown) (fox)") match_compiled = regex_compiled.search(text) if match_compiled: print("Compiled Regex Match Found:") print(f" Full match: {match_compiled.group(0)}") print(f" Group 1: {match_compiled.group(1)}") print(f" Group 2: {match_compiled.group(2)}") print(f" Group 3: {match_compiled.group(3)}") # Match without pre-compiling (less efficient for repeated use) match_direct = re.search(r"(quick) (brown) (fox)", text) if match_direct: print("\nDirect Regex Match Found:") print(f" Full match: {match_direct.group(0)}") print(f" Group 1: {match_direct.group(1)}") print(f" Group 2: {match_direct.group(2)}") print(f" Group 3: {match_direct.group(3)}") # Example with no match no_match = re.search(r"cat", text) if not no_match: print("\nNo match found for 'cat'.") ``` -------------------------------- ### Add Arguments for Output Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html A class method to add command-line arguments related to output configuration to a subparser. This is intended to be overridden by subclasses. ```python @classmethod def add_arguments(cls, subparsers): pass ``` -------------------------------- ### Generate Basic Call Graph Source: https://lewiscowles1986.github.io/py-call-graph/guide/command_line_usage.html Use this command to create a call graph image named 'pycallgraph.png' from your Python script 'myprogram.py'. ```bash pycallgraph graphviz -- ./myprogram.py ``` -------------------------------- ### Output Source: https://lewiscowles1986.github.io/py-call-graph/api/api.html Base class for all output modules. This class provides a foundation for different output formats used by the library. ```APIDOC ## Class: Output ### Description Base class for all output modules. ### Usage This is a base class that other output modules inherit from. ``` -------------------------------- ### Add Output File Argument Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html A class method to add the '-o' or '--output-file' argument to a subparser, allowing users to specify the output file path. ```python @classmethod def add_output_file(cls, subparser, defaults, help): subparser.add_argument( '-o', '--output-file', type=str, default=defaults.output_file, help=help, ) ``` -------------------------------- ### Normalize File Path Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Normalizes a given file path by expanding user (~/) and environment variables. This ensures consistent path handling across different systems. ```python def normalize_path(self, path): regex_user_expand = re.compile(r'~') if regex_user_expand.match(path): path = os.path.expanduser(path) else: path = os.path.expandvars(path) # expand, just in case return path ``` -------------------------------- ### Tracer Class Selection Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Determines and returns the appropriate tracer class (asynchronous or synchronous) based on the configuration. ```python def get_tracer_class(self): if self.config.threaded: return AsyncronousTracer else: return SyncronousTracer ``` -------------------------------- ### Default Node and Edge Coloring Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Defines default methods for calculating node and edge colors based on their time and call fractions. These methods use the Color.hsv utility to generate colors. ```python def node_color(self, node): value = float(node.time.fraction * 2 + node.calls.fraction) / 3 return Color.hsv(value / 2 + .5, value, 0.9) def edge_color(self, edge): value = float(edge.time.fraction * 2 + edge.calls.fraction) / 3 return Color.hsv(value / 2 + .5, value, 0.7) ``` -------------------------------- ### Output Class Source: https://lewiscowles1986.github.io/py-call-graph/api/output.html The base class for all output modules in py-call-graph. It provides fundamental methods for initializing, configuring, and finalizing the graph output process. ```APIDOC ## class pycallgraph.output.Output ### Description Base class for all outputters. ### Methods #### done() Called when the trace is complete and ready to be saved. #### sanity_check() Basic checks for certain libraries or external applications. Raise or warn if there is a problem. #### set_config(config) This is a quick hack to move the config variables set in Config into the output module config variables. #### should_update() Return True if the update method should be called periodically. #### start() Initialise variables after initial configuration. #### update() Called periodically during a trace, but only when should_update is set to True. ``` -------------------------------- ### Output Class Sanity Check Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html A placeholder method for performing basic checks on required libraries or external applications. It is intended to raise or warn if any issues are found. ```python def sanity_check(self): '''Basic checks for certain libraries or external applications. Raise or warn if there is a problem. ''' pass ``` -------------------------------- ### Set Processor for Output Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Assigns the processor object to the outputter, allowing it to access processor-related configurations and methods. ```python def set_processor(self, processor): self.processor = processor ``` -------------------------------- ### Generate Filtered Call Graph for Django Source: https://lewiscowles1986.github.io/py-call-graph/guide/command_line_usage.html This command generates a call graph for Django's 'manage.py' script, enabling verbose mode, including the standard library, and filtering to trace only 'django.core.*' modules. This is useful for managing the size of the generated graph. ```bash pycallgraph -v --stdlib --include "django.core.*" graphviz -- ./manage.py syncdb --noinput ``` -------------------------------- ### Default Node and Edge Labeling Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Defines default methods for generating labels for nodes and edges. Node labels include name, call count, and time, with optional memory information. Edge labels show the call count. ```python def node_label(self, node): parts = [ '{0.name}', 'calls: {0.calls.value:n}', 'time: {0.time.value:f}s', ] if self.processor.config.memory: parts += [ 'memory in: {0.memory_in.value_human_bibyte}', 'memory out: {0.memory_out.value_human_bibyte}', ] return r'\n'.join(parts).format(node) def edge_label(self, edge): return '{0}'.format(edge.calls.value) ``` -------------------------------- ### Generate Graphviz Call Graph Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/command_line_usage.rst.txt Creates a call graph image named 'pycallgraph.png' from 'myprogram.py' using the Graphviz output mode. ```bash pycallgraph graphviz -- ./myprogram.py ``` -------------------------------- ### Completing a Trace Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Stops the trace and instructs the outputters to generate their output. This method calls stop() and then generate(). ```python def done(self): """Stops the trace and tells the outputters to generate their output. """ self.stop() self.generate() ``` -------------------------------- ### pycallgraph.output.Output Source: https://lewiscowles1986.github.io/py-call-graph/_sources/api/output.rst.txt Base class for all output modules. This class provides the fundamental structure and methods for generating call graph visualizations in various formats. ```APIDOC class Output: """Base class for all output modules.""" pass ``` -------------------------------- ### Adding Outputters Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Adds a new outputter to the PyCallGraph instance and prepares it for use. ```python def add_output(self, output): self.output.append(output) self.prepare_output(output) ``` -------------------------------- ### Measure without Filtering Source: https://lewiscowles1986.github.io/py-call-graph/guide/filtering.html This snippet shows how to generate a call graph without any filters applied. It measures the execution of the Banana class's eat method. ```python #!/usr/bin/env python from pycallgraph import PyCallGraph from pycallgraph.output import GraphvizOutput from banana import Banana graphviz = GraphvizOutput(output_file='filter_none.png') with PyCallGraph(output=graphviz): banana = Banana() banana.eat() ``` -------------------------------- ### Finalize Output Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Called when the trace is complete and the output is ready to be saved. This method must be implemented by subclasses to perform finalization steps. ```python def done(self): '''Called when the trace is complete and ready to be saved.' raise NotImplementedError('done') ``` -------------------------------- ### Generating Output Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Finalizes the trace by waiting for the processor thread (if in threaded mode) and then signaling each outputter to generate its output. ```python def generate(self): # If in threaded mode, wait for the processor thread to complete self.tracer.done() for output in self.output: output.done() ``` -------------------------------- ### PyCallGraph Source: https://lewiscowles1986.github.io/py-call-graph/api/api.html Main interface to Python Call Graph. This class serves as the primary entry point for interacting with the Python Call Graph functionality. ```APIDOC ## Class: PyCallGraph ### Description Main interface to Python Call Graph. ### Usage This class is the main interface for users to interact with the Python Call Graph library. ``` -------------------------------- ### Measure Call Graph Without Filtering Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/filtering.rst.txt This code measures the call graph without any specific filtering configurations. It's useful for understanding the default behavior. ```python from pycallgraph import PyCallGraph from pycallgraph.reporter import GraphvizReporter reporter = GraphvizReporter() with PyCallGraph(reporter=reporter): banana = Banana() banana.eat() banana.peel() ``` -------------------------------- ### Update Output Periodically Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Called periodically during a trace when 'should_update' returns True. This method must be implemented by subclasses to handle incremental output updates. ```python def update(self): '''Called periodically during a trace, but only when should_update is set to True. ''' raise NotImplementedError('update') ``` -------------------------------- ### Limit Maximum Call Depth Source: https://lewiscowles1986.github.io/py-call-graph/_sources/guide/filtering.rst.txt This code snippet demonstrates how to limit the depth of the call graph using the 'config.max_depth' setting. It's useful for focusing on the first level of calls. ```python from pycallgraph import PyCallGraph from pycallgraph.reporter import GraphvizReporter reporter = GraphvizReporter() # Limit call depth to 1 with PyCallGraph(reporter=reporter, config=dict(max_depth=1)): banana = Banana() banana.eat() banana.peel() ``` -------------------------------- ### PyCallGraph Class Methods Source: https://lewiscowles1986.github.io/py-call-graph/api/pycallgraph.html The PyCallGraph class provides methods to control the tracing of Python function calls. ```APIDOC ## `PyCallGraph` Class ### Description This class serves as the main interface for the Python Call Graph library, allowing users to start, stop, and manage call tracing. ### Methods #### `__init__(_output=None, _config=None)` Initializes the PyCallGraph object. It can optionally take an output handler and configuration. #### `done()` Stops the trace and triggers the outputters to generate their results. #### `reset()` Resets all collected statistics. This is automatically called by `start(reset=True)` and during initialization. #### `start(_reset=True)` Begins a trace. If `reset` is set to `True`, all previously recorded trace data will be cleared before starting. #### `stop()` Stops the currently running trace, if any. ``` -------------------------------- ### PyCallGraph Class Source: https://lewiscowles1986.github.io/py-call-graph/_sources/api/pycallgraph.rst.txt The PyCallGraph class provides the main interface for users to interact with the Python Call Graph library. It allows for the configuration and generation of call graphs. ```APIDOC ## Class: PyCallGraph ### Description This class is the main entry point for generating call graphs. It encapsulates the configuration and execution logic for the call graph generation process. ### Methods (Members of this class are documented separately and can be invoked directly by users.) ### Usage Example ```python from pycallgraph import PyCallGraph from pycallgraph.analyzer import GraphAnalyzer # Example function to analyze def my_function(): pass # Instantiate PyCallGraph with an analyzer with PyCallGraph(GraphAnalyzer()): my_function() ``` ``` -------------------------------- ### Reset Output State Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html A method to reset the state of the outputter. This is intended to be overridden by subclasses. ```python def reset(self): pass ``` -------------------------------- ### Determine if Output Should Update Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Returns a boolean indicating whether the 'update' method should be called. This method is intended to be overridden by subclasses to control the frequency of updates. ```python def should_update(self): '''Return True if the update method should be called periodically.' return False ``` -------------------------------- ### GlobbingFilter Class Source: https://lewiscowles1986.github.io/py-call-graph/api/globbing_filter.html Class used for filtering module names using a set of globs. Objects are matched against the exclude list first, then the include list. Anything that passes through without matching either, is excluded. ```APIDOC ## `globbing_filter.GlobbingFilter` ### Description Class used for filtering module names using a set of globs. Objects are matched against the exclude list first, then the include list. Anything that passes through without matching either, is excluded. ### Class Signature `GlobbingFilter(_include =None_, _exclude =None_)` ``` -------------------------------- ### GlobbingFilter Class Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/globbing_filter.html The GlobbingFilter class allows you to define inclusion and exclusion patterns for module names. It checks against exclude patterns first, then include patterns. If a name doesn't match either, it's excluded by default. ```APIDOC ## Class: GlobbingFilter ### Description Filter module names using a set of globs. Objects are matched against the exclude list first, then the include list. Anything that passes through without matching either, is excluded. ### Methods #### `__init__(self, include=None, exclude=None)` Initializes the GlobbingFilter with optional include and exclude lists of glob patterns. If both `include` and `exclude` are None, `include` defaults to `['*']` and `exclude` to `[]`. If `include` is None, it defaults to `['*']`. If `exclude` is None, it defaults to `[]`. - **include** (list of str, optional): A list of glob patterns to include. - **exclude** (list of str, optional): A list of glob patterns to exclude. #### `__call__(self, full_name=None)` Checks if a given `full_name` matches the filter criteria. - **full_name** (str, optional): The full name of the module to check. ### Returns - **bool**: `True` if the `full_name` should be included, `False` otherwise. ### Example ```python # Example usage (not part of the original documentation, for illustration) filter = GlobbingFilter(include=['my_module.*'], exclude=['my_module.internal.*']) print(filter('my_module.sub_module')) # Output: True print(filter('my_module.internal.helper')) # Output: False print(filter('another_module')) # Output: False ``` ``` -------------------------------- ### Exclude Functions using GlobbingFilter Source: https://lewiscowles1986.github.io/py-call-graph/guide/filtering.html Demonstrates how to use GlobbingFilter to exclude specific functions, such as 'secret_function' and internal 'pycallgraph' calls, from the generated graph. ```python #!/usr/bin/env python from pycallgraph import PyCallGraph from pycallgraph import Config from pycallgraph import GlobbingFilter from pycallgraph.output import GraphvizOutput from banana import Banana config = Config() config.trace_filter = GlobbingFilter(exclude=[ 'pycallgraph.*', '*.secret_function', ]) graphviz = GraphvizOutput(output_file='filter_exclude.png') with PyCallGraph(output=graphviz, config=config): banana = Banana() banana.eat() ``` -------------------------------- ### GlobbingFilter Class for Module Filtering Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/globbing_filter.html Defines a filter that uses glob patterns to include or exclude module names. It prioritizes exclude patterns over include patterns. If no patterns are provided, it defaults to including all modules. ```python from fnmatch import fnmatch [docs] class GlobbingFilter(object): '''Filter module names using a set of globs. Objects are matched against the exclude list first, then the include list. Anything that passes through without matching either, is excluded. ''' def __init__(self, include=None, exclude=None): if include is None and exclude is None: include = ['*'] exclude = [] elif include is None: include = ['*'] elif exclude is None: exclude = [] self.include = include self.exclude = exclude def __call__(self, full_name=None): for pattern in self.exclude: if fnmatch(full_name, pattern): return False for pattern in self.include: if fnmatch(full_name, pattern): return True return False ``` -------------------------------- ### Python Regular Expression (Ungrouped) Source: https://lewiscowles1986.github.io/py-call-graph/_sources/examples/regexp_ungrouped.rst.txt This snippet shows a Python script that utilizes regular expressions. It is intended to be used in conjunction with generating a call graph image, specifically demonstrating behavior when grouping is disabled. ```python from pycallgraph import PyCallGraph from pycallgraph.analyzer import OffsetAnalyzer def func_a(): func_b() def func_b(): func_c() def func_c(): pass if __name__ == "__main__": graph = PyCallGraph(analyzer=OffsetAnalyzer(), groups=False) graph.start() func_a() graph.stop() graph.render("regexp_ungrouped.png") ``` -------------------------------- ### Log Verbose Message Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Logs a message at the verbose level using the processor's configuration. This is useful for detailed debugging information. ```python def verbose(self, text): self.processor.config.log_verbose(text) ``` -------------------------------- ### Log Debug Message Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/output/output.html Logs a message at the debug level using the processor's configuration. This is useful for lower-level debugging information. ```python def debug(self, text): self.processor.config.log_debug(text) ``` -------------------------------- ### Stopping a Trace Source: https://lewiscowles1986.github.io/py-call-graph/_modules/pycallgraph/pycallgraph.html Stops the currently running trace, if any, by signaling the tracer to stop. ```python def stop(self): """Stops the currently running trace, if any.""" self.tracer.stop() ``` -------------------------------- ### GlobbingFilter Source: https://lewiscowles1986.github.io/py-call-graph/api/api.html Class used for filtering methods. This class is responsible for applying filtering logic to methods within the call graph. ```APIDOC ## Class: GlobbingFilter ### Description Class used for filtering methods. ### Usage Instantiate this class to filter methods based on specified patterns. ``` -------------------------------- ### GlobbingFilter Class Source: https://lewiscowles1986.github.io/py-call-graph/_sources/api/globbing_filter.rst.txt The GlobbingFilter class provides functionality for filtering methods based on glob patterns. It is part of the pycallgraph.globbing_filter module. ```APIDOC ## Class: pycallgraph.globbing_filter.GlobbingFilter ### Description Class used for filtering methods. ### Members This class has the following members: - `__init__(self, include=None, exclude=None)`: Initializes the GlobbingFilter with include and exclude patterns. - `filter(self, node)`: Filters a given node based on the include and exclude patterns. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.