### Full Example with All Options Source: https://context7.com/scottrogowski/code2flow/llms.txt Demonstrates advanced usage with various options including source paths, output file, language, exclusion lists, and parsing error handling. ```python code2flow.code2flow( raw_source_paths=['src/app.py', 'src/models.py'], output_file='detailed.png', language='py', hide_legend=False, exclude_namespaces=['TestClass', 'MockDB'], exclude_functions=['debug', 'log'], include_only_namespaces=None, include_only_functions=None, no_grouping=False, no_trimming=False, skip_parse_errors=True ) ``` -------------------------------- ### Dynamic Language Ambiguity Example Source: https://github.com/scottrogowski/code2flow/blob/master/README.md A Python example illustrating why static analysis cannot perfectly resolve function calls in dynamic languages when function references are determined at runtime. ```python def func_factory(param): if param < .5: return func_a else: return func_b func = func_factory(important_variable) func() ``` -------------------------------- ### Install Code2flow via pip Source: https://github.com/scottrogowski/code2flow/blob/master/README.md Installs the code2flow package using the Python package manager. ```bash pip3 install code2flow ``` -------------------------------- ### Python Library Integration Source: https://context7.com/scottrogowski/code2flow/llms.txt Example of importing the code2flow library into a Python script for programmatic call graph generation. ```python import code2flow ``` -------------------------------- ### Running Unit Tests for Code2flow Source: https://github.com/scottrogowski/code2flow/blob/master/README.md Provides the necessary commands to set up the development environment and run the unit tests for the code2flow project. This ensures the project's code is functioning as expected. ```bash pip install -r requirements_dev.txt make test ``` -------------------------------- ### Analyze Source Code via CLI Source: https://context7.com/scottrogowski/code2flow/llms.txt Basic commands to analyze source files, directories, or patterns and generate call graphs in various formats like DOT, JSON, PNG, or SVG. ```bash code2flow myproject.py code2flow src/app.js src/utils.js src/api.js code2flow ./lib --language rb code2flow myproject.py --output flowchart.png code2flow myproject.py --output flowchart.svg code2flow myproject.py --output graph.json code2flow myproject.py --output graph.dot ``` -------------------------------- ### Using Code2flow as a Python Library Source: https://github.com/scottrogowski/code2flow/blob/master/README.md Demonstrates how to import and use the code2flow library within a Python script. It takes a list of file paths and an output file path as arguments, similar to its CLI usage. ```python import code2flow code2flow.code2flow(['path/to/filea', 'path/to/fileb'], 'path/to/outputfile') ``` -------------------------------- ### Iterate tokens with Acorn tokenizer Source: https://github.com/scottrogowski/code2flow/blob/master/code2flow/node_modules/acorn/README.md Demonstrates how to use the Acorn tokenizer in an ES6 environment to iterate over tokens or convert them into an array. ```javascript for (let token of acorn.tokenizer(str)) { // iterate over the tokens } // transform code to array of tokens: var tokens = [...acorn.tokenizer(str)]; ``` -------------------------------- ### Extend Acorn Parser with plugins Source: https://github.com/scottrogowski/code2flow/blob/master/code2flow/node_modules/acorn/README.md Shows how to create a custom Parser class by extending the base Acorn Parser with external plugins like acorn-jsx. ```javascript var acorn = require("acorn"); var jsx = require("acorn-jsx"); var JSXParser = acorn.Parser.extend(jsx()); JSXParser.parse("foo()", {ecmaVersion: 2020}); ``` -------------------------------- ### Configure Display and Grouping Options Source: https://context7.com/scottrogowski/code2flow/llms.txt Commands to customize the visual representation of the graph, including legend visibility, grouping, and handling of orphaned functions. ```bash code2flow myproject.py --hide-legend --output clean.png code2flow myproject.py --no-grouping --output flat.png code2flow myproject.py --no-trimming --output complete.png code2flow myproject.py --no-grouping --hide-legend --output minimal.png code2flow ./src --language py --skip-parse-errors --output partial.png ``` -------------------------------- ### Generate Call Graphs from CLI Source: https://github.com/scottrogowski/code2flow/blob/master/README.md Commands to generate call graphs for various file types and directories. Supports single files, multiple files, and directory-wide analysis with language specification. ```bash code2flow mypythonfile.py code2flow myjavascriptfile.js code2flow project/directory/source_a.js project/directory/source_b.js code2flow project/directory/*.js code2flow project/directory --language js ``` -------------------------------- ### Parse JavaScript code with Acorn Source: https://github.com/scottrogowski/code2flow/blob/master/code2flow/node_modules/acorn/README.md Demonstrates the primary usage of the Acorn library to parse a simple JavaScript expression into an abstract syntax tree. It requires the 'acorn' package and accepts an options object to specify the ECMAScript version. ```javascript let acorn = require("acorn"); console.log(acorn.parse("1 + 1", {ecmaVersion: 2020})); ``` -------------------------------- ### Generate PNG from Source Files Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates a PNG call graph from a single Python source file. ```python code2flow.code2flow(['path/to/file.py'], 'output.png') ``` -------------------------------- ### Language-Specific Parsing Configuration Source: https://context7.com/scottrogowski/code2flow/llms.txt Commands to specify language-specific parsing settings for JavaScript module types and Ruby version compatibility. ```bash code2flow app.mjs --source-type module --output graph.png code2flow app.js --source-type script --output graph.png code2flow app.rb --ruby-version 31 --output graph.png code2flow legacy_app.rb --ruby-version 27 --output graph.png ``` -------------------------------- ### Generate DOT File from Multiple Sources Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates a DOT file representing the call graph from multiple Python source files. ```python code2flow.code2flow( ['src/main.py', 'src/utils.py', 'src/handlers.py'], 'callgraph.dot' ) ``` -------------------------------- ### Filter Namespaces and Functions Source: https://context7.com/scottrogowski/code2flow/llms.txt Commands to refine the call graph output by including or excluding specific namespaces, classes, or individual functions. ```bash code2flow myproject.py --exclude-namespaces TestClass,MockHandler,DebugHelper code2flow myproject.py --exclude-functions log,debug,print_status code2flow myproject.py --include-only-namespaces UserService,AuthHandler,Database code2flow myproject.py --include-only-functions main,process,validate,save code2flow myproject.py --exclude-namespaces TestSuite --exclude-functions helper,util ``` -------------------------------- ### Filter Call Graph Output Source: https://github.com/scottrogowski/code2flow/blob/master/README.md Demonstrates how to extract a specific subset of a call graph by targeting a function and defining upstream/downstream search depths. ```bash code2flow mypythonfile.py --target-function my_func --upstream-depth=1 --downstream-depth=1 ``` -------------------------------- ### POST /code2flow/generate Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates a call graph from provided source files. This endpoint supports various output formats and configuration options for filtering and grouping. ```APIDOC ## POST /code2flow/generate ### Description Generates a call graph from a list of source files. The output format is determined by the file extension of the output_file parameter (e.g., .png, .dot, .json). ### Method POST ### Endpoint /code2flow/generate ### Parameters #### Request Body - **raw_source_paths** (list of strings) - Required - List of file paths to analyze. - **output_file** (string) - Required - Path to save the generated graph. - **language** (string) - Optional - The programming language of the source files. - **exclude_namespaces** (list of strings) - Optional - Namespaces to ignore in the graph. - **exclude_functions** (list of strings) - Optional - Functions to ignore in the graph. - **skip_parse_errors** (boolean) - Optional - Whether to continue processing if parsing errors occur. ### Request Example { "raw_source_paths": ["src/app.py"], "output_file": "graph.png", "language": "py" } ### Response #### Success Response (200) - **status** (string) - Success message indicating the file was generated. #### Response Example { "status": "success", "output": "graph.png" } ``` -------------------------------- ### JSON Output Format and Processing Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates call graphs in JSON Graph Specification format for machine processing and custom visualization, including reading and processing the JSON data. ```python import code2flow import json # Generate JSON output code2flow.code2flow(['myapp.py'], 'graph.json') # Read and process the JSON with open('graph.json', 'r') as f: graph_data = json.load(f) # JSON structure follows jsongraph specification # { # "graph": { # "directed": true, # "nodes": { # "node_abc123": { # "uid": "node_abc123", # "label": "42: process_data()", # "name": "myapp::MyClass.process_data" # } # }, # "edges": [ # { # "source": "node_abc123", # "target": "node_def456", # "directed": true # } # ] # } # } # Process nodes for uid, node in graph_data['graph']['nodes'].items(): print(f"Function: {node['label']} in {node['name']}") # Process edges (function calls) for edge in graph_data['graph']['edges']: source = graph_data['graph']['nodes'][edge['source']]['label'] target = graph_data['graph']['nodes'][edge['target']]['label'] print(f"{source} -> {target}") ``` -------------------------------- ### Generate JSON Output for Processing Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates a JSON file representing the call graph, suitable for machine processing. ```python code2flow.code2flow( ['myproject.py'], 'graph.json' ) ``` -------------------------------- ### Extract Call Graph Subsets Source: https://context7.com/scottrogowski/code2flow/llms.txt Commands to focus the call graph analysis on specific functions or classes by defining upstream and downstream depth levels. ```bash code2flow myproject.py --target-function main --upstream-depth 2 --downstream-depth 3 code2flow myproject.py --target-function MyClass.process_data --downstream-depth 2 code2flow myproject.py --target-function mymodule::DatabaseHandler.connect --upstream-depth 1 --downstream-depth 1 code2flow app.js --target-function initialize --downstream-depth 5 code2flow app.py --target-function validate_input --upstream-depth 3 ``` -------------------------------- ### POST /code2flow/subset Source: https://context7.com/scottrogowski/code2flow/llms.txt Generates a focused subgraph centered around a specific target function, useful for analyzing complex call chains. ```APIDOC ## POST /code2flow/subset ### Description Extracts a subgraph centered on a target function, allowing for upstream and downstream depth control. ### Method POST ### Endpoint /code2flow/subset ### Parameters #### Request Body - **target_function** (string) - Required - The function name to center the graph on. - **upstream_depth** (integer) - Optional - Number of levels to traverse upwards. - **downstream_depth** (integer) - Optional - Number of levels to traverse downwards. ### Request Example { "target_function": "process_request", "upstream_depth": 2, "downstream_depth": 3 } ### Response #### Success Response (200) - **graph_data** (object) - The generated subset graph data. #### Response Example { "status": "success", "graph_data": { ... } } ``` -------------------------------- ### Logging and Verbosity Control (Library) Source: https://context7.com/scottrogowski/code2flow/llms.txt Configures the logging level for code2flow when used as a library, allowing for verbose (DEBUG) or quiet (WARNING) operation. ```python import logging import code2flow # Verbose logging in library mode code2flow.code2flow( ['myproject.py'], 'graph.png', level=logging.DEBUG ) # Quiet logging code2flow.code2flow( ['myproject.py'], 'graph.png', level=logging.WARNING ) ``` -------------------------------- ### Logging and Verbosity Control (CLI) Source: https://context7.com/scottrogowski/code2flow/llms.txt Controls the verbosity of code2flow's output using command-line arguments for detailed processing information or quiet operation. ```bash # Verbose mode - show detailed processing information code2flow myproject.py --verbose --output graph.png # Outputs: found groups, nodes, calls, variables, processing times # Quiet mode - suppress most logging code2flow myproject.py --quiet --output graph.png # Check version code2flow --version ``` -------------------------------- ### Language Parameters for JavaScript ES6 Source: https://context7.com/scottrogowski/code2flow/llms.txt Applies language-specific parameters, such as source type for JavaScript modules, during graph generation. ```python # With language parameters for JavaScript ES6 lang_params = LanguageParams(source_type='module') code2flow.code2flow( raw_source_paths=['app.mjs'], output_file='es6_graph.png', lang_params=lang_params ) ``` -------------------------------- ### Subset Parameters for Library Usage Source: https://context7.com/scottrogowski/code2flow/llms.txt Utilizes SubsetParams to programmatically extract subgraphs centered on target functions, with specified upstream and downstream depths. ```python import code2flow from code2flow.engine import SubsetParams, LanguageParams # Create subset parameters to focus on a specific function subset = SubsetParams.generate( target_function='process_request', upstream_depth=2, downstream_depth=3 ) # Generate subset graph code2flow.code2flow( raw_source_paths=['server.py'], output_file='request_flow.png', subset_params=subset ) # Target a class method subset = SubsetParams.generate( target_function='APIHandler.handle_post', upstream_depth=1, downstream_depth=2 ) ``` -------------------------------- ### Define comment tracking structure Source: https://github.com/scottrogowski/code2flow/blob/master/code2flow/node_modules/acorn/README.md Shows the expected structure for comment objects when the 'onComment' option is used with an array, following the Esprima format for tracking comments within the parsed AST. ```javascript { "type": "Line" | "Block", "value": "comment text", "start": Number, "end": Number, "loc": { "start": {line: Number, column: Number}, "end": {line: Number, column: Number} } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.