Giter Site home page Giter Site logo

func-deps-tracer's Introduction

Function Dependency Tracer

  • Features

    • Generating call graph in static way.
    • Can search specific function or module.
    • Support for Py2 and Py3.
  • What it solved?
    It traces dependencies between functions over whole project, even where functions be called can be traced. There are many tools can trace dependencies between modules. However, tools for functions are rare. Here comes the solution, enjoy it!

  • How it solved?
    Since Python codes will be transferred to ast(abstract syntax tree) before it becomes binary. With ast nodes(anything in python file are ast nodes. e.g. import ,class, function, attribute), we do the following:

    1. Collect all function calls.
    2. Search where target function is used. Meanwhile, check if module of target function is imported to avoid name duplicate.
    3. Search where "function used target function" is used recursively until no function is found.

    NOTE: This tool can only trace approximately dependencies. It do not handle any kind of ast nodes. Some rare usages might not be traced(--verbose to get details). Still, it can trace most of the cases.

Installation

git clone "https://github.com/junyiacademy/func-deps-tracer.git"

Usage

  • To trace where a function is used

    python <path to this tool> <path to your project/file> --function <function name be traced>
    
    • Example

      python trace_function_dependency/trace_function_dependency.py my_project --function foo
      
  • To trace where functions in a module are used

    python <path to this tool> <path to your project/file> --module <module name be traced>
    
    • Example w/ skip dirs and output as json

      python trace_function_dependency/trace_function_dependency.py my_project --module foo.py --skip dir1 dir2 --json
      

Output

  • Format

    root, target:
        filepath:lineno, class::function::function
            filepath:lineno, class::function::function::call
                filepath:lineno, function::call
                    filepath:lineno, function::function::call
                    filepath:lineno, function::function::call
        filepath:lineno, function::function::call
            filepath:lineno, function::call
            filepath:lineno, function::call
    
  • Example

    To trace file below with this command.

    python trace_function_dependency/trace_function_dependency.py dog.py --function do_something
    
    # dog.py
    1  def do_something():
    2      # do something
    3      return None
    4
    5  class Dog(object):
    6      def __init__(self, name):
    7          self.name = name
    8
    9      def get_name_and_do_something(self):
    10         do_something()
    11         return self.name
    12
    13 dog = Dog('foo')
    14 dog_name = dog.get_name_and_do_something()

    This will be the output.

    root, do_something
        dog.py:10, Dog::get_name_and_do_something::do_something
            dog.py:14, dog.get_name_and_do_something
    

License

Function Dependency Tracer is released under the MIT license.

func-deps-tracer's People

Contributors

cyuanbin avatar

Stargazers

VincentJia avatar

Watchers

James Cloos avatar shianyow avatar 呂冠緯 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.