fastled 1.2.96__py3-none-any.whl → 1.2.98__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/__init__.py +1 -1
- fastled/client_server.py +513 -513
- fastled/compile_server_impl.py +355 -355
- fastled/docker_manager.py +987 -987
- fastled/open_browser.py +137 -137
- fastled/print_filter.py +190 -190
- fastled/project_init.py +129 -129
- fastled/server_flask.py +2 -8
- fastled/site/build.py +449 -449
- fastled/string_diff.py +82 -82
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/METADATA +471 -471
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/RECORD +16 -16
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/WHEEL +0 -0
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/entry_points.txt +0 -0
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/licenses/LICENSE +0 -0
- {fastled-1.2.96.dist-info → fastled-1.2.98.dist-info}/top_level.txt +0 -0
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
|