Giter Club home page Giter Club logo

functiondefextractor's Introduction

Function Extractor

Python application License: MIT codecov

Tool to extract the function definitions from the source code

It can be used to extract functions from,

  • C

  • C++

  • C#

  • Java

  • Python

  • TypeScript

  • JavaScript

Advantage of using such function extractions are,

  • Resolving technical debt

  • Identify function similarity

  • Identify pattern check (Supresswarnings, Assert, etc...)

Dependencies

  • python 3.8 : 64 bit

  • python packages (xlrd, xlsxwriter, pandas)

  • third party packages [Ctags, grep]

Installation

INSTALL.md

pip install functiondefextractor

Usage & Configuration

Code

  • General usage with out options.
from functiondefextractor import core_extractor
out_put = core_extractor.extractor (r"path_to_repo/code")
print(out_put)
  • To exclude specific files from repository.
from functiondefextractor import core_extractor
out_put = core_extractor.extractor (r"path_to_repo/code", exclude=r'*\test\*,*.java')
print(out_put)

Sample regex patterns: Note: Space given after comma(,) in regex pattern is also treated as part of the pattern. For example

(*.java, *.cpp) != (*.java,*.cpp)
1. '*.java' =>  to exclude all java files in a repository.

2. '*/test/*' => to exclude test folder and files in it.

3. '*/src/*/*.cpp' => to exclude all cpp files in src and it's sub directories
  • To extract functions based on annotation.
from functiondefextractor import core_extractor
out_put = core_extractor.extractor (r"path_to_repo/code", annot="@Test")
print(out_put)
  • To extract delta lines(+/-) from code based on annotation/key word. Note: If user is unaware of complete annotation use this(annot with delta) feature to extract functions else use the above feature. Suggested to use delta=0 to get only line with annotation.
from functiondefextractor import core_extractor
out_put = core_extractor.extractor(r"path_to_repo/code", annot="@SupressWarning", delta="5")
print(out_put)
  • To analyse various patterns in the code based on given condition. For example to search assert, suppress warnings patterns.
from functiondefextractor import condition_checker
out_put = core_extractor.check_condition("@SupressWarning", r"path_to_excelfile/dataframe", "(")
print(out_put[0], out_put[1])

Commandline

  • General usage with out options to extract functions from repo.
>>>python -m functiondefextractor --p "path/to/repo"
  • To extract functions from repo having specific annotation.
>>>python -m functiondefextractor --p "path/to/repo" --a "@SuppressWarnings(\"UnusedReturnValue\")"

Note: If annotation contains double quotes as part of annotation(like above example) use backslash() before double quote inside annotation.

  • To ignore files from repo using regex pattern.
>>>python -m functiondefextractor --p "path/to/repo" --i '*.java, *.cpp'
  • To analyse various patterns in the code based on given condition.
>>>python -m functiondefextractor --c "Assert" --e "path/to/excel" --s "("
  • Help option can be found at,
>>>python -m functiondefextractor --h

Sample use cases

  • To extract all functions from a repository
>>>python -m functiondefextractor --p "path/to/repo"
from functiondefextractor import core_extractor
out_put = core_extractor.extractor (r"path_to_repo/code")
print(out_put)
  • To extract all functions with "@Test" annotation excluding all ".cpp" files in the repository
>>>python -m functiondefextractor --p "path/to/repo" --a "@Test" --i '*.cpp'
from functiondefextractor import core_extractor
out_put = core_extractor.extractor(r"path_to_repo/code", annot="@Test", exclude=r'*.cpp')
print(out_put)

Note:

  1. functionstartwith argument can be used to specifically extract code from required functions whose names starts with "test_" or what ever name user is interested in.

  2. delta and annot arguments together can be used to extract required number of lines below and above the given annotation/keyword.

  • To analyze various patterns present in extracted code
>>>python -m functiondefextractor --c "Assert" --e "path/to/excel" --s "("
from functiondefextractor import condition_checker
out_put = core_extractor.check_condition("@SupressWarning", r"path_to_excelfile/dataframe", "(")
print(out_put[0], out_put[1])

Output

  • Executing functiondefextractor to extract functions from command line would generate an output excel file which contains FileName_FunctionName in Unique ID column and extracted functions in Code column

  • Using functiondefextractor to extract functions from code would return a dataframe with same content as excel file.

  • When functiondefextractor is executed from script to analyse patterns in code, a tuple with 2 data frames would be generated which contains the requested pattern statements with their count in various functions and a pivot table of the same respectively.

Contact

MAINTAINERS.md

License

License.md

functiondefextractor's People

Contributors

brijeshkrishnan avatar jeroenknoops avatar sannihithreddy610 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

functiondefextractor's Issues

Add argument "output-path" to cli

The CLI tool currently does not support customizing output path and output file name. An optional argument should be added to enable user-defined behavior in writing xlsx files.

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.