fastled 1.3.4__py3-none-any.whl → 1.3.6__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/types.py CHANGED
@@ -1,96 +1,11 @@
1
- import argparse
2
1
  from dataclasses import dataclass
3
2
  from enum import Enum
4
- from pathlib import Path
5
3
  from typing import Any
6
4
 
5
+ from fastled.args import Args
7
6
  from fastled.print_filter import PrintFilterFastled
8
7
 
9
8
 
10
- @dataclass
11
- class Args:
12
- directory: Path | None
13
- init: bool | str
14
- just_compile: bool
15
- web: str | None
16
- interactive: bool
17
- profile: bool
18
- force_compile: bool
19
- auto_update: bool | None
20
- update: bool
21
- localhost: bool
22
- build: bool
23
- server: bool
24
- purge: bool
25
- debug: bool
26
- quick: bool
27
- release: bool
28
-
29
- @staticmethod
30
- def from_namespace(args: argparse.Namespace) -> "Args":
31
- assert isinstance(
32
- args.directory, str | None
33
- ), f"expected str | None, got {type(args.directory)}"
34
- assert isinstance(
35
- args.init, bool | str | None
36
- ), f"expected bool, got {type(args.init)}"
37
- assert isinstance(
38
- args.just_compile, bool
39
- ), f"expected bool, got {type(args.just_compile)}"
40
- assert isinstance(
41
- args.web, str | None
42
- ), f"expected str | None, got {type(args.web)}"
43
- assert isinstance(
44
- args.interactive, bool
45
- ), f"expected bool, got {type(args.interactive)}"
46
- assert isinstance(
47
- args.profile, bool
48
- ), f"expected bool, got {type(args.profile)}"
49
- assert isinstance(
50
- args.force_compile, bool
51
- ), f"expected bool, got {type(args.force_compile)}"
52
- assert isinstance(
53
- args.no_auto_updates, bool | None
54
- ), f"expected bool | None, got {type(args.no_auto_updates)}"
55
- assert isinstance(args.update, bool), f"expected bool, got {type(args.update)}"
56
- assert isinstance(
57
- args.localhost, bool
58
- ), f"expected bool, got {type(args.localhost)}"
59
- assert isinstance(args.build, bool), f"expected bool, got {type(args.build)}"
60
- assert isinstance(args.server, bool), f"expected bool, got {type(args.server)}"
61
- assert isinstance(args.purge, bool), f"expected bool, got {type(args.purge)}"
62
- assert isinstance(args.debug, bool), f"expected bool, got {type(args.debug)}"
63
- assert isinstance(args.quick, bool), f"expected bool, got {type(args.quick)}"
64
- assert isinstance(
65
- args.release, bool
66
- ), f"expected bool, got {type(args.release)}"
67
- init: bool | str = False
68
- if args.init is None:
69
- init = False
70
- elif isinstance(args.init, bool):
71
- init = args.init
72
- elif isinstance(args.init, str):
73
- init = args.init
74
- return Args(
75
- directory=Path(args.directory) if args.directory else None,
76
- init=init,
77
- just_compile=args.just_compile,
78
- web=args.web,
79
- interactive=args.interactive,
80
- profile=args.profile,
81
- force_compile=args.force_compile,
82
- auto_update=not args.no_auto_updates,
83
- update=args.update,
84
- localhost=args.localhost,
85
- build=args.build,
86
- server=args.server,
87
- purge=args.purge,
88
- debug=args.debug,
89
- quick=args.quick,
90
- release=args.release,
91
- )
92
-
93
-
94
9
  @dataclass
95
10
  class CompileResult:
96
11
  success: bool
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()