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

feat/towards writer extension point #258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions nvchecker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import structlog

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

logger = structlog.get_logger(logger_name=__name__)
Expand Down Expand Up @@ -80,24 +80,24 @@ 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))
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))
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]
vers = core.read_verfile(newverf)
vers.update(newvers)
vers.update({k: r.version for k, r in results.items()})
core.write_verfile(newverf, vers)

if args.failures and has_failures:
sys.exit(3)

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

Expand Down
2 changes: 2 additions & 0 deletions nvchecker/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class Result(NamedTuple):
gitref: Optional[str]
revision: Optional[str]

ResultData = Dict[str, Result]

class BaseWorker:
'''The base class for defining `Worker` classes for source plugins.

Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ 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)
return vers
results, _has_failures = await main.run(result_coro, runner_coro)
return {k: r.version for k, r in results.items()}

@pytest_asyncio.fixture(scope="session")
async def get_version():
Expand Down
Loading