webcode-tk 1.2.19__tar.gz → 1.2.21__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: webcode-tk
3
- Version: 1.2.19
3
+ Version: 1.2.21
4
4
  Summary: A set of tools for inspecting HTML and CSS code
5
5
  License: MIT
6
6
  License-File: LICENSE.rst
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "webcode-tk"
3
- version = "1.2.19"
3
+ version = "1.2.21"
4
4
  description = "A set of tools for inspecting HTML and CSS code"
5
5
  authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
6
6
  keywords = ["html", "validation", "css", ]
@@ -40,4 +40,4 @@
40
40
  - **`validator_tools`**: sends HTML or CSS code to the W3C Validator to check
41
41
  for errors.
42
42
  """
43
- __version__ = "1.2.19"
43
+ __version__ = "1.2.21"
@@ -24,13 +24,12 @@ font-file or some other hidden calculation from the browser.
24
24
 
25
25
  import re
26
26
  from typing import Any
27
- from typing import Union
27
+
28
28
  from file_clerk import clerk
29
29
 
30
30
  from webcode_tk import css_tools
31
31
  from webcode_tk import html_tools as html
32
32
 
33
-
34
33
  absolute_keyword_regex = (
35
34
  r"\b(?:xx-small|x-small|small(?!-caps)|medium|large|x-large|"
36
35
  )
@@ -137,7 +136,7 @@ def get_font_unit(value: str) -> str:
137
136
  """returns unit being use when setting font-size"""
138
137
  unit = ""
139
138
  # Check for relative keywords
140
- if value in KEYWORD_SIZE_MAP.keys():
139
+ if value in KEYWORD_SIZE_MAP:
141
140
  unit = "absolute_keyword"
142
141
  elif relative_keyword.search(value):
143
142
  unit = "relative_keyword"
@@ -169,7 +168,7 @@ def split_value_unit(value: str) -> tuple:
169
168
  value_unit: a tuple of the value and the unit.
170
169
  """
171
170
  value_unit = ["", ""]
172
- if value in KEYWORD_SIZE_MAP.keys():
171
+ if value in KEYWORD_SIZE_MAP:
173
172
  value_unit = (value, "absolute_keyword")
174
173
  elif relative_keyword.search(value):
175
174
  value_unit = (value, "relative_keyword")
@@ -236,17 +235,15 @@ def is_large_text(size: float, is_bold: bool) -> bool:
236
235
  is_large: whether the text is considered large or not.
237
236
  """
238
237
  is_large = False
239
- if size >= 24:
240
- is_large = True
241
- elif is_bold and size >= 18.66:
238
+ if size >= 24 or is_bold and size >= 18.66:
242
239
  is_large = True
243
240
  return is_large
244
241
 
245
242
 
246
243
  def compute_font_size(
247
- value: Union[str, int, float],
244
+ value: str | float,
248
245
  unit: str,
249
- parent_size: Union[int, float] = 16.0,
246
+ parent_size: float = 16.0,
250
247
  element_name: str = "",
251
248
  ) -> float:
252
249
  """Computes font size based on value, unit, and possibly parent size.
@@ -288,7 +285,7 @@ def compute_font_size(
288
285
  percentage = value * 0.01
289
286
  computed_size = parent_size * percentage
290
287
  elif unit == "em":
291
- if element_name.lower() in HEADING_SIZES.keys():
288
+ if element_name.lower() in HEADING_SIZES:
292
289
  # factor = HEADING_SIZES.get(element_name).split("e")[0]
293
290
  computed_size = parent_size * value # * factor
294
291
  else:
@@ -296,7 +293,7 @@ def compute_font_size(
296
293
  elif unit in ("unset", "inherit"):
297
294
  computed_size = parent_size
298
295
  elif unit in "revert":
299
- if element_name.lower() in HEADING_SIZES.keys():
296
+ if element_name.lower() in HEADING_SIZES:
300
297
  ems = HEADING_SIZES.get(element_name)
301
298
  multiplier = ems.split("e")[0]
302
299
  computed_size = parent_size * float(multiplier)
@@ -340,13 +337,12 @@ def is_valid_shorthand(value: str) -> bool:
340
337
  if ignore:
341
338
  continue
342
339
  font_size_values = get_numeric_fontsize_values(val)
343
- if font_size_values:
344
- targets_size = True
345
- elif val in KEYWORD_SIZE_MAP.keys():
346
- targets_size = True
347
- elif val in ("larger", "smaller"):
348
- targets_size = True
349
- elif val in UNIT_TO_PT_CONVERSIONS.keys():
340
+ if (
341
+ font_size_values
342
+ or val in KEYWORD_SIZE_MAP
343
+ or val in ("larger", "smaller")
344
+ or val in UNIT_TO_PT_CONVERSIONS
345
+ ):
350
346
  targets_size = True
351
347
 
352
348
  # check for font family.
@@ -419,9 +415,8 @@ def get_google_font_report(project_dir: str, min=1, max=2) -> str:
419
415
  families = extract_families(font_data)
420
416
  if families:
421
417
  for family in google_fonts_linked:
422
- if family in families:
423
- if family not in fonts_used:
424
- fonts_used.append(family)
418
+ if family in families and family not in fonts_used:
419
+ fonts_used.append(family)
425
420
 
426
421
  num_used = len(fonts_used)
427
422
  if num_used >= min and num_used <= max:
@@ -0,0 +1,24 @@
1
+ name: Update requirements.txt
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ requirements:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: actions/setup-python@v2
14
+ - name: Install Poetry
15
+ uses: snok/install-poetry@v1
16
+ - name: Generate requirements.txt
17
+ run: poetry export --with dev -f requirements.txt -o requirements.txt
18
+ - name: Commit and push requirements.txt
19
+ run: |
20
+ git config user.name "github-actions"
21
+ git config user.email "github-actions@github.com"
22
+ git add requirements.txt
23
+ git commit -m "chore: update requirements.txt" || true
24
+ git push
@@ -103,7 +103,7 @@ def get_markup_validity(file_path: str) -> list:
103
103
  try:
104
104
  errors = r.json()
105
105
  errors = errors.get("messages")
106
- except Exception:
106
+ except ValueError:
107
107
  # We need to use the web browser
108
108
  errors = get_validation_by_browser(file_path)
109
109
 
@@ -252,7 +252,7 @@ def get_validation_by_browser(file_path: str) -> list:
252
252
  browser["fragment"] = html_code
253
253
  browser.submit_selected()
254
254
  results = browser.get_current_page().select("div#results")
255
- except Exception:
255
+ except requests.ConnectionError:
256
256
  # Convert the file "no_css_connection.html" into a soup tag object
257
257
  no_connection_code = (
258
258
  "<h1>Sorry, but we could not make a connection</h1>"
@@ -288,11 +288,18 @@ def validate_css(css_code: str) -> bs4.ResultSet:
288
288
  browser["text"] = css_code
289
289
  browser.submit_selected()
290
290
  results = browser.get_current_page().select("#results_container")
291
- except Exception:
292
- # Convert the file "no_css_connection.html" into a soup tag object
293
- no_connection_code = clerk.file_to_string(
294
- "webanalyst/no_css_connection.html"
295
- )
291
+ except requests.ConnectionError:
292
+ no_connection_code = """
293
+ <div id="results_container">
294
+ <table>
295
+ <tr class="error">
296
+ <td>NA</td>
297
+ <td>NA</td>
298
+ <td>Sorry, but we could not make a connection</td>
299
+ </tr>
300
+ </table>
301
+ </div>
302
+ """
296
303
  soup = BeautifulSoup(no_connection_code, "lxml")
297
304
  # Convert string to result set
298
305
  results = soup.select("#results_container")
@@ -357,6 +364,6 @@ def get_project_validation(project_dir: str, type="html") -> list:
357
364
  if __name__ == "__main__":
358
365
  path = "tests/test_files/sample_with_errors.html"
359
366
  report = get_markup_validity(path)
360
- print("report is a {}.".format(type(report)))
367
+ print(f"report is a {type(report)}.")
361
368
  for item in report:
362
369
  print(item)
File without changes
File without changes