Skip to content

Commit

Permalink
Format code with autopep8, isort and black
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 01f7e32 according to the output
from autopep8, isort and black.

Details: https://deepsource.io/gh/robinthibaut/pysgems/transform/dc8e86bc-8776-43c7-9aef-22e723b28497/
  • Loading branch information
deepsource-autofix[bot] authored Feb 28, 2021
1 parent 01f7e32 commit 73040b0
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 288 deletions.
13 changes: 3 additions & 10 deletions pysgems/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
__name__ = 'pysgems'
__author__ = 'Robin Thibaut'
__name__ = "pysgems"
__author__ = "Robin Thibaut"

from . import algo
from . import base
from . import dis
from . import examples
from . import io
from . import plot
from . import sgems
from . import utils
from . import algo, base, dis, examples, io, plot, sgems, utils
1 change: 0 additions & 1 deletion pysgems/algo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Copyright (c) 2020. Robin Thibaut, Ghent University

152 changes: 89 additions & 63 deletions pysgems/algo/sgalgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@


class XML(Package):
def __init__(self,
project,
algo_dir=None):
def __init__(self, project, algo_dir=None):

Package.__init__(self, project)

Expand All @@ -22,13 +20,14 @@ def __init__(self,
self.res_dir = self.parent.res_dir
self.algo_dir = algo_dir
if self.algo_dir is None:
self.algo_dir = jp(self.cwd, 'algorithms')
self.algo_dir = jp(self.cwd, "algorithms")

self.op_file = jp(self.algo_dir, f'{uuid.uuid4().hex}.xml') # Temporary saves a modified XML
# Temporary saves a modified XML
self.op_file = jp(self.algo_dir, f"{uuid.uuid4().hex}.xml")
self.tree = None
self.root = None

setattr(self.parent, 'algo', self)
setattr(self.parent, "algo", self)

def xml_reader(self, algo_name):
"""
Expand All @@ -40,23 +39,25 @@ def xml_reader(self, algo_name):
except FileNotFoundError:
pass

self.tree = ET.parse(jp(self.algo_dir, '{}.xml'.format(algo_name)))
self.tree = ET.parse(jp(self.algo_dir, "{}.xml".format(algo_name)))
self.root = self.tree.getroot()

name = self.root.find('algorithm').attrib['name'] # Algorithm name
name = self.root.find("algorithm").attrib["name"] # Algorithm name

# By default, replace the grid name by 'computation_grid', and the name by the algorithm name.
replace = [['Grid_Name', {'value': 'computation_grid', 'region': ''}],
['Property_Name', {'value': name}]]
replace = [
["Grid_Name", {"value": "computation_grid", "region": ""}],
["Property_Name", {"value": name}],
]

for r in replace:
try:
self.xml_update(path=r[0], new_attribute_dict=r[1])
except AttributeError:
pass

setattr(self.parent.algo, 'tree', self.tree)
setattr(self.parent.algo, 'root', self.root)
setattr(self.parent.algo, "tree", self.tree)
setattr(self.parent.algo, "root", self.root)

def show_tree(self):
"""
Expand All @@ -72,19 +73,17 @@ def show_tree(self):
elems = list(element)
for e in elems:
c_list.append(e.tag)
print('//'.join(c_list))
print("//".join(c_list))
print(e.attrib)
element = list(e)
if len(element) == 0:
c_list.pop(-1)
except TypeError:
print('No loaded XML file')
print("No loaded XML file")

def xml_update(self, path,
attribute_name=None,
value=None,
new_attribute_dict=None,
show=1):
def xml_update(
self, path, attribute_name=None, value=None, new_attribute_dict=None, show=1
):
"""
Given a path in the algorithm XML file, changes the corresponding attribute to the new attribute
:param path: object path
Expand All @@ -95,14 +94,14 @@ def xml_update(self, path,
"""

if new_attribute_dict is not None:
if (auto_update is True) and ('property' in new_attribute_dict):
if (auto_update is True) and ("property" in new_attribute_dict):
# If one property point set needs to be used
pp = new_attribute_dict['property'] # Name property
pp = new_attribute_dict["property"] # Name property
if pp in self.parent.point_set.columns:
if 'grid' in new_attribute_dict: # ensure default grid name
new_attribute_dict['grid'] = '{}_grid'.format(pp)
if 'value' in new_attribute_dict: # ensure default grid name
new_attribute_dict['value'] = '{}_grid'.format(pp)
if "grid" in new_attribute_dict: # ensure default grid name
new_attribute_dict["grid"] = "{}_grid".format(pp)
if "value" in new_attribute_dict: # ensure default grid name
new_attribute_dict["value"] = "{}_grid".format(pp)
self.root.find(path).attrib = new_attribute_dict
self.tree.write(self.op_file)

Expand All @@ -111,12 +110,12 @@ def xml_update(self, path,
self.tree.write(self.op_file)

if show:
print('Updated')
print("Updated")
print(self.root.find(path).tag)
print(self.root.find(path).attrib)

setattr(self.parent.algo, 'tree', self.tree)
setattr(self.parent.algo, 'root', self.root)
setattr(self.parent.algo, "tree", self.tree)
setattr(self.parent.algo, "root", self.root)

def auto_fill(self):
"""
Expand All @@ -138,41 +137,63 @@ def auto_fill(self):
trk = list(element.attrib.keys())

for i in range(len(trv)):
if (trv[i] in self.parent.point_set.columns) \
and ('Variable' or 'Hard_Data' in element.tag):
if (trv[i] in self.parent.point_set.columns) and (
"Variable" or "Hard_Data" in element.tag
):
if trv[i] not in self.parent.object_file_names:
self.parent.object_file_names.append(trv[i])
try:
if trk[i - 1] == 'grid': # ensure default grid name
if trk[i - 1] == "grid": # ensure default grid name
print(element.attrib)
element.attrib['grid'] = '{}_grid'.format(trv[i])
self.xml_update('//'.join(c_list), 'grid', '{}_grid'.format(trv[i]))
print('>>>')
element.attrib["grid"] = "{}_grid".format(trv[i])
self.xml_update(
"//".join(c_list),
"grid",
"{}_grid".format(trv[i]),
)
print(">>>")
print(element.attrib)
if trk[i - 1] == 'value' and trk[i] == 'property': # ensure default grid name
# ensure default grid name
if trk[i - 1] == "value" and trk[i] == "property":
print(element.attrib)
element.attrib['value'] = '{}_grid'.format(trv[i])
self.xml_update('//'.join(c_list), 'value', '{}_grid'.format(trv[i]))
print('>>>')
element.attrib["value"] = "{}_grid".format(trv[i])
self.xml_update(
"//".join(c_list),
"value",
"{}_grid".format(trv[i]),
)
print(">>>")
print(element.attrib)
except IndexError:
pass
try:
if 'Grid' in elist[-2].tag:
if "Grid" in elist[-2].tag:
tp = list(elist[-2].attrib.keys())
if 'grid' in tp:
print('//'.join(c_list[:-2]))
if "grid" in tp:
print("//".join(c_list[:-2]))
print(elist[-2].attrib)
elist[-2].attrib['grid'] = '{}_grid'.format(trv[i])
self.xml_update(elist[-2].tag, 'grid', '{}_grid'.format(trv[i]))
print('>>>')
elist[-2].attrib["grid"] = "{}_grid".format(
trv[i]
)
self.xml_update(
elist[-2].tag,
"grid",
"{}_grid".format(trv[i]),
)
print(">>>")
print(elist[-2].attrib)
if 'value' in tp:
print('//'.join(c_list[:-2]))
if "value" in tp:
print("//".join(c_list[:-2]))
print(elist[-2].attrib)
elist[-2].attrib['value'] = '{}_grid'.format(trv[i])
self.xml_update(elist[-2].tag, 'value', '{}_grid'.format(trv[i]))
print('>>>')
elist[-2].attrib["value"] = "{}_grid".format(
trv[i]
)
self.xml_update(
elist[-2].tag,
"value",
"{}_grid".format(trv[i]),
)
print(">>>")
print(elist[-2].attrib)
except IndexError:
pass
Expand All @@ -189,26 +210,31 @@ def auto_fill(self):
if trv[i] in self.parent.point_set.columns:
if trv[i] not in self.parent.object_file_names:
self.parent.object_file_names.append(trv[i])
if trk[i] == 'grid': # ensure default grid name
print('//'.join(c_list))
if trk[i] == "grid": # ensure default grid name
print("//".join(c_list))
print(e.attrib)
e.attrib['grid'] = '{}_grid'.format(trv[i])
self.xml_update('//'.join(c_list), 'grid', '{}_grid'.format(trv[i]))
print('>>>')
e.attrib["grid"] = "{}_grid".format(trv[i])
self.xml_update(
"//".join(c_list),
"grid",
"{}_grid".format(trv[i]),
)
print(">>>")
print(e.attrib)
if trk[i] == 'value': # ensure default grid name
print('//'.join(c_list))
if trk[i] == "value": # ensure default grid name
print("//".join(c_list))
print(e.attrib)
e.attrib['value'] = '{}_grid'.format(trv[i])
self.xml_update('//'.join(c_list), 'value', '{}_grid'.format(trv[i]))
print('>>>')
e.attrib["value"] = "{}_grid".format(trv[i])
self.xml_update(
"//".join(c_list),
"value",
"{}_grid".format(trv[i]),
)
print(">>>")
print(e.attrib)

element = list(e)
if len(element) == 0:
c_list.pop(-1)
except TypeError:
print('No loaded XML file')



print("No loaded XML file")
1 change: 0 additions & 1 deletion pysgems/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Copyright (c) 2020. Robin Thibaut, Ghent University

8 changes: 4 additions & 4 deletions pysgems/base/packbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class PackageInterface(object):
@abc.abstractmethod
def parent(self):
raise NotImplementedError(
'must define get_model_dim_arrays in child '
'class to use this base class')
"must define get_model_dim_arrays in child " "class to use this base class"
)

@parent.setter
@abc.abstractmethod
def parent(self, name):
raise NotImplementedError(
'must define get_model_dim_arrays in child '
'class to use this base class')
"must define get_model_dim_arrays in child " "class to use this base class"
)


class Package(PackageInterface):
Expand Down
1 change: 0 additions & 1 deletion pysgems/dis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# Copyright (c) 2020. Robin Thibaut, Ghent University

Loading

0 comments on commit 73040b0

Please sign in to comment.