Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] qmk find #21096

Merged
merged 7 commits into from
Feb 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint
  • Loading branch information
elpekenin committed Nov 28, 2023
commit fd03188c60b40d1e2eb2ffd6f2192ab17cfc5506
27 changes: 5 additions & 22 deletions lib/python/qmk/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Functions for searching through QMK keyboards and keymaps.

Check failure on line 1 in lib/python/qmk/search.py

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
"""
import contextlib
import functools
Expand Down Expand Up @@ -64,20 +64,14 @@

def apply(self, target_info: TargetInfo) -> bool:
_kb, _km, info = target_info
return (
self.key in info
and len(info[self.key]) == int(self.value)
)
return (self.key in info and len(info[self.key]) == int(self.value))

class Contains(FilterFunction):
func_name = "contains"

def apply(self, target_info: TargetInfo) -> bool:
_kb, _km, info = target_info
return (
self.key in info
and self.value in info[self.key]
)
return (self.key in info and self.value in info[self.key])


def _get_filter_class(func_name: str, key: str, value: str) -> Optional[FilterFunction]:
Expand All @@ -94,10 +88,7 @@

def filter_help() -> str:
names = [f"'{f.func_name}'" for f in FilterFunction.__subclasses__()]
return (
", ".join(names[:-1])
+ f" and {names[-1]}"
)
return (", ".join(names[:-1]) + f" and {names[-1]}")

def _set_log_level(level):
cli.acquire_lock()
Expand Down Expand Up @@ -229,11 +220,7 @@
continue
valid_keymaps = filter(filter_class.apply, valid_keymaps)

value_str = (
f", {{fg_cyan}}{value}{{fg_reset}})"
if value is not None
else ""
)
value_str = (f", {{fg_cyan}}{value}{{fg_reset}})" if value is not None else "")
cli.log.info(f'Filtering on condition: {{fg_green}}{func_name}{{fg_reset}}({{fg_cyan}}{key}{{fg_reset}}{value_str}...')

elif equals_match is not None:
Expand All @@ -257,11 +244,7 @@
else:
cli.log.warning(f'Unrecognized filter expression: {filter_expr}')

# return filtered targets
return [
KeyboardKeymapBuildTarget(keyboard=kb, keymap=km, json=json)
for (kb, km, json) in valid_keymaps
]
return [KeyboardKeymapBuildTarget(keyboard=kb, keymap=km, json=json) for (kb, km, json) in valid_keymaps]


def search_keymap_targets(targets: List[Tuple[str, str]] = [('all', 'default')], filters: List[str] = []) -> List[BuildTarget]:
Expand Down
Loading