Skip to content

Commit

Permalink
fix(search_cli; test: cli): new workaround for #298
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Feb 9, 2022
1 parent 65f4e85 commit fdf7baf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
25 changes: 19 additions & 6 deletions pikaur/search_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def filter_aur_results(
return filtered_results


def package_search_thread_aur(queries: List[str]) -> Dict[str, List[Any]]: # pylint: disable=too-many-branches
def package_search_thread_aur(queries: List[str]) -> List[Any]: # pylint: disable=too-many-branches
args = parse_args()
result = {}
filtered_result = {}
if queries:
use_as_filters: List[str] = []
with ThreadPool() as pool:
Expand All @@ -59,6 +60,7 @@ def package_search_thread_aur(queries: List[str]) -> Dict[str, List[Any]]: # py
for query, request in requests.items():
try:
result[query] = request.get()
filtered_result[query] = result[query]
except AURError as exc:
if exc.error == "Too many package results.":
print_error(
Expand All @@ -76,9 +78,16 @@ def package_search_thread_aur(queries: List[str]) -> Dict[str, List[Any]]: # py
use_as_filters.append(query)
else:
raise
else:
# @TODO:
# https://github.com/actionless/pikaur/issues/298
# - broken in a different way in AUR RPC now?
if len(result[query]) == 5000:
use_as_filters.append(query)
del filtered_result[query]
pool.join()
for query in use_as_filters:
result = filter_aur_results(result, query)
filtered_result = filter_aur_results(filtered_result, query)
if args.namesonly:
for subindex, subresult in result.items():
result[subindex] = [
Expand All @@ -98,7 +107,11 @@ def package_search_thread_aur(queries: List[str]) -> Dict[str, List[Any]]: # py
result = {'all': get_all_aur_packages()}
if not args.quiet:
sys.stderr.write('#')
return result
joined_aur_results = list(set(
list(join_search_results(list(result.values()))) +
list(join_search_results(list(filtered_result.values())))
))
return joined_aur_results


def package_search_thread_local() -> Dict[str, str]:
Expand All @@ -114,6 +127,8 @@ def package_search_thread_local() -> Dict[str, str]:
def join_search_results(
all_search_results: List[List[SamePackageType]]
) -> Iterable[SamePackageType]:
if not all_search_results:
return []
pkgnames_set: Set[str] = set()
for search_results in all_search_results:
new_pkgnames_set = set(get_pkg_id(result) for result in search_results)
Expand Down Expand Up @@ -173,9 +188,7 @@ def cli_search_packages(enumerated=False) -> List[AnyPackage]: # pylint: disabl
joined_repo_results: Iterable[pyalpm.Package] = []
if result_repo:
joined_repo_results = join_search_results(result_repo)
joined_aur_results: Iterable[AURPackageInfo] = []
if result_aur:
joined_aur_results = join_search_results(list(result_aur.values()))
joined_aur_results: Iterable[AURPackageInfo] = result_aur or []

return print_package_search_results(
repo_packages=joined_repo_results,
Expand Down
15 changes: 8 additions & 7 deletions pikaur_test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def test_search_multiword(self):
def test_search_multiword_too_many(self):
"""
https://github.com/actionless/pikaur/issues/298
- broken in a different way in AUR RPC now?
"""
proc_aur_too_many = pikaur('-Ssq --aur python', capture_stderr=True)
self.assertIn(
"Too many package results for 'python'",
proc_aur_too_many.stderr
)
result_aur_too_many = proc_aur_too_many.stdout.splitlines()
self.assertEqual(len(result_aur_too_many), 0)
# proc_aur_too_many = pikaur('-Ssq --aur python', capture_stderr=True)
# self.assertIn(
# "Too many package results for 'python'",
# proc_aur_too_many.stderr
# )
# result_aur_too_many = proc_aur_too_many.stdout.splitlines()
# self.assertEqual(len(result_aur_too_many), 0)

result_aur_second = pikaur('-Ssq --aur opencv').stdout.splitlines()
self.assertIn('python-imutils', result_aur_second)
Expand Down

0 comments on commit fdf7baf

Please sign in to comment.