From 231b31be7ddf83cb1b43bb401b7865f6d1b87ff6 Mon Sep 17 00:00:00 2001 From: orhtej2 <2871798+orhtej2@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:43:03 +0200 Subject: [PATCH] Fixed json output --- .gitignore | 3 +++ lib/lib_package_linter.py | 15 ++------------- lib/print.py | 16 ++++++++++++++++ package_linter.py | 3 ++- requirements.txt | 2 ++ tests/test_app.py | 4 ++-- tests/test_catalog.py | 2 +- tests/test_configurations.py | 2 +- tests/test_manifest.py | 1 - tests/test_scripts.py | 2 +- 10 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 lib/print.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 6ab8220..a187347 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ __pycache__/ .apps/ .manifest.* .tests.* + +.venv/ +venv/ \ No newline at end of file diff --git a/lib/lib_package_linter.py b/lib/lib_package_linter.py index 5403de2..660d02c 100644 --- a/lib/lib_package_linter.py +++ b/lib/lib_package_linter.py @@ -5,6 +5,8 @@ import urllib import jsonschema +from lib.print import _print + # ############################################################################ # Utilities # ############################################################################ @@ -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) diff --git a/lib/print.py b/lib/print.py new file mode 100644 index 0000000..9ced10f --- /dev/null +++ b/lib/print.py @@ -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" diff --git a/package_linter.py b/package_linter.py index fd4cdd1..f8e9ecc 100755 --- a/package_linter.py +++ b/package_linter.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..992f3db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +jsonschema +toml \ No newline at end of file diff --git a/tests/test_app.py b/tests/test_app.py index d840d8c..ddb37cc 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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 @@ -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( { diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 2dfd9ed..c4f0337 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -7,7 +7,7 @@ import subprocess from lib.lib_package_linter import * -from lib.lib_package_linter import _print +from lib.print import _print ######################################## # _____ _ _ # diff --git a/tests/test_configurations.py b/tests/test_configurations.py index 25951cd..7c01ef3 100644 --- a/tests/test_configurations.py +++ b/tests/test_configurations.py @@ -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): diff --git a/tests/test_manifest.py b/tests/test_manifest.py index b6a7e0b..c59113a 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -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 diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 1774e83..4cb1259 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -6,7 +6,7 @@ import statistics from lib.lib_package_linter import * -from lib.lib_package_linter import _print +from lib.print import _print ##################################