pyglove 0.4.5.dev202504260808__py3-none-any.whl → 0.4.5.dev202504270808__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.
pyglove/core/logging.py CHANGED
@@ -17,17 +17,47 @@ This module allows PyGlove to use external created logger for logging PyGlove
17
17
  events without introducing library dependencies in PyGlove.
18
18
  """
19
19
 
20
+ import inspect
20
21
  import logging
22
+ from typing import Any, Callable, List, Union
21
23
 
22
24
 
23
25
  _DEFAULT_LOGGER = logging.getLogger()
24
26
 
25
27
 
28
+ def register_frame_to_skip(
29
+ method: Union[Callable[..., Any], List[Callable[..., Any]]]
30
+ ) -> bool:
31
+ """Skips the source of the given method when logging.
32
+
33
+ Args:
34
+ method: The method to skip. Can be a single method or a list of methods.
35
+
36
+ Returns:
37
+ True if the method is registered to skip.
38
+
39
+ Raises:
40
+ TypeError: The source file of the method cannot be inspected.
41
+ """
42
+ register_fn = getattr(
43
+ _DEFAULT_LOGGER.__class__, 'register_frame_to_skip', None
44
+ )
45
+ if register_fn is None:
46
+ return False
47
+ methods = [method] if not isinstance(method, list) else method
48
+ for m in methods:
49
+ register_fn(inspect.getsourcefile(m), m.__name__)
50
+ return True
51
+
52
+
26
53
  def set_logger(logger: logging.Logger) -> None:
27
54
  """Sets current logger."""
28
55
  global _DEFAULT_LOGGER
29
56
  _DEFAULT_LOGGER = logger
30
57
 
58
+ # Skip logging frames in pyglove.logging.
59
+ register_frame_to_skip([debug, info, warning, error, critical])
60
+
31
61
 
32
62
  def get_logger() -> logging.Logger:
33
63
  """Gets the current logger."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyglove
3
- Version: 0.4.5.dev202504260808
3
+ Version: 0.4.5.dev202504270808
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -1,6 +1,6 @@
1
1
  pyglove/__init__.py,sha256=YPUWALRDu4QuI7N3TUmVaVr513hUt0qXrjY582I1q5c,1352
2
2
  pyglove/core/__init__.py,sha256=BF-8v1D5lTBAo4vlpDt0qyOG9NQ71oh_UfthBVrPaN4,9614
3
- pyglove/core/logging.py,sha256=Sr5nLyUQmc4CAEYAq8qbP3ghpjmpz2sOuhq2A0tgQ6I,2456
3
+ pyglove/core/logging.py,sha256=pD5A6K8TOWoQdYZ1IgGHHd_vIcqtcWQ51Eep5Hswfwc,3305
4
4
  pyglove/core/logging_test.py,sha256=3z_c6wnxbqDbwUmSOAZzeDPXvzoweYL5QHUQVMJ5Xgo,1917
5
5
  pyglove/core/coding/__init__.py,sha256=tuHIg19ZchtkOQbdFVTVLkUpBa5f1eo66XtnKw3lcIU,1645
6
6
  pyglove/core/coding/errors.py,sha256=aP3Y4amBzOKdlb5JnESJ3kdoijQXbiBiPDMeA88LNrk,3310
@@ -212,8 +212,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
212
212
  pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
213
213
  pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
214
214
  pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
215
- pyglove-0.4.5.dev202504260808.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
216
- pyglove-0.4.5.dev202504260808.dist-info/METADATA,sha256=cO3gt2hth4HqVh7ao1AzuahePKJK_UbC1tIf60FtE_k,7089
217
- pyglove-0.4.5.dev202504260808.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
218
- pyglove-0.4.5.dev202504260808.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
219
- pyglove-0.4.5.dev202504260808.dist-info/RECORD,,
215
+ pyglove-0.4.5.dev202504270808.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
216
+ pyglove-0.4.5.dev202504270808.dist-info/METADATA,sha256=uUnAmPm01eYJ9lrXzgb0ctaoqxr3UWbTCFKhgdi-oJU,7089
217
+ pyglove-0.4.5.dev202504270808.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
218
+ pyglove-0.4.5.dev202504270808.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
219
+ pyglove-0.4.5.dev202504270808.dist-info/RECORD,,