Fix python 2.7/3.5 support, PEP8 and redundant code

This commit is contained in:
allegroai
2020-11-25 11:05:40 +02:00
parent 313e99f156
commit 5d1c477e10
6 changed files with 27 additions and 30 deletions

View File

@@ -54,7 +54,7 @@ class HyperParams(object):
def edit_hyper_params(
self,
*iterables, # type: Union[Mapping[str, Union[str, dict, None]], Iterable[dict, tasks.ParamsItem]]
iterables, # type: Union[Mapping[str, Union[str, dict, None]], Iterable[dict, tasks.ParamsItem]]
replace=None, # type: Optional[str]
default_section=None, # type: Optional[str]
force_section=None # type: Optional[str]
@@ -89,8 +89,11 @@ class HyperParams(object):
item = value
elif isinstance(value, dict):
item = tasks.ParamsItem(**value)
elif isinstance(value, tuple):
item = tasks.ParamsItem(name=str(value[0]), value=str(value[1]))
else:
item = tasks.ParamsItem(value=str(value))
if name:
item.name = str(name)
if not item.name:
@@ -105,11 +108,15 @@ class HyperParams(object):
return item
props = {}
if isinstance(iterables, dict):
iterables = [iterables]
for i in iterables:
if isinstance(i, dict):
props.update({name: make_item(value, name) for name, value in i.items()})
else:
props.update({item.name: item for item in map(make_item, i)})
item = make_item(i)
props.update({item.name: item})
res = self.task.session.send(
tasks.EditHyperParamsRequest(
@@ -213,4 +220,4 @@ UNSAFE_NAMES_2_10 = {
"exact",
"iexact",
"match",
}
}

View File

@@ -21,8 +21,8 @@ def pip_freeze(combine_conda_with_pip=False):
# check if this is a pypi package, if it is, leave it outside
if not r.get('channel') or r.get('channel') == 'pypi':
name = (r['name'].replace('-', '_'), r['name'])
pip_req_line = [l for l in pip_lines
if l.split('==', 1)[0].strip() in name or l.split('@', 1)[0].strip() in name]
pip_req_line = [pip_l for pip_l in pip_lines
if pip_l.split('==', 1)[0].strip() in name or pip_l.split('@', 1)[0].strip() in name]
if pip_req_line and \
('@' not in pip_req_line[0] or
not pip_req_line[0].split('@', 1)[1].strip().startswith('file://')):

View File

@@ -1109,7 +1109,7 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
# type: (Optional[str], Optional[str]) -> ()
# if running remotely and we are the main task, skip setting ourselves.
if self._is_main_remote_task():
if self._is_remote_main_task():
return
if not project_id:
@@ -1202,7 +1202,7 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
self._edit(comment=comment)
def set_task_type(self, task_type):
# type: (Union[str, TaskTypes]) -> ()
# type: (Union[str, Task.TaskTypes]) -> ()
"""
Set the task_type for the Task.
@@ -1628,9 +1628,6 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
return None
return text_to_config_dict(config_text)
def _is_main_remote_task(self):
return running_remotely() and get_remote_task_id() == self.id
def get_offline_mode_folder(self):
# type: () -> (Optional[Path])
"""