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

How to use pydeps api. #170

Open
happyhebaby opened this issue Mar 22, 2023 · 8 comments
Open

How to use pydeps api. #170

happyhebaby opened this issue Mar 22, 2023 · 8 comments
Assignees

Comments

@happyhebaby
Copy link

The doc is not clear on how to use the pydeps api.
For example, for command line to scan the current folder:

pydeps  --show-deps --no-output --include-missing -LERROR .

I guess it should be something like

        pydeps(fname='foo', **empty('--show-deps --no-output --include-missing -LERROR .'))

but it returned with error: _jb_pytest_runner.py: error: unrecognized arguments: .
Could you kindly advice what should be the proper way to write this api?
Thank you.

@thebjorn
Copy link
Owner

>>> from pydeps.pydeps import pydeps
>>> from pydeps import cli
>>> pydeps(**cli.parse_args(['--show-deps', '--no-output', '--include-missing', '-LERROR', '.']))

(it might be possible to set fname="." and omit the last . in your example, but I haven't tested it).

@thebjorn
Copy link
Owner

An easier to use, and more clearly defined and documented api would probably be a good idea...

@happyhebaby
Copy link
Author

Thank you @thebjorn for your info. I modified the script according to your reply:

pydeps(fname='/Users/foo/python/flask/tests', **empty('--show-deps --no-output --include-missing -LERROR',
                                                        output='/Users/foo/python/flask/tests/foo.json'))

It run without any error, but I couldn't find the result file after the call. If this is not the right way, how should I get the run result?

@thebjorn
Copy link
Owner

The --output flag determines the name of the final svg file.

The dependency graph is always printed to stdout (https://github.com/thebjorn/pydeps/blob/master/pydeps/pydeps.py#L36)

There should probably be a way to override this.

@happyhebaby
Copy link
Author

Could you change the api so the graph is returned for the call, in my case the result needs to be captured and processed further, and also I run parallel on multiple folders to improve perf. Could be able to write code to capture the stdout myself, but it makes sense to return the graph in scenarios when the graph is not the final result and needs further processing, besides it is more perf efficient this way.
Thanks a lot for your reply @thebjorn.

@thebjorn thebjorn self-assigned this Mar 24, 2023
@thebjorn
Copy link
Owner

Check out v1.11.2 available on PyPI.

@happyhebaby
Copy link
Author

Thanks so much, sorry for the slow response, I could confirm that it works with specifying an output file.

Just want to discuss this a little bit further, as in my original request, in my case save the result to an output file is not a desired way, as this result is only an intermediate result that needs further processing. With this current api design I have to given a temp file name, read the content of the file and deleting the file after processing, this expensive process will make perf pretty bad especially if I need to deal with a large repo where hundreds of directories (i/o on files are slow). Just curious why you couldn't change the api to return the graph map directly? Of course I am totally good that you added support to output the graph to a file, I am sure there are quite some users wanting this, but return the result graph with the api call will make the api much easier to use for certain scenarios like ours.

Thanks for your further consideration.

@happyhebaby
Copy link
Author

@thebjorn, cheers:)

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

No branches or pull requests

2 participants