htmlcmp 1.0.2__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlcmp
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Compare HTML files by rendered output
5
5
  Home-page: https://github.com/opendocument-app/compare-html
6
6
  Author: Andreas Stefl
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "htmlcmp"
3
- version = "1.0.2"
3
+ version = "1.0.4"
4
4
  description = "Compare HTML files by rendered output"
5
5
  classifiers = []
6
6
  authors = [
@@ -7,7 +7,7 @@ long_description = (this_directory / "README.md").read_text()
7
7
 
8
8
  setup(
9
9
  name="htmlcmp",
10
- version="1.0.2",
10
+ version="1.0.4",
11
11
  author="Andreas Stefl",
12
12
  author_email="stefl.andreas@gmail.com",
13
13
  description="Compare HTML files by rendered output",
@@ -1,24 +1,23 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- import os
5
4
  import sys
6
5
  import argparse
7
6
  import io
8
7
  import time
8
+ from pathlib import Path
9
9
 
10
10
  from PIL import Image, ImageChops
11
11
  from selenium import webdriver
12
12
  from selenium.webdriver.common.by import By
13
13
  from selenium.webdriver.support import expected_conditions
14
14
  from selenium.webdriver.support.ui import WebDriverWait
15
- import pathlib
16
15
 
17
16
 
18
- def to_url(something):
19
- if os.path.isfile(something):
20
- return pathlib.Path(os.path.abspath(something)).as_uri()
21
- return something
17
+ def to_url(path):
18
+ if path.is_file():
19
+ return path.as_uri()
20
+ return path
22
21
 
23
22
 
24
23
  def screenshot(browser, url):
@@ -77,8 +76,8 @@ def html_render_diff(a, b, browser):
77
76
 
78
77
  def main():
79
78
  parser = argparse.ArgumentParser()
80
- parser.add_argument("a")
81
- parser.add_argument("b")
79
+ parser.add_argument("a", type=Path)
80
+ parser.add_argument("b", type=Path)
82
81
  parser.add_argument(
83
82
  "--driver", choices=["chrome", "firefox", "phantomjs"], default="firefox"
84
83
  )
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- import os
5
4
  import sys
6
5
  import argparse
7
6
  import json
8
7
  import subprocess
9
8
  import shlex
9
+ from pathlib import Path
10
10
 
11
11
  from htmlcmp.common import bcolors
12
12
 
@@ -20,12 +20,14 @@ def tidy_json(path):
20
20
  return 1
21
21
 
22
22
 
23
- def tidy_html(path):
24
- config_path = os.path.join(
25
- os.path.dirname(os.path.realpath(__file__)), ".html-tidy"
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}"')
26
+ else:
27
+ cmd = shlex.split(f'tidy -q "{path}"')
28
+ result = subprocess.run(
29
+ cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
26
30
  )
27
- cmd = shlex.split(f'tidy -config "{config_path}" -q "{path}"')
28
- result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
29
31
  if result.returncode == 1:
30
32
  return 1
31
33
  if result.returncode > 1:
@@ -33,22 +35,22 @@ def tidy_html(path):
33
35
  return 0
34
36
 
35
37
 
36
- def tidy_file(path):
37
- if path.endswith(".json"):
38
+ def tidy_file(path, html_tidy_config=None):
39
+ if path.suffix == ".json":
38
40
  return tidy_json(path)
39
- elif path.endswith(".html"):
40
- return tidy_html(path)
41
+ elif path.suffix == ".html":
42
+ return tidy_html(path, html_tidy_config=html_tidy_config)
41
43
 
42
44
 
43
45
  def tidyable_file(path):
44
- if path.endswith(".json"):
46
+ if path.suffix == ".json":
45
47
  return True
46
- if path.endswith(".html"):
48
+ if path.suffix == ".html":
47
49
  return True
48
50
  return False
49
51
 
50
52
 
51
- def tidy_dir(path, level=0, prefix=""):
53
+ def tidy_dir(path, level=0, prefix="", html_tidy_config=None):
52
54
  prefix_file = prefix + "├── "
53
55
  if level == 0:
54
56
  print(f"tidy dir {path}")
@@ -58,15 +60,13 @@ def tidy_dir(path, level=0, prefix=""):
58
60
  "error": [],
59
61
  }
60
62
 
61
- items = [os.path.join(path, name) for name in os.listdir(path)]
62
- files = sorted(
63
- [path for path in items if os.path.isfile(path) and tidyable_file(path)]
64
- )
65
- dirs = sorted([path for path in items if os.path.isdir(path)])
63
+ items = [path / name for name in path.iterdir()]
64
+ files = sorted([path for path in items if path.is_file() and tidyable_file(path)])
65
+ dirs = sorted([path for path in items if path.is_dir()])
66
66
 
67
- for filename in [os.path.basename(path) for path in files]:
68
- filepath = os.path.join(path, filename)
69
- tidy = tidy_file(filepath)
67
+ for filename in [path.name for path in files]:
68
+ filepath = path / filename
69
+ tidy = tidy_file(filepath, html_tidy_config=html_tidy_config)
70
70
  if tidy == 0:
71
71
  print(f"{prefix_file}{bcolors.OKGREEN}{filename} ✓{bcolors.ENDC}")
72
72
  elif tidy == 1:
@@ -76,10 +76,13 @@ def tidy_dir(path, level=0, prefix=""):
76
76
  print(f"{prefix_file}{bcolors.FAIL}{filename} ✘{bcolors.ENDC}")
77
77
  result["error"].append(filepath)
78
78
 
79
- for dirname in [os.path.basename(path) for path in dirs]:
79
+ for dirname in [path.name for path in dirs]:
80
80
  print(prefix + "├── " + dirname)
81
81
  subresult = tidy_dir(
82
- os.path.join(path, dirname), level=level + 1, prefix=prefix + "│ "
82
+ path / dirname,
83
+ level=level + 1,
84
+ prefix=prefix + "│ ",
85
+ html_tidy_config=html_tidy_config,
83
86
  )
84
87
  result["warning"].extend(subresult["warning"])
85
88
  result["error"].extend(subresult["error"])
@@ -89,10 +92,13 @@ def tidy_dir(path, level=0, prefix=""):
89
92
 
90
93
  def main():
91
94
  parser = argparse.ArgumentParser()
92
- parser.add_argument("a")
95
+ parser.add_argument("path", type=Path, help="Path to directory to tidy")
96
+ parser.add_argument(
97
+ "--html-tidy-config", type=Path, help="Path to tidy config file"
98
+ )
93
99
  args = parser.parse_args()
94
100
 
95
- result = tidy_dir(args.a)
101
+ result = tidy_dir(args.path, html_tidy_config=args.html_tidy_config)
96
102
  if result["error"]:
97
103
  return 1
98
104
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlcmp
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Compare HTML files by rendered output
5
5
  Home-page: https://github.com/opendocument-app/compare-html
6
6
  Author: Andreas Stefl
File without changes
File without changes
File without changes
File without changes