Skip to content

Commit 92dff16

Browse files
committed
fix tidy_output
1 parent df628d4 commit 92dff16

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/htmlcmp/tidy_output.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,26 @@ def tidy_json(path):
2020
return 1
2121

2222

23-
def tidy_html(path, tidy_config=None):
24-
if tidy_config:
25-
cmd = shlex.split(f'tidy -config "{tidy_config.resove()}" -q "{path}"')
23+
def tidy_html(path, html_tidy_config=None):
24+
if html_tidy_config:
25+
cmd = shlex.split(f'tidy -config "{html_tidy_config.resolve()}" -q "{path}"')
2626
else:
2727
cmd = shlex.split(f'tidy -q "{path}"')
28-
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
28+
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
2929
if result.returncode == 1:
30+
print(result.stdout)
3031
return 1
3132
if result.returncode > 1:
33+
print(result.stdout)
3234
return 2
3335
return 0
3436

3537

36-
def tidy_file(path, tidy_config=None):
38+
def tidy_file(path, html_tidy_config=None):
3739
if path.suffix == ".json":
3840
return tidy_json(path)
3941
elif path.suffix == ".html":
40-
return tidy_html(path, tidy_config=tidy_config)
42+
return tidy_html(path, html_tidy_config=html_tidy_config)
4143

4244

4345
def tidyable_file(path):
@@ -48,7 +50,7 @@ def tidyable_file(path):
4850
return False
4951

5052

51-
def tidy_dir(path, level=0, prefix="", tidy_config=None):
53+
def tidy_dir(path, level=0, prefix="", html_tidy_config=None):
5254
prefix_file = prefix + "├── "
5355
if level == 0:
5456
print(f"tidy dir {path}")
@@ -66,7 +68,7 @@ def tidy_dir(path, level=0, prefix="", tidy_config=None):
6668

6769
for filename in [path.name for path in files]:
6870
filepath = path / filename
69-
tidy = tidy_file(filepath, tidy_config=tidy_config)
71+
tidy = tidy_file(filepath, html_tidy_config=html_tidy_config)
7072
if tidy == 0:
7173
print(f"{prefix_file}{bcolors.OKGREEN}{filename}{bcolors.ENDC}")
7274
elif tidy == 1:
@@ -82,7 +84,7 @@ def tidy_dir(path, level=0, prefix="", tidy_config=None):
8284
path / dirname,
8385
level=level + 1,
8486
prefix=prefix + "│ ",
85-
tidy_config=tidy_config,
87+
html_tidy_config=html_tidy_config,
8688
)
8789
result["warning"].extend(subresult["warning"])
8890
result["error"].extend(subresult["error"])
@@ -96,7 +98,7 @@ def main():
9698
parser.add_argument("--html-tidy-config", type=Path, help="Path to tidy config file")
9799
args = parser.parse_args()
98100

99-
result = tidy_dir(args.path, tidy_config=args.tidy_config)
101+
result = tidy_dir(args.path, html_tidy_config=args.html_tidy_config)
100102
if result["error"]:
101103
return 1
102104

0 commit comments

Comments
 (0)