fpgmaas/deptry

JSON reporting or summary line

WTK opened this issue · 10 comments

WTK commented

Is your feature request related to a problem? Please describe.

It's related to using deptry in CI (particularly Jenkins)

Describe the solution you would like

It would make it easier to integrate deptry into CI pipelines if you'd offert json output and/or some summary line that can be easily regexped to find out number of issues found.

Additional context

Jenkins allows us to define scripts that are used to parse output of various tools and collect errors/warnings. For example we use it to parse output from black formatter check, that after bunch of text spits out line like "2 files would be modified.". So we parse that and report that black found 2 issues.

Thanks for the suggestion, sure, this sounds like something we can add. It will be fairly output to add a line to the logging, similar to black, that says

There were X dependency issues found

I will work on this in the upcoming days. Would this suffice for your purposes?

Alternatively/additionally, we could add a json file, this will be slightly more work. For example, the output json file could look something like this:

{
  "missing": [
    "foo"
  ],
    "obsolete": [
    "bar"
  ]
}
WTK commented

Yes, looks pretty much perfect.

Hi @WTK , sorry, I just updated my comment. Should maybe have added a new one instead. Could you let me know if just the additional logging output would suffice, or if the json file is needed?

WTK commented

No worries :) As for the summary line, I'd suggest adding a tiny bit more details. Like "There were X dependency issues found: Y obsolete, Z missing, W transitive".

I'm thinking of adding this code in the upcoming release:

    @staticmethod
    def _log_total_number_of_issues_found(number):
        if number == 0:
            logging.info("Success! No dependency issues found.")
        elif number == 1:
            logging.info("There was 1 dependency issue found.")
        else:
            logging.info(f"There were {number} dependency issues found.")

However, I do have a strong preference to not add the details you mentioned to the output in that line, since it feels a bit redundant. The issues are outlined right below it.

Scanning 19 files...
There was 1 dependency issue found.

-----------------------------------------------------

The project contains obsolete dependencies:

        foo

Consider removing them from your project's dependencies. If a package is used for development purposes, you should add it to your development dependencies instead.

-----------------------------------------------------

So if the above logging line is not sufficient and you'd like to have the number of issues per category, I'd prefer to work on adding a CLI argument that can be used to specify a path for a json file with the details.

Let me know your thoughts :)

WTK commented

They're outlined in the response indeed, but it's not a one-liner you can just take a look to understand what are we dealing with. That said, I'm not pushing for it :)

I do understand that the logging output is not very useful to get numbers of different types of issues from, that would become too much of a hassle and prone to errors. However, if you are okay with it I'll choose not to add details about the number of different issues to the summary line. I think those are more suited to be fetched from a json file. So if you need those, just give me a heads up and I'll work on that.

side-note; since this is an open-source project I don't think that my preference should be a deciding factor in these kind of decisions. So if there are more people in favour of expanding the summary line than adding json output, then that should be the way to go.

Thanks for considering this! I just came here today to see if this was an upcoming feature.

We want to use this in python pre-commit tool and the json will be helpful to make a wrapper around it.

Thanks for letting me know this is a feature you also need, I'll work on adding json output.

@rrauenza I just created a PR that allows the user to run deptry as

deptry . -o deptry.json

where an example of the resulting deptry.json looks as follows:

{
    "obsolete": [
        "foo"
    ],
    "missing": [],
    "transitive": [],
    "misplaced_dev": []
}

Would this suffice for your purposes?