Skip to content

Commit

Permalink
Merge pull request #162 from orhtej2/fix_json_output
Browse files Browse the repository at this point in the history
Fixed json output
  • Loading branch information
alexAubin authored Sep 24, 2024
2 parents 29df9c4 + 231b31b commit 2ccd9fc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ __pycache__/
.apps/
.manifest.*
.tests.*

.venv/
venv/
15 changes: 2 additions & 13 deletions lib/lib_package_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import urllib
import jsonschema

from lib.print import _print

# ############################################################################
# Utilities
# ############################################################################
Expand Down Expand Up @@ -50,19 +52,6 @@ class Critical(TestReport):
style = c.FAIL + " ✘✘✘ %s" + c.END


output = "plain"


def _print(*args, **kwargs):
if output == "plain":
print(*args, **kwargs)


def set_output_json():
global output
output = "json"


def report_warning_not_reliable(str):
_print(c.MAYBE_FAIL + "?", str, c.END)

Expand Down
16 changes: 16 additions & 0 deletions lib/print.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output = "plain"


def _print(*args, **kwargs):
if not is_json_output():
print(*args, **kwargs)


def set_output_json():
global output
print("setting")
output = "json"


def is_json_output() -> bool:
return output == "json"
3 changes: 2 additions & 1 deletion package_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import argparse
from pathlib import Path

from lib.lib_package_linter import _print, c, set_output_json
from lib.lib_package_linter import c
from lib.print import _print, set_output_json

from tests.test_app import App

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jsonschema
toml
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import toml

from lib.lib_package_linter import *
from lib.lib_package_linter import _print
from lib.print import _print, is_json_output

from tests.test_manifest import Manifest
from tests.test_scripts import Script
Expand Down Expand Up @@ -263,7 +263,7 @@ def report(self):
self.run_single_test(App.qualify_for_level_8)
self.run_single_test(App.qualify_for_level_9)

if output == "json":
if is_json_output():
print(
json.dumps(
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import subprocess

from lib.lib_package_linter import *
from lib.lib_package_linter import _print
from lib.print import _print

########################################
# _____ _ _ #
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess

from lib.lib_package_linter import *
from lib.lib_package_linter import _print
from lib.print import _print


class Configurations(TestSuite):
Expand Down
1 change: 0 additions & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re

from lib.lib_package_linter import *
from lib.lib_package_linter import _print


# Only packaging v2 is supported on the linter now ... But someday™ according The Prophecy™, packaging v3 will be a thing
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import statistics

from lib.lib_package_linter import *
from lib.lib_package_linter import _print
from lib.print import _print


##################################
Expand Down

0 comments on commit 2ccd9fc

Please sign in to comment.