From e880e623c6eaf46a6b35a5ccb1a42d95044d9bf0 Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Tue, 25 Jul 2023 15:15:21 -0400 Subject: [PATCH 1/2] Enable mypy review for pyshacl.cli:main and fix reported issues This patch updates the results of `mypy --ignore-missing-imports`, run only against `/pyshacl/cli.py`: | Count | Type-reviewed state | | ----- | --------------------------------- | | 0 | Current `master` branch state | | 40 | Only designating `main() -> None` | | 0 | Committed state | This patch updates the results of `mypy --ignore-missing-imports`, run against `/pyshacl`: | Count | Type-reviewed state | | ----- | --------------------------------------------- | | 20 | Current `master` branch state | | 61 | Only designating `main() -> None` in `cli.py` | | 21 | Committed state of `cli.py` | | 20 | Committed state including `main.py` | Signed-off-by: Alex Nelson --- pyshacl/__main__.py | 2 +- pyshacl/cli.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyshacl/__main__.py b/pyshacl/__main__.py index 19eaabc..c2e8d0a 100644 --- a/pyshacl/__main__.py +++ b/pyshacl/__main__.py @@ -23,4 +23,4 @@ def str_is_true(s_var: str): sys.exit(http_cli()) -sys.exit(main()) +main() diff --git a/pyshacl/cli.py b/pyshacl/cli.py index d92b44a..ee2ddc1 100644 --- a/pyshacl/cli.py +++ b/pyshacl/cli.py @@ -4,8 +4,10 @@ import argparse import os import sys +from typing import Any, Dict, Union from prettytable import PrettyTable +from rdflib import Graph from rdflib.namespace import SH from pyshacl import __version__, validate @@ -183,16 +185,13 @@ def str_is_true(s_var: str): # parser.add_argument('-h', '--help', action="help", help='Show this help text.') -def main(): +def main() -> None: basename = os.path.basename(sys.argv[0]) if basename == "__main__.py": parser.prog = "python3 -m pyshacl" do_server = os.getenv("PYSHACL_HTTP", "") do_server = os.getenv("PYSHACL_SERVER", do_server) - if do_server: - args = {} - else: - args = parser.parse_args() + args = parser.parse_args() if str_is_true(do_server) or args.server: from pyshacl.sh_http import cli as http_cli @@ -306,10 +305,11 @@ def col_widther(s, w): t2.field_names = ['No.', 'Severity', 'Focus Node', 'Result Path', 'Message', 'Component', 'Shape', 'Value'] t2.align = "l" + assert isinstance(v_graph, Graph) for i, o in enumerate(v_graph.objects(None, SH.result)): r = {} for o2 in v_graph.predicate_objects(o): - r[o2[0]] = str(col_widther(o2[1].replace(f'{SH}', ''), 25)) # max col width 30 chars + r[o2[0]] = str(col_widther(str(o2[1]).replace(f'{SH}', ''), 25)) # max col width 30 chars t2.add_row( [ i + 1, From 71d16c6ac3fec4f8f40739975a438d0227a6c340 Mon Sep 17 00:00:00 2001 From: Alex Nelson Date: Mon, 13 Nov 2023 09:51:39 -0500 Subject: [PATCH 2/2] Restore do_server check This patch also cleans away some typing symbols added when trying to make the "server mode" `args` variable work, but that became vestigial. Reported-by: Ashley Sommer Signed-off-by: Alex Nelson --- pyshacl/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyshacl/cli.py b/pyshacl/cli.py index ee2ddc1..efd5fa6 100644 --- a/pyshacl/cli.py +++ b/pyshacl/cli.py @@ -4,7 +4,6 @@ import argparse import os import sys -from typing import Any, Dict, Union from prettytable import PrettyTable from rdflib import Graph @@ -191,7 +190,10 @@ def main() -> None: parser.prog = "python3 -m pyshacl" do_server = os.getenv("PYSHACL_HTTP", "") do_server = os.getenv("PYSHACL_SERVER", do_server) - args = parser.parse_args() + if do_server: + args = argparse.Namespace() + else: + args = parser.parse_args() if str_is_true(do_server) or args.server: from pyshacl.sh_http import cli as http_cli