Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
clearml committed Nov 24, 2024
1 parent 13ee873 commit de81b6c
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions clearml/backend_api/session/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def __init__(self, config_file=None, initialize_logging=False, *args, **kwargs):
"""

def init():
super(StrictSession, self).__init__(
initialize_logging=initialize_logging, *args, **kwargs
)
super(StrictSession, self).__init__(initialize_logging=initialize_logging, *args, **kwargs)

if not config_file:
init()
Expand Down Expand Up @@ -142,17 +140,17 @@ def __init__(self, result, dest=None):
self.response = None
self._result = result
response = getattr(result, "response", result)
if getattr(response, "_service") == "events" and \
getattr(response, "_action") in ("scalar_metrics_iter_histogram",
"multi_task_scalar_metrics_iter_histogram",
"vector_metrics_iter_histogram",
):
if getattr(response, "_service") == "events" and getattr(response, "_action") in (
"scalar_metrics_iter_histogram",
"multi_task_scalar_metrics_iter_histogram",
"vector_metrics_iter_histogram",
):
# put all the response data under metrics:
response.metrics = result.response_data
# noinspection PyProtectedMember
if 'metrics' not in response.__class__._get_data_props():
if "metrics" not in response.__class__._get_data_props():
# noinspection PyProtectedMember
response.__class__._data_props_list['metrics'] = 'metrics'
response.__class__._data_props_list["metrics"] = "metrics"
if dest:
response = getattr(response, dest)
self.response = response
Expand All @@ -170,11 +168,7 @@ def __repr__(self):
return repr(self.response)

def __dir__(self):
fields = [
name
for name in dir(self.response)
if isinstance(getattr(type(self.response), name, None), property)
]
fields = [name for name in dir(self.response) if isinstance(getattr(type(self.response), name, None), property)]
return list(set(chain(super(Response, self).__dir__(), fields)) - {"response"})


Expand Down Expand Up @@ -224,7 +218,7 @@ def getter(obj, attr):
return "" if result is None else result

fields = fields or self.fields
return '\n'.join(str(dict((attr, getter(item, attr)) for attr in fields)) for item in self)
return "\n".join(str(dict((attr, getter(item, attr)) for attr in fields)) for item in self)

def display(self, fields=None):
print(self._format_table(fields=fields))
Expand All @@ -251,10 +245,7 @@ def compare_enum(x, y):
item
for item in self
if (not predicate or predicate(item))
and all(
compare_enum(getattr(item, key), value)
for key, value in kwargs.items()
)
and all(compare_enum(getattr(item, key), value) for key, value in kwargs.items())
],
)

Expand Down Expand Up @@ -393,19 +384,15 @@ def new_func(self, *args, **kwargs):

@wrap
def get(self, *args, **kwargs):
return entity(
self, self.session.send(request_cls(*args, **kwargs)).response
)
return entity(self, self.session.send(request_cls(*args, **kwargs)).response)

elif action == "create":

@wrap
def get(self, *args, **kwargs):
return entity(
self,
Namespace(
id=self.session.send(request_cls(*args, **kwargs)).response.id
),
Namespace(id=self.session.send(request_cls(*args, **kwargs)).response.id),
)

elif action in ["get_all", "get_all_ex"]:
Expand Down Expand Up @@ -458,7 +445,8 @@ def get_requests(service):
return OrderedDict(
(key, value)
for key, value in sorted(
vars(service.__wrapped__ if hasattr(service, '__wrapped__') else service).items(), key=itemgetter(0))
vars(service.__wrapped__ if hasattr(service, "__wrapped__") else service).items(), key=itemgetter(0)
)
if isinstance(value, type) and issubclass(value, APIRequest) and value._action
)

Expand All @@ -476,10 +464,7 @@ def make_service_class(module):
]
)
properties.update(
(f.__name__, f)
for f in (
make_action(module, value) for key, value in get_requests(module).items()
)
(f.__name__, f) for f in (make_action(module, value) for key, value in get_requests(module).items())
)
# noinspection PyTypeChecker
return type(str(module_name(module)), (Service,), properties)
Expand All @@ -504,14 +489,12 @@ def fetch(self):
except AttributeError:
published = False

self.data = self._service.get_versions(
dataset=self.dataset, only_published=published, versions=[self.id]
)[0].data
self.data = self._service.get_versions(dataset=self.dataset, only_published=published, versions=[self.id])[
0
].data

def _get_default_kwargs(self):
return dict(
super(Version, self)._get_default_kwargs(), **{"dataset": self.data.dataset}
)
return dict(super(Version, self)._get_default_kwargs(), **{"dataset": self.data.dataset})


class APIClient(object):
Expand Down Expand Up @@ -549,18 +532,13 @@ def import_(*args, **kwargs):
if mod
)
else:
services = OrderedDict(
(name, getattr(_api_services, name)) for name in _api_services.__all__
)
services = OrderedDict((name, getattr(_api_services, name)) for name in _api_services.__all__)
self._update_services(services)

def _update_services(self, services):
# type: (Dict[str, types.ModuleType]) -> ()
self.__dict__.update(
dict(
{
name: make_service_class(module)(self.session)
for name, module in services.items()
},
{name: make_service_class(module)(self.session) for name, module in services.items()},
)
)

0 comments on commit de81b6c

Please sign in to comment.