fastled 1.4.12__py3-none-any.whl → 1.4.13__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/__version__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # IMPORTANT! There's a bug in github which will REJECT any version update
2
2
  # that has any other change in the repo. Please bump the version as the
3
3
  # ONLY change in a commit, or else the pypi update and the release will fail.
4
- __version__ = "1.4.12"
4
+ __version__ = "1.4.13"
5
5
 
6
6
  __version_url_latest__ = "https://raw.githubusercontent.com/zackees/fastled-wasm/refs/heads/main/src/fastled/__version__.py"
fastled/print_filter.py CHANGED
@@ -1,52 +1,52 @@
1
- import re
2
- from abc import ABC, abstractmethod
3
- from enum import Enum
4
-
5
-
6
- class PrintFilter(ABC):
7
- """Abstract base class for filtering text output."""
8
-
9
- def __init__(self, echo: bool = True) -> None:
10
- self.echo = echo
11
-
12
- @abstractmethod
13
- def filter(self, text: str) -> str:
14
- """Filter the text according to implementation-specific rules."""
15
- pass
16
-
17
- def print(self, text: str | bytes) -> str:
18
- """Prints the text to the console after filtering."""
19
- if isinstance(text, bytes):
20
- text = text.decode("utf-8")
21
- text = self.filter(text)
22
- if self.echo:
23
- print(text, end="")
24
- return text
25
-
26
-
27
- def _handle_ino_cpp(line: str) -> str:
28
- if ".ino.cpp" in line[0:30]:
29
- # Extract the filename without path and extension
30
- match = re.search(r"src/([^/]+)\.ino\.cpp", line)
31
- if match:
32
- filename = match.group(1)
33
- # Replace with examples/Filename/Filename.ino format
34
- line = line.replace(
35
- f"src/{filename}.ino.cpp", f"examples/{filename}/{filename}.ino"
36
- )
37
- else:
38
- # Fall back to simple extension replacement if regex doesn't match
39
- line = line.replace(".ino.cpp", ".ino")
40
- return line
41
-
42
-
43
- class PrintFilterDefault(PrintFilter):
44
- """Provides default filtering for FastLED output."""
45
-
46
- def filter(self, text: str) -> str:
47
- return text
48
-
49
-
50
- class CompileOrLink(Enum):
51
- COMPILE = "compile"
52
- LINK = "link"
1
+ import re
2
+ from abc import ABC, abstractmethod
3
+ from enum import Enum
4
+
5
+
6
+ class PrintFilter(ABC):
7
+ """Abstract base class for filtering text output."""
8
+
9
+ def __init__(self, echo: bool = True) -> None:
10
+ self.echo = echo
11
+
12
+ @abstractmethod
13
+ def filter(self, text: str) -> str:
14
+ """Filter the text according to implementation-specific rules."""
15
+ pass
16
+
17
+ def print(self, text: str | bytes) -> str:
18
+ """Prints the text to the console after filtering."""
19
+ if isinstance(text, bytes):
20
+ text = text.decode("utf-8")
21
+ text = self.filter(text)
22
+ if self.echo:
23
+ print(text, end="")
24
+ return text
25
+
26
+
27
+ def _handle_ino_cpp(line: str) -> str:
28
+ if ".ino.cpp" in line[0:30]:
29
+ # Extract the filename without path and extension
30
+ match = re.search(r"src/([^/]+)\.ino\.cpp", line)
31
+ if match:
32
+ filename = match.group(1)
33
+ # Replace with examples/Filename/Filename.ino format
34
+ line = line.replace(
35
+ f"src/{filename}.ino.cpp", f"examples/{filename}/{filename}.ino"
36
+ )
37
+ else:
38
+ # Fall back to simple extension replacement if regex doesn't match
39
+ line = line.replace(".ino.cpp", ".ino")
40
+ return line
41
+
42
+
43
+ class PrintFilterDefault(PrintFilter):
44
+ """Provides default filtering for FastLED output."""
45
+
46
+ def filter(self, text: str) -> str:
47
+ return text
48
+
49
+
50
+ class CompileOrLink(Enum):
51
+ COMPILE = "compile"
52
+ LINK = "link"
fastled/string_diff.py CHANGED
@@ -1,165 +1,165 @@
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
- if not input_str.strip(): # Handle empty input
14
- return string_list
15
-
16
- input_chars = set(input_str.lower())
17
- filtered_list = []
18
- for s in string_list:
19
- # Check if at least half of the input characters are in the string
20
- s_chars = set(s.lower())
21
- common_chars = input_chars.intersection(s_chars)
22
- if len(common_chars) >= len(input_chars) / 2:
23
- filtered_list.append(s)
24
- return filtered_list
25
-
26
-
27
- def is_in_order_match(input_str: str, other: str) -> bool:
28
- """
29
- Check if the input string is an in-order match for any string in the list.
30
- An in-order match means that the characters of the input string appear
31
- in the same order in the string from the list, ignoring spaces in the input.
32
- """
33
-
34
- # Remove spaces from input string for matching
35
- input_chars = [c.lower() for c in input_str if c != " "]
36
- other_chars = [c.lower() for c in other]
37
- input_index = 0
38
- other_index = 0
39
- while input_index < len(input_chars) and other_index < len(other_chars):
40
- if input_chars[input_index] == other_chars[other_index]:
41
- input_index += 1
42
- other_index += 1
43
- # If we reached the end of the input string, it means all characters were found in order
44
- if input_index == len(input_chars):
45
- return True
46
- return False
47
-
48
-
49
- # Returns the min distance strings. If there is a tie, it returns
50
- # all the strings that have the same min distance.
51
- # Returns a tuple of index and string.
52
- def string_diff(
53
- input_string: str, string_list: list[str], ignore_case=True
54
- ) -> list[tuple[float, str]]:
55
-
56
- def normalize(s: str) -> str:
57
- return s.lower() if ignore_case else s
58
-
59
- # Handle empty input or empty list
60
- if not input_string.strip():
61
- # Return all strings with equal distance for empty input
62
- return [(i, s) for i, s in enumerate(string_list)]
63
-
64
- if not string_list:
65
- return []
66
-
67
- map_string: dict[str, str] = {}
68
-
69
- if ignore_case:
70
- map_string = {s.lower(): s for s in string_list}
71
- else:
72
- map_string = {s: s for s in string_list}
73
-
74
- original_string_list = string_list.copy()
75
- if ignore_case:
76
- string_list = [s.lower() for s in string_list]
77
- input_string = input_string.lower()
78
-
79
- # Check for exact matches, but also check if there are other substring matches
80
- exact_matches = [s for s in string_list if s == input_string]
81
- substring_matches = [s for s in string_list if input_string in s]
82
-
83
- # If there's an exact match AND other substring matches, return all substring matches
84
- # This provides better user experience for partial matching
85
- if exact_matches and len(substring_matches) > 1:
86
- out: list[tuple[float, str]] = []
87
- for i, s in enumerate(substring_matches):
88
- s_mapped = map_string.get(s, s)
89
- out.append((i, s_mapped))
90
- return out
91
-
92
- # If there's only an exact match and no other substring matches, return just the exact match
93
- if exact_matches and len(substring_matches) == 1:
94
- out: list[tuple[float, str]] = []
95
- for i, s in enumerate(exact_matches):
96
- s_mapped = map_string.get(s, s)
97
- out.append((i, s_mapped))
98
- return out
99
-
100
- # Apply set membership filtering for queries with 3+ characters
101
- if len(input_string.strip()) >= 3:
102
- filtered = _filter_out_obvious_bad_choices(input_string, string_list)
103
- if filtered: # Only apply filter if it doesn't eliminate everything
104
- string_list = filtered
105
-
106
- # Second filter: exact substring filtering if applicable
107
- if substring_matches:
108
- string_list = substring_matches
109
- # Return all substring matches
110
- out: list[tuple[float, str]] = []
111
- for i, s in enumerate(string_list):
112
- s_mapped = map_string.get(s, s)
113
- out.append((i, s_mapped))
114
- return out
115
-
116
- # Third filter: in order exact match filtering if applicable.
117
- in_order_matches = [s for s in string_list if is_in_order_match(input_string, s)]
118
- if in_order_matches:
119
- string_list = in_order_matches
120
-
121
- # Calculate distances
122
- distances: list[float] = []
123
- for s in string_list:
124
- dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
125
- distances.append(1.0 / (dist + 1.0))
126
-
127
- # Handle case where no strings remain after filtering
128
- if not distances:
129
- # Fall back to original list and calculate distances
130
- string_list = original_string_list.copy()
131
- if ignore_case:
132
- string_list = [s.lower() for s in string_list]
133
-
134
- distances = []
135
- for s in string_list:
136
- dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
137
- distances.append(1.0 / (dist + 1.0))
138
-
139
- min_distance = min(distances)
140
- out: list[tuple[float, str]] = []
141
- for i, d in enumerate(distances):
142
- if d == min_distance:
143
- s = string_list[i]
144
- s_mapped = map_string.get(s, s)
145
- out.append((i, s_mapped))
146
-
147
- return out
148
-
149
-
150
- def string_diff_paths(
151
- input_string: str | Path, path_list: list[Path], ignore_case=True
152
- ) -> list[tuple[float, Path]]:
153
- # Normalize path separators to forward slashes for consistent comparison
154
- string_list = [str(p).replace("\\", "/") for p in path_list]
155
- input_str = str(input_string).replace("\\", "/")
156
-
157
- tmp = string_diff(input_str, string_list, ignore_case)
158
- out: list[tuple[float, Path]] = []
159
- for i, j in tmp:
160
- # Find the original path that matches the normalized result
161
- for idx, orig_path in enumerate(path_list):
162
- if str(orig_path).replace("\\", "/") == j:
163
- out.append((i, orig_path))
164
- break
165
- 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
+ if not input_str.strip(): # Handle empty input
14
+ return string_list
15
+
16
+ input_chars = set(input_str.lower())
17
+ filtered_list = []
18
+ for s in string_list:
19
+ # Check if at least half of the input characters are in the string
20
+ s_chars = set(s.lower())
21
+ common_chars = input_chars.intersection(s_chars)
22
+ if len(common_chars) >= len(input_chars) / 2:
23
+ filtered_list.append(s)
24
+ return filtered_list
25
+
26
+
27
+ def is_in_order_match(input_str: str, other: str) -> bool:
28
+ """
29
+ Check if the input string is an in-order match for any string in the list.
30
+ An in-order match means that the characters of the input string appear
31
+ in the same order in the string from the list, ignoring spaces in the input.
32
+ """
33
+
34
+ # Remove spaces from input string for matching
35
+ input_chars = [c.lower() for c in input_str if c != " "]
36
+ other_chars = [c.lower() for c in other]
37
+ input_index = 0
38
+ other_index = 0
39
+ while input_index < len(input_chars) and other_index < len(other_chars):
40
+ if input_chars[input_index] == other_chars[other_index]:
41
+ input_index += 1
42
+ other_index += 1
43
+ # If we reached the end of the input string, it means all characters were found in order
44
+ if input_index == len(input_chars):
45
+ return True
46
+ return False
47
+
48
+
49
+ # Returns the min distance strings. If there is a tie, it returns
50
+ # all the strings that have the same min distance.
51
+ # Returns a tuple of index and string.
52
+ def string_diff(
53
+ input_string: str, string_list: list[str], ignore_case=True
54
+ ) -> list[tuple[float, str]]:
55
+
56
+ def normalize(s: str) -> str:
57
+ return s.lower() if ignore_case else s
58
+
59
+ # Handle empty input or empty list
60
+ if not input_string.strip():
61
+ # Return all strings with equal distance for empty input
62
+ return [(i, s) for i, s in enumerate(string_list)]
63
+
64
+ if not string_list:
65
+ return []
66
+
67
+ map_string: dict[str, str] = {}
68
+
69
+ if ignore_case:
70
+ map_string = {s.lower(): s for s in string_list}
71
+ else:
72
+ map_string = {s: s for s in string_list}
73
+
74
+ original_string_list = string_list.copy()
75
+ if ignore_case:
76
+ string_list = [s.lower() for s in string_list]
77
+ input_string = input_string.lower()
78
+
79
+ # Check for exact matches, but also check if there are other substring matches
80
+ exact_matches = [s for s in string_list if s == input_string]
81
+ substring_matches = [s for s in string_list if input_string in s]
82
+
83
+ # If there's an exact match AND other substring matches, return all substring matches
84
+ # This provides better user experience for partial matching
85
+ if exact_matches and len(substring_matches) > 1:
86
+ out: list[tuple[float, str]] = []
87
+ for i, s in enumerate(substring_matches):
88
+ s_mapped = map_string.get(s, s)
89
+ out.append((i, s_mapped))
90
+ return out
91
+
92
+ # If there's only an exact match and no other substring matches, return just the exact match
93
+ if exact_matches and len(substring_matches) == 1:
94
+ out: list[tuple[float, str]] = []
95
+ for i, s in enumerate(exact_matches):
96
+ s_mapped = map_string.get(s, s)
97
+ out.append((i, s_mapped))
98
+ return out
99
+
100
+ # Apply set membership filtering for queries with 3+ characters
101
+ if len(input_string.strip()) >= 3:
102
+ filtered = _filter_out_obvious_bad_choices(input_string, string_list)
103
+ if filtered: # Only apply filter if it doesn't eliminate everything
104
+ string_list = filtered
105
+
106
+ # Second filter: exact substring filtering if applicable
107
+ if substring_matches:
108
+ string_list = substring_matches
109
+ # Return all substring matches
110
+ out: list[tuple[float, str]] = []
111
+ for i, s in enumerate(string_list):
112
+ s_mapped = map_string.get(s, s)
113
+ out.append((i, s_mapped))
114
+ return out
115
+
116
+ # Third filter: in order exact match filtering if applicable.
117
+ in_order_matches = [s for s in string_list if is_in_order_match(input_string, s)]
118
+ if in_order_matches:
119
+ string_list = in_order_matches
120
+
121
+ # Calculate distances
122
+ distances: list[float] = []
123
+ for s in string_list:
124
+ dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
125
+ distances.append(1.0 / (dist + 1.0))
126
+
127
+ # Handle case where no strings remain after filtering
128
+ if not distances:
129
+ # Fall back to original list and calculate distances
130
+ string_list = original_string_list.copy()
131
+ if ignore_case:
132
+ string_list = [s.lower() for s in string_list]
133
+
134
+ distances = []
135
+ for s in string_list:
136
+ dist = fuzz.token_sort_ratio(normalize(input_string), normalize(s))
137
+ distances.append(1.0 / (dist + 1.0))
138
+
139
+ min_distance = min(distances)
140
+ out: list[tuple[float, str]] = []
141
+ for i, d in enumerate(distances):
142
+ if d == min_distance:
143
+ s = string_list[i]
144
+ s_mapped = map_string.get(s, s)
145
+ out.append((i, s_mapped))
146
+
147
+ return out
148
+
149
+
150
+ def string_diff_paths(
151
+ input_string: str | Path, path_list: list[Path], ignore_case=True
152
+ ) -> list[tuple[float, Path]]:
153
+ # Normalize path separators to forward slashes for consistent comparison
154
+ string_list = [str(p).replace("\\", "/") for p in path_list]
155
+ input_str = str(input_string).replace("\\", "/")
156
+
157
+ tmp = string_diff(input_str, string_list, ignore_case)
158
+ out: list[tuple[float, Path]] = []
159
+ for i, j in tmp:
160
+ # Find the original path that matches the normalized result
161
+ for idx, orig_path in enumerate(path_list):
162
+ if str(orig_path).replace("\\", "/") == j:
163
+ out.append((i, orig_path))
164
+ break
165
+ return out
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()