mirror of
https://github.com/clearml/clearml
synced 2025-02-07 13:23:40 +00:00
Refactor APIClient
This commit is contained in:
parent
56db3c67e7
commit
a3e53a727f
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import abc
|
import abc
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
@ -520,9 +521,11 @@ class APIClient(object):
|
|||||||
models = None # type: Any
|
models = None # type: Any
|
||||||
projects = None # type: Any
|
projects = None # type: Any
|
||||||
|
|
||||||
def __init__(self, session=None, api_version=None):
|
def __init__(self, session=None, api_version=None, **kwargs):
|
||||||
self.session = session or StrictSession()
|
self.session = session or StrictSession()
|
||||||
|
|
||||||
|
_api_services = kwargs.pop("api_services", api_services)
|
||||||
|
|
||||||
def import_(*args, **kwargs):
|
def import_(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return import_module(*args, **kwargs)
|
return import_module(*args, **kwargs)
|
||||||
@ -536,16 +539,20 @@ class APIClient(object):
|
|||||||
for name, mod in (
|
for name, mod in (
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
import_(".".join((api_services.__name__, api_version, name))),
|
import_(".".join((_api_services.__name__, api_version, name))),
|
||||||
)
|
)
|
||||||
for name in api_services.__all__
|
for name in _api_services.__all__
|
||||||
)
|
)
|
||||||
if mod
|
if mod
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
services = OrderedDict(
|
services = OrderedDict(
|
||||||
(name, getattr(api_services, name)) for name in api_services.__all__
|
(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(
|
self.__dict__.update(
|
||||||
dict(
|
dict(
|
||||||
{
|
{
|
||||||
@ -553,4 +560,4 @@ class APIClient(object):
|
|||||||
for name, module in services.items()
|
for name, module in services.items()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
Loading…
Reference in New Issue
Block a user