fastled 1.3.19__py3-none-any.whl → 1.3.21__py3-none-any.whl

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.
fastled/string_diff.py CHANGED
@@ -1,82 +1,82 @@
1
- from pathlib import Path
2
-
3
- from rapidfuzz import fuzz
4
-
5
-
6
- def _filter_out_obvious_bad_choices(
7
- input_str: str, string_list: list[str]
8
- ) -> list[str]:
9
- """
10
- Filter out strings that are too different from the input string.
11
- This is a heuristic and may not be perfect.
12
- """
13
- input_chars = set(input_str)
14
- filtered_list = []
15
- for s in string_list:
16
- # Check if at least half of the input characters are in the string
17
- s_chars = set(s)
18
- common_chars = input_chars.intersection(s_chars)
19
- if len(common_chars) >= len(input_chars) / 2:
20
- filtered_list.append(s)
21
- return filtered_list
22
-
23
-
24
- # Returns the min distance strings. If there is a tie, it returns
25
- # all the strings that have the same min distance.
26
- # Returns a tuple of index and string.
27
- def string_diff(
28
- input_string: str, string_list: list[str], ignore_case=True
29
- ) -> list[tuple[float, str]]:
30
-
31
- def normalize(s: str) -> str:
32
- return s.lower() if ignore_case else s
33
-
34
- map_string: dict[str, str] = {}
35
-
36
- if ignore_case:
37
- map_string = {s.lower(): s for s in string_list}
38
- else:
39
- map_string = {s: s for s in string_list}
40
-
41
- if ignore_case:
42
- string_list = [s.lower() for s in string_list]
43
- input_string = input_string.lower()
44
-
45
- # Apply set membership filtering for queries with 3+ characters
46
- if len(input_string) >= 3:
47
- string_list = _filter_out_obvious_bad_choices(input_string, string_list)
48
-
49
- is_substring = False
50
- for s in string_list:
51
- if input_string in s:
52
- is_substring = True
53
- break
54
-
55
- if is_substring:
56
- string_list = [s for s in string_list if input_string in s]
57
-
58
- distances: list[float] = []
59
- for s in string_list:
60
- dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
61
- distances.append(1.0 / (dist + 1.0))
62
- min_distance = min(distances)
63
- out: list[tuple[float, str]] = []
64
- for i, d in enumerate(distances):
65
- if d == min_distance:
66
- s = string_list[i]
67
- s_mapped = map_string.get(s, s)
68
- out.append((i, s_mapped))
69
-
70
- return out
71
-
72
-
73
- def string_diff_paths(
74
- input_string: str | Path, path_list: list[Path], ignore_case=True
75
- ) -> list[tuple[float, Path]]:
76
- string_list = [str(p) for p in path_list]
77
- tmp = string_diff(str(input_string), string_list, ignore_case)
78
- out: list[tuple[float, Path]] = []
79
- for i, j in tmp:
80
- p = Path(j)
81
- out.append((i, p))
82
- return out
1
+ from pathlib import Path
2
+
3
+ from rapidfuzz import fuzz
4
+
5
+
6
+ def _filter_out_obvious_bad_choices(
7
+ input_str: str, string_list: list[str]
8
+ ) -> list[str]:
9
+ """
10
+ Filter out strings that are too different from the input string.
11
+ This is a heuristic and may not be perfect.
12
+ """
13
+ input_chars = set(input_str)
14
+ filtered_list = []
15
+ for s in string_list:
16
+ # Check if at least half of the input characters are in the string
17
+ s_chars = set(s)
18
+ common_chars = input_chars.intersection(s_chars)
19
+ if len(common_chars) >= len(input_chars) / 2:
20
+ filtered_list.append(s)
21
+ return filtered_list
22
+
23
+
24
+ # Returns the min distance strings. If there is a tie, it returns
25
+ # all the strings that have the same min distance.
26
+ # Returns a tuple of index and string.
27
+ def string_diff(
28
+ input_string: str, string_list: list[str], ignore_case=True
29
+ ) -> list[tuple[float, str]]:
30
+
31
+ def normalize(s: str) -> str:
32
+ return s.lower() if ignore_case else s
33
+
34
+ map_string: dict[str, str] = {}
35
+
36
+ if ignore_case:
37
+ map_string = {s.lower(): s for s in string_list}
38
+ else:
39
+ map_string = {s: s for s in string_list}
40
+
41
+ if ignore_case:
42
+ string_list = [s.lower() for s in string_list]
43
+ input_string = input_string.lower()
44
+
45
+ # Apply set membership filtering for queries with 3+ characters
46
+ if len(input_string) >= 3:
47
+ string_list = _filter_out_obvious_bad_choices(input_string, string_list)
48
+
49
+ is_substring = False
50
+ for s in string_list:
51
+ if input_string in s:
52
+ is_substring = True
53
+ break
54
+
55
+ if is_substring:
56
+ string_list = [s for s in string_list if input_string in s]
57
+
58
+ distances: list[float] = []
59
+ for s in string_list:
60
+ dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
61
+ distances.append(1.0 / (dist + 1.0))
62
+ min_distance = min(distances)
63
+ out: list[tuple[float, str]] = []
64
+ for i, d in enumerate(distances):
65
+ if d == min_distance:
66
+ s = string_list[i]
67
+ s_mapped = map_string.get(s, s)
68
+ out.append((i, s_mapped))
69
+
70
+ return out
71
+
72
+
73
+ def string_diff_paths(
74
+ input_string: str | Path, path_list: list[Path], ignore_case=True
75
+ ) -> list[tuple[float, Path]]:
76
+ string_list = [str(p) for p in path_list]
77
+ tmp = string_diff(str(input_string), string_list, ignore_case)
78
+ out: list[tuple[float, Path]] = []
79
+ for i, j in tmp:
80
+ p = Path(j)
81
+ out.append((i, p))
82
+ return out
fastled/util.py CHANGED
@@ -19,7 +19,8 @@ def banner_string(msg: str) -> str:
19
19
  for line in lines:
20
20
  out.append(f"# {line} " + " " * (max_length - len(line)) + "#")
21
21
  out.append(border)
22
- return "\n".join(out)
22
+ outstr = "\n".join(out)
23
+ return f"\n{outstr}\n"
23
24
 
24
25
 
25
26
  def print_banner(msg: str) -> None:
fastled/version.py CHANGED
@@ -1,41 +1,41 @@
1
- from concurrent.futures import Future, ThreadPoolExecutor
2
-
3
- import httpx
4
-
5
- from fastled.__version__ import __version_url_latest__
6
-
7
-
8
- def _fetch_version() -> str | Exception:
9
- """
10
- Helper function to fetch the latest version from the GitHub repository.
11
- """
12
- try:
13
- response = httpx.get(__version_url_latest__)
14
- response.raise_for_status()
15
- # Extract the version string from the response text
16
- version_line = response.text.split("__version__ = ")[1].split('"')[1]
17
- return version_line
18
- except Exception as e:
19
- return e
20
-
21
-
22
- def get_latest_version() -> Future[str | Exception]:
23
- """
24
- Fetch the latest version from the GitHub repository.
25
- Returns a future that will resolve with the version string or an exception.
26
- """
27
- executor = ThreadPoolExecutor()
28
- return executor.submit(_fetch_version)
29
-
30
-
31
- def unit_test() -> None:
32
- future = get_latest_version()
33
- latest_version = future.result() # Wait for the future to complete
34
- if isinstance(latest_version, Exception):
35
- print(f"Error fetching latest version: {latest_version}")
36
- else:
37
- print(f"Latest version: {latest_version}")
38
-
39
-
40
- if __name__ == "__main__":
41
- unit_test()
1
+ from concurrent.futures import Future, ThreadPoolExecutor
2
+
3
+ import httpx
4
+
5
+ from fastled.__version__ import __version_url_latest__
6
+
7
+
8
+ def _fetch_version() -> str | Exception:
9
+ """
10
+ Helper function to fetch the latest version from the GitHub repository.
11
+ """
12
+ try:
13
+ response = httpx.get(__version_url_latest__)
14
+ response.raise_for_status()
15
+ # Extract the version string from the response text
16
+ version_line = response.text.split("__version__ = ")[1].split('"')[1]
17
+ return version_line
18
+ except Exception as e:
19
+ return e
20
+
21
+
22
+ def get_latest_version() -> Future[str | Exception]:
23
+ """
24
+ Fetch the latest version from the GitHub repository.
25
+ Returns a future that will resolve with the version string or an exception.
26
+ """
27
+ executor = ThreadPoolExecutor()
28
+ return executor.submit(_fetch_version)
29
+
30
+
31
+ def unit_test() -> None:
32
+ future = get_latest_version()
33
+ latest_version = future.result() # Wait for the future to complete
34
+ if isinstance(latest_version, Exception):
35
+ print(f"Error fetching latest version: {latest_version}")
36
+ else:
37
+ print(f"Latest version: {latest_version}")
38
+
39
+
40
+ if __name__ == "__main__":
41
+ unit_test()
fastled/web_compile.py CHANGED
@@ -182,7 +182,7 @@ def _banner(msg: str) -> str:
182
182
 
183
183
  # Add the bottom border
184
184
  banner += "#" * width + "\n"
185
- return banner
185
+ return f"\n{banner}\n"
186
186
 
187
187
 
188
188
  def _print_banner(msg: str) -> None: