Skip to content

Commit

Permalink
feat: return full results from result processing
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Mar 13, 2024
1 parent 9dd7fb1 commit 87ed641
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions nvchecker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import sys
import argparse
import asyncio
from typing import Coroutine, Tuple
from typing import Coroutine, Tuple, List
from pathlib import Path

import structlog

from . import core
from .util import VersData, RawResult, KeyManager, EntryWaiter
from .util import VersData, RawResult, Result, KeyManager, EntryWaiter
from .ctxvars import proxy as ctx_proxy

logger = structlog.get_logger(logger_name=__name__)
Expand Down Expand Up @@ -80,10 +80,10 @@ def main() -> None:

if sys.version_info >= (3, 10):
# Python 3.10 has deprecated asyncio.get_event_loop
newvers, has_failures = asyncio.run(run(result_coro, runner_coro))
newvers, results, has_failures = asyncio.run(run(result_coro, runner_coro))
else:
# Python < 3.10 will create an eventloop when asyncio.Queue is initialized
newvers, has_failures = asyncio.get_event_loop().run_until_complete(run(result_coro, runner_coro))
newvers, results, has_failures = asyncio.get_event_loop().run_until_complete(run(result_coro, runner_coro))

if options.ver_files is not None:
newverf = options.ver_files[1]
Expand All @@ -95,9 +95,9 @@ def main() -> None:
sys.exit(3)

async def run(
result_coro: Coroutine[None, None, Tuple[VersData, bool]],
result_coro: Coroutine[None, None, Tuple[VersData, List[Result], bool]],
runner_coro: Coroutine[None, None, None],
) -> Tuple[VersData, bool]:
) -> Tuple[VersData, List[Result], bool]:
result_fu = asyncio.create_task(result_coro)
runner_fu = asyncio.create_task(runner_coro)
await runner_fu
Expand Down
6 changes: 4 additions & 2 deletions nvchecker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ async def process_result(
result_q: Queue[RawResult],
entry_waiter: EntryWaiter,
verbose: bool = False,
) -> Tuple[VersData, bool]:
) -> Tuple[VersData, List[Result], bool]:
ret = {}
results = []
has_failures = False
try:
while True:
Expand All @@ -412,8 +413,9 @@ async def process_result(
check_version_update(oldvers, r1, verbose)
entry_waiter.set_result(r1.name, r1.version)
ret[r1.name] = r1.version
results.append(r1)
except asyncio.CancelledError:
return ret, has_failures
return ret, results, has_failures

async def run_tasks(
futures: Sequence[Awaitable[None]]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def run(
result_coro = core.process_result(oldvers, result_q, entry_waiter)
runner_coro = core.run_tasks(futures)

vers, _has_failures = await main.run(result_coro, runner_coro)
vers, _results, _has_failures = await main.run(result_coro, runner_coro)
return vers

@pytest_asyncio.fixture(scope="session")
Expand Down

0 comments on commit 87ed641

Please sign in to comment.