-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to write output to json (#125)
* added a json writer * added tests, formatting * added docs * fixed pyproject.toml
- Loading branch information
Florian Maas
authored
Sep 24, 2022
1 parent
59159dc
commit 94730ba
Showing
8 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
docs/source | ||
deptry.json | ||
|
||
# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json | ||
from typing import Dict | ||
|
||
|
||
class JsonWriter: | ||
""" | ||
Class to write issues to a json file | ||
Args: | ||
json_output: file path to store output, e.g. `output.json` | ||
""" | ||
|
||
def __init__(self, json_output: str) -> None: | ||
self.json_output = json_output | ||
|
||
def write(self, issues: Dict): | ||
with open(self.json_output, "w", encoding="utf-8") as f: | ||
json.dump(issues, f, ensure_ascii=False, indent=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import json | ||
|
||
from deptry.json_writer import JsonWriter | ||
from deptry.utils import run_within_dir | ||
|
||
|
||
def test_simple(tmp_path): | ||
|
||
with run_within_dir(tmp_path): | ||
JsonWriter(json_output="output.json").write(issues={"one": "two", "three": "four"}) | ||
|
||
with open("output.json", "r") as f: | ||
data = json.load(f) | ||
|
||
assert data["one"] == "two" | ||
assert data["three"] == "four" |