Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide example of code #50

Closed
CristinaRaileanu opened this issue Feb 20, 2020 · 4 comments
Closed

Provide example of code #50

CristinaRaileanu opened this issue Feb 20, 2020 · 4 comments

Comments

@CristinaRaileanu
Copy link

I need to do a call graph using pydeps, but on an executable. So, I think a way to do it is to add code that uses pydeps to make a call graph. The things is, I didn't find any example of how to use it programmatically. Could you, please, provide some. Sorry, if this is similar to other issues.

@thebjorn
Copy link
Owner

Good starting points would be https://github.com/thebjorn/pydeps/blob/master/tests/test_skinny_package.py and

return _pydeps(inp, **_args)
If you have any specific questions I can try to answer them...

@CristinaRaileanu
Copy link
Author

CristinaRaileanu commented Feb 20, 2020

still not very clear how should I call it from the code. As I understand inp is the target file and args is a dictionary with flags. I am tried to do this:

    args = {"max-bacon": 4,
           "only": "src.ps. src.fov. src.pcm.",
           "rmprefix": "src.ps. src.fov. src.pcm."}
    _pydeps(inp, args)```

but gives me this error:
 TypeError: _pydeps() takes exactly 1 argument (2 given)

@thebjorn
Copy link
Owner

Ah, ok. Something like this should work:

import os
from pydeps.pydeps import _pydeps
from pydeps.target import Target
import pydeps.cli

FNAME = 'callpydeps.py'
OUT_FNAME = os.path.join(os.getcwd(), 'callpydeps.svg')

the output should be an absolute'ish path.

It's usually easier to let pydeps parse the args (note the format and the .split())

args = pydeps.cli.parse_args("""
    {fname}
    -o {output}
    --max-bacon=4
""".format(
    fname=FNAME,
    output=OUT_FNAME,
).split())

You can create your own arg-dict, but perhaps print the one returned from cli.parse_args to see what is expected...

print("ARGS:", args)

_pydeps(
    Target(args['fname']),
    **args
)

The filename needs to be wrapped in a pydeps.target.Target class, and the args should be passed with the double-star (**) notation.

You should get a graph if you put the above in a file named 'callpydeps.py' and run it.

@CristinaRaileanu
Copy link
Author

Thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants