4
4
5
5
import logging
6
6
import os
7
+ from typing import Any , Callable , Set
7
8
8
9
from sky .adaptors import common
9
10
from sky .sky_logging import set_logging_level
30
31
API_TIMEOUT = 5
31
32
32
33
33
- def _decorate_methods (obj , decorator ):
34
+ def _decorate_methods (obj : Any , decorator : Callable , decoration_type : str ):
34
35
for attr_name in dir (obj ):
35
36
attr = getattr (obj , attr_name )
37
+ # Skip methods starting with '__' since they are invoked through one
38
+ # of the main methods, which are already decorated.
36
39
if callable (attr ) and not attr_name .startswith ('__' ):
37
- setattr (obj , attr_name , decorator (attr ))
40
+ decorated_types : Set [str ] = getattr (attr , '_sky_decorator_types' ,
41
+ set ())
42
+ if decoration_type not in decorated_types :
43
+ decorated_attr = decorator (attr )
44
+ decorated_attr ._sky_decorator_types = ( # pylint: disable=protected-access
45
+ decorated_types | {decoration_type })
46
+ setattr (obj , attr_name , decorated_attr )
38
47
return obj
39
48
40
49
@@ -49,7 +58,7 @@ def decorated_api(api):
49
58
50
59
def wrapped (* args , ** kwargs ):
51
60
obj = api (* args , ** kwargs )
52
- _decorate_methods (obj , set_logging_level (logger , level ))
61
+ _decorate_methods (obj , set_logging_level (logger , level ), 'api_log' )
53
62
return obj
54
63
55
64
return wrapped
0 commit comments