pymake

A build system based on Build Systems à la Carte
git clone https://git.grace.moe/pymake
Log | Files | Refs | README

commit 5ce8b7bc6309bf3c1ee0071fb239e79fcc043800
parent 7fc5bfcf341c686524755e71d8e835833134a544
Author: gracefu <81774659+gracefuu@users.noreply.github.com>
Date:   Tue, 15 Apr 2025 18:10:47 +0800

Move stuff into classes

Diffstat:
Mmake.py | 28++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/make.py b/make.py @@ -201,16 +201,16 @@ rawrule = _rules.rawrule cache = _rules.cache() -def _fNone(): - return None - - class Store: + @staticmethod + def _fNone(): + return None + def __init__(self, filename, rules): self.filename = filename self.rules = rules - self.key_value = collections.defaultdict(_fNone) + self.key_value = collections.defaultdict(Store._fNone) self.key_info = collections.defaultdict(list) try: @@ -230,13 +230,17 @@ class Store: self.save() -_background_tasks = set() +class Detach: + def __init__(self): + self._background_tasks = set() + + def __call__(self, *args, **kwargs): + task = asyncio.create_task(*args, **kwargs) + self._background_tasks.add(task) + task.add_done_callback(self._background_tasks.discard) -def detach(*args, **kwargs): - task = asyncio.create_task(*args, **kwargs) - _background_tasks.add(task) - task.add_done_callback(_background_tasks.discard) +detach = Detach() class SuspendingFetch: @@ -246,8 +250,8 @@ class SuspendingFetch: self.waits = dict() async def wait(self): - while _background_tasks: - await asyncio.gather(*_background_tasks) + while detach._background_tasks: + await asyncio.gather(*detach._background_tasks) async def fetch(self, task: Task): task_key = task.task_key