dycw-utilities 0.129.0__py3-none-any.whl → 0.129.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.129.0
3
+ Version: 0.129.2
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
7
- Requires-Dist: typing-extensions<4.14,>=4.13.1
7
+ Requires-Dist: typing-extensions<4.15,>=4.14.0
8
8
  Provides-Extra: test
9
9
  Requires-Dist: dycw-pytest-only<2.2,>=2.1.1; extra == 'test'
10
- Requires-Dist: hypothesis<6.134,>=6.133.0; extra == 'test'
10
+ Requires-Dist: hypothesis<6.136,>=6.135.0; extra == 'test'
11
11
  Requires-Dist: pytest-asyncio<1.1,>=1.0.0; extra == 'test'
12
12
  Requires-Dist: pytest-cov<6.2,>=6.1.1; extra == 'test'
13
13
  Requires-Dist: pytest-instafail<0.6,>=0.5.0; extra == 'test'
@@ -77,7 +77,7 @@ Provides-Extra: zzz-test-hypothesis
77
77
  Requires-Dist: aiosqlite<0.22,>=0.21.0; extra == 'zzz-test-hypothesis'
78
78
  Requires-Dist: asyncpg<0.31,>=0.30.0; extra == 'zzz-test-hypothesis'
79
79
  Requires-Dist: greenlet<3.3,>=3.2.0; extra == 'zzz-test-hypothesis'
80
- Requires-Dist: hypothesis<6.134,>=6.133.0; extra == 'zzz-test-hypothesis'
80
+ Requires-Dist: hypothesis<6.136,>=6.135.0; extra == 'zzz-test-hypothesis'
81
81
  Requires-Dist: luigi<3.7,>=3.6.0; extra == 'zzz-test-hypothesis'
82
82
  Requires-Dist: numpy<2.3,>=2.2.6; extra == 'zzz-test-hypothesis'
83
83
  Requires-Dist: pathvalidate<3.3,>=3.2.3; extra == 'zzz-test-hypothesis'
@@ -1,6 +1,6 @@
1
- utilities/__init__.py,sha256=SLPkIGR28QU6Zy5OKMEX-IvxA2c0MLdH8FuPAUwRzrc,60
1
+ utilities/__init__.py,sha256=xCbJwDm5euQ0FhR3M7TD-JZyt1BghWGAEn2rH1dZO9k,60
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
- utilities/asyncio.py,sha256=OIQ4JddpQw8tSubzwDR0WyqQ-uE-L5DdbwuTqRQK5MQ,38202
3
+ utilities/asyncio.py,sha256=mP67R3RwY6cTCgiNlxA9h-o3Y6xv5uGzKKB08C49uKI,37001
4
4
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
5
5
  utilities/atools.py,sha256=IYMuFSFGSKyuQmqD6v5IUtDlz8PPw0Sr87Cub_gRU3M,1168
6
6
  utilities/cachetools.py,sha256=C1zqOg7BYz0IfQFK8e3qaDDgEZxDpo47F15RTfJM37Q,2910
@@ -89,7 +89,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
89
89
  utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
90
90
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
91
91
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
92
- dycw_utilities-0.129.0.dist-info/METADATA,sha256=FRizi23CYGCVbYnOw9jcaTlerh4kCxHwLLm-Tpi-XR4,12803
93
- dycw_utilities-0.129.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.129.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.129.0.dist-info/RECORD,,
92
+ dycw_utilities-0.129.2.dist-info/METADATA,sha256=2XZ9vn3lnybj_7rhJwuTFSU8SVBRLkroYURNVY1_9sc,12803
93
+ dycw_utilities-0.129.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
+ dycw_utilities-0.129.2.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
+ dycw_utilities-0.129.2.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.129.0"
3
+ __version__ = "0.129.2"
utilities/asyncio.py CHANGED
@@ -458,7 +458,9 @@ class Looper(Generic[_T]):
458
458
  """Remove and return an item from the end of the queue without blocking."""
459
459
  return self._queue.get_right_nowait()
460
460
 
461
- async def initialize(self, *, sleep_if_failure: bool) -> Exception | None:
461
+ async def initialize(
462
+ self, *, skip_sleep_if_failure: bool = False
463
+ ) -> Exception | None:
462
464
  """Initialize the looper."""
463
465
  match self._is_initializing.is_set():
464
466
  case True:
@@ -476,21 +478,21 @@ class Looper(Generic[_T]):
476
478
  async with self._lock:
477
479
  self._initialization_failures += 1
478
480
  ret = error
479
- match sleep_if_failure:
481
+ match skip_sleep_if_failure:
480
482
  case True:
481
483
  _ = self._logger.warning(
482
- "%s: encountered %s whilst initializing; sleeping for %s...",
484
+ "%s: encountered %s whilst initializing",
483
485
  self,
484
486
  repr_error(error),
485
- self.backoff,
486
487
  )
487
- await sleep(self._backoff)
488
488
  case False:
489
489
  _ = self._logger.warning(
490
- "%s: encountered %s whilst initializing",
490
+ "%s: encountered %s whilst initializing; sleeping for %s...",
491
491
  self,
492
492
  repr_error(error),
493
+ self.backoff,
493
494
  )
495
+ await sleep(self._backoff)
494
496
  case _ as never:
495
497
  assert_never(never)
496
498
  else:
@@ -590,20 +592,22 @@ class Looper(Generic[_T]):
590
592
  case _ as never:
591
593
  assert_never(never)
592
594
 
593
- async def restart(self, *, sleep_if_failure: bool) -> None:
595
+ async def restart(self) -> None:
594
596
  """Restart the looper."""
595
597
  _ = self._debug and self._logger.debug("%s: restarting...", self)
596
598
  self._is_pending_restart.clear()
597
599
  async with self._lock:
598
600
  self._restart_attempts += 1
599
- tear_down = await self.tear_down(sleep_if_failure=False)
600
- initialization = await self.initialize(sleep_if_failure=False)
601
- match tear_down, initialization, sleep_if_failure:
602
- case None, None, bool():
603
- _ = self._debug and self._logger.debug("%s: finished restarting", self)
601
+ tear_down = await self.tear_down(skip_sleep_if_failure=True)
602
+ initialization = await self.initialize(skip_sleep_if_failure=True)
603
+ match tear_down, initialization:
604
+ case None, None:
605
+ _ = self._debug and self._logger.debug(
606
+ "%s: finished restarting; sleeping for %s...", self, self.backoff
607
+ )
604
608
  async with self._lock:
605
609
  self._restart_successes += 1
606
- case Exception(), None, True:
610
+ case Exception(), None:
607
611
  async with self._lock:
608
612
  self._restart_failures += 1
609
613
  _ = self._logger.warning(
@@ -612,16 +616,7 @@ class Looper(Generic[_T]):
612
616
  repr_error(tear_down),
613
617
  self.backoff,
614
618
  )
615
- await sleep(self._backoff)
616
- case Exception(), None, False:
617
- async with self._lock:
618
- self._restart_failures += 1
619
- _ = self._logger.warning(
620
- "%s: encountered %s whilst restarting (tear down)",
621
- self,
622
- repr_error(tear_down),
623
- )
624
- case None, Exception(), True:
619
+ case None, Exception():
625
620
  async with self._lock:
626
621
  self._restart_failures += 1
627
622
  _ = self._logger.warning(
@@ -630,16 +625,7 @@ class Looper(Generic[_T]):
630
625
  repr_error(initialization),
631
626
  self.backoff,
632
627
  )
633
- await sleep(self._backoff)
634
- case None, Exception(), False:
635
- async with self._lock:
636
- self._restart_failures += 1
637
- _ = self._logger.warning(
638
- "%s: encountered %s whilst restarting (initialize)",
639
- self,
640
- repr_error(initialization),
641
- )
642
- case Exception(), Exception(), True:
628
+ case Exception(), Exception():
643
629
  async with self._lock:
644
630
  self._restart_failures += 1
645
631
  _ = self._logger.warning(
@@ -649,18 +635,9 @@ class Looper(Generic[_T]):
649
635
  repr_error(initialization),
650
636
  self.backoff,
651
637
  )
652
- await sleep(self._backoff)
653
- case Exception(), Exception(), False:
654
- async with self._lock:
655
- self._restart_failures += 1
656
- _ = self._logger.warning(
657
- "%s: encountered %s (tear down) and then %s (initialization) whilst restarting",
658
- self,
659
- repr_error(tear_down),
660
- repr_error(initialization),
661
- )
662
638
  case _ as never:
663
639
  assert_never(never)
640
+ await sleep(self._backoff)
664
641
 
665
642
  async def run_looper(self) -> None:
666
643
  """Run the looper."""
@@ -675,9 +652,9 @@ class Looper(Generic[_T]):
675
652
  ):
676
653
  await self.stop()
677
654
  elif self._is_pending_restart.is_set():
678
- await self.restart(sleep_if_failure=True)
655
+ await self.restart()
679
656
  elif not self._is_initialized.is_set():
680
- _ = await self.initialize(sleep_if_failure=True)
657
+ _ = await self.initialize()
681
658
  else:
682
659
  _ = self._debug and self._logger.debug(
683
660
  "%s: running core...", self
@@ -695,7 +672,6 @@ class Looper(Generic[_T]):
695
672
  async with self._lock:
696
673
  self._core_failures += 1
697
674
  self.request_restart()
698
- await sleep(self._backoff)
699
675
  else:
700
676
  async with self._lock:
701
677
  self._core_successes += 1
@@ -749,7 +725,9 @@ class Looper(Generic[_T]):
749
725
  case _ as never:
750
726
  assert_never(never)
751
727
 
752
- async def tear_down(self, *, sleep_if_failure: bool) -> Exception | None:
728
+ async def tear_down(
729
+ self, *, skip_sleep_if_failure: bool = False
730
+ ) -> Exception | None:
753
731
  """Tear down the looper."""
754
732
  match self._is_tearing_down.is_set():
755
733
  case True:
@@ -766,21 +744,21 @@ class Looper(Generic[_T]):
766
744
  async with self._lock:
767
745
  self._tear_down_failures += 1
768
746
  ret = error
769
- match sleep_if_failure:
747
+ match skip_sleep_if_failure:
770
748
  case True:
771
749
  _ = self._logger.warning(
772
- "%s: encountered %s whilst tearing down; sleeping for %s...",
750
+ "%s: encountered %s whilst tearing down",
773
751
  self,
774
752
  repr_error(error),
775
- self.backoff,
776
753
  )
777
- await sleep(self._backoff)
778
754
  case False:
779
755
  _ = self._logger.warning(
780
- "%s: encountered %s whilst tearing down",
756
+ "%s: encountered %s whilst tearing down; sleeping for %s...",
781
757
  self,
782
758
  repr_error(error),
759
+ self.backoff,
783
760
  )
761
+ await sleep(self._backoff)
784
762
  case _ as never:
785
763
  assert_never(never)
786
764
  else: