koknat / callgraph Goto Github PK
View Code? Open in Web Editor NEWA multi-language tool which parses source code for function definitions and calls
License: GNU General Public License v3.0
A multi-language tool which parses source code for function definitions and calls
License: GNU General Public License v3.0
It seems a nice tool with the graph and all.
Would it be an interesting feature to scan all files (of a certain language) in a folder (and if wished all subfolders?).
It would require to generate a list of all functions per file per folder, as well as a list of all function-calls per function.
I was thinking of programming something like that my self but i am still in the phase of "make or find".
When scanning code in R files, callGraph searches for function definitions using the regex
^(\s*)()(\w+)\s+<-\s+function\s*\(.*\)
The .
wildcard doesn't match newlines, so this fails to detect function definitions like:
example_function <- function(a_long_argument_name,
another_rather_long_argument_name,
a_third_argument)...
An alternative would be to replace .
with the character set matching everything except closing parentheses ([^\)]
):
^(\s*)()(\w+)\s+<-\s+function\s*\([^\)]*\)
=
instead of ->
Whilst using <-
for assignment is preferred, =
may be used. Any functions defined in this way will not be recognised.
This could be fixed by replacing the <-
with (<-|=)
.
Hi and thanks for this useful tool!
Given that so many languages are supported, including R and Python, would it be possible to add support for Julia as well?
Hi,
it doesn't seem to support fat arrow functions in javascript.
My code looks like this:
const setOrderItems = (formItems) => {
callGraph: ERROR: Could not find any function definitions in your file
Hello @koknat thank you very much for this tool!
Is it somehow possible to specify the path to the file in combination with the function name in the -start option?
e.g. ./callGraph . -start 'src/subfolder/main.go#update' -language 'go'
I would like to generate a call graph for a specific function but the same name is used in different files of my application.
ERROR: Language '' not recognized. Specify it with -language <language>
For example: -language pl
For example: -language py
For example: -language tcl
Supported languages are: awk bas c cpp dart for go java jl js kt lua m pas php pl py r rb rs sc sh swift tcl ts v
i find it couldn't find class,
such as
class A:
def init(self):
pass
def forward(self):
pass
only identity functions,
Hi @koknat this tool is so good! Thank you so much for your hard work
Though I think it would be great to add ways to create group at the file level and folder level.
This can be done with dot format and has been done in typescript here: https://github.com/PSeitz/ts-dependency-graph
Can you please share your thoughts on this?
it is currently not possible to differentiate methods with the same name but from different classes in the same file.
Example:
class ClassA:
def method_name(self):
return 0
class ClassB:
def method_name(self):
return 0
if __name__ == '__main__':
ClassA.method_name()
ClassB.method_name()
callGraph output:
{
"teste/multiple_functions.py:method_name": {
"called_by": {
"teste/multiple_functions.py:__MAIN__": 1
}
},
"teste/multiple_functions.py:__MAIN__": {
"calls": {
"teste/multiple_functions.py:method_name": 1
}
}
}
Hi, I have two questions around the tool, thanks for your info.
flask
repo has a test file tests/test_appctx.py
that has the following import statements:import pytest
import flask
from flask.globals import app_ctx
from flask.globals import request_ctx
I am looking for output of file level dependency like the following:
"tests.test_appctx": {
"imports": [
"flask",
"flask.globals",
"pytest"
],
"name": "tests.test_appctx",
"path": "/Users/myuserid/python/flask/tests/test_appctx.py"
},
can someone provide me with steps on how I can generate a callGraph in windows? for Dart language @koknat
root@6f38527114dc:/# cpan install GraphViz
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/root/.cpan/Metadata'
Database was generated on Tue, 29 Nov 2022 08:41:02 GMT
(error): Could not expand [GraphViz]. Check the module name.
(info): I can suggest names if you install one of Text::Levenshtein::XS, Text::Levenshtein::Damerau::XS, Text::Levenshtein, and Text::Levenshtein::Damerau::PP
(info): and you provide the -x option on invocation.
(error): Skipping GraphViz because I couldn't find a matching namespace.
I just learned of this project today, and it's really cool!
Thought you'd be interested to know of the GraphViz2 module, which may make things easier/better in this script. Example usage:
From https://github.com/PDLPorters/pdl/blob/master/perldl#L335-L338:
my $g = PDL::Core::pdumpgraph(PDL::Core::pdumphash($pdl));
require GraphViz2;
my $gv = GraphViz2->from_graph(PDL::Core::pdumpgraphvizify($g));
$gv->run(format => $format, output_file => $file);
The general idiom is you make a Graph
object, then annotate it (e.g. with a graphvizify
procedure such as https://github.com/PDLPorters/pdl/blob/ac270e21cafeda8726dd64fa4b90e4a6e686c8c2/Basic/Core/Core.pm#L2394-L2439), then GraphViz2
can run with it.
python
def function_name():
print('Trace: Called function_name()') # ERROR.. this will show as a function call when it is just a string
Hi there,
This is a very useful looking tool, but I'm having trouble running it on mac.
I've run brew install graphviz
as well as sudo cpan install GraphViz
, copied callGraph's executable into /usr/local/Cellar/graphviz/2.48.0/bin
, and called it like so, with the following error:
macbook ~ % callgraph /Users/username/Developer/Project/FileToGraph.swift
ERROR: Install GraphViz and the CPAN GraphViz module to create the call graph
sudo apt-get install Graphviz
and
sudo cpan install GraphViz
Am I doing something wrong? Is it possible to use callGraph on macOS?
Thanks,
Luke
Expected behavior: using -ymlOut
and -ymlIn
should produce a .dot graph which has the same features as running callGraph against a file or directory.
Actual behavior: callGraph -ymlIn $previously_produced_yml
produces a .dot graph whose nodes lack the filenames where the referenced functions exist.
Hi,
I am a rookie in this, but I want to get this tool works.
I saw the issue of luke: #1.
I tried following his advice but that don't work.
Warning: No available formula with the name "graphviz".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
It was migrated from homebrew/cask to homebrew/core.
Configuring R/RS/RSAVAGE/GraphViz-2.24.tgz with Makefile.PL
Can't exec "dot": No such file or directory at Makefile.PL line 21.
Please install Graphviz from http://www.graphviz.org/.
No 'Makefile' created RSAVAGE/GraphViz-2.24.tgz
/usr/bin/perl Makefile.PL -- NOT OK
Is someone that can help me?
Thanks a lot!
No code? Is this a test set?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.