Skip to content

Commit

Permalink
some trivial cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-st-john committed May 22, 2024
1 parent 38909f0 commit 80820d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
28 changes: 10 additions & 18 deletions src/yedextended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def checkValue(


class File:
"""Object to check and act on yEd files / filepaths."""
"""Object to check and act on yEd files / filepaths (or the excel files during bulk data management)."""

def __init__(self, file_name_or_path=None):
self.DEFAULT_FILE_NAME = "temp"
Expand Down Expand Up @@ -118,13 +118,13 @@ def base_name_validate(self, temp_name_or_path=None):
if temp_name_or_path:
temp_name = os.path.basename(temp_name_or_path)
temp_name = temp_name or f"{self.DEFAULT_FILE_NAME}"
if not temp_name.endswith(self.EXTENSION) and not temp_name.endswith(".xlsx"): # FIXME:
if not temp_name.endswith(self.EXTENSION) and not temp_name.endswith(".xlsx"):
temp_name += self.EXTENSION
return temp_name

def open_with_yed(self, force=False):
"""Method to open GraphML file directly with yEd application (must be installed and on path)."""
print("opening...")
print("opening file with yed...")
open_yed_file(self, force)
return get_yed_pid()

Expand Down Expand Up @@ -493,7 +493,6 @@ def add_group(self, group_id, **kwargs):

def add_edge(self, node1_id, node2_id, **kwargs):
"""Adds edge - input: node names, not actual node objects"""
# TODO: DO EDGES NEED A PARENT FOR EASE OF OPERATIONS

node1 = self.parent_graph.existing_entities.get(node1_id) or self.add_node(node1_id)

Expand Down Expand Up @@ -1353,7 +1352,7 @@ def excel_to_graph_conversion(self, type=None, excel_data=None):
elif isinstance(obj, Node): # node
parent.remove_node(obj_id)

elif self.type == "relations": # TODO: Implement this
elif self.type == "relations":
# Columns
# node1name
# node2name
Expand Down Expand Up @@ -1451,8 +1450,7 @@ def excel_to_graph_conversion(self, type=None, excel_data=None):
self.graph.run_graph_rules()

def give_user_chance_to_modify(self):
# FIXME: make sure not open

"""Open Excel for user to modify data."""
# kill excel process
self.kill_excel()

Expand Down Expand Up @@ -1492,7 +1490,7 @@ def __init__(self, directed="directed", graph_id="G"):

self.custom_properties = []

self.graphml: ET.Element # FIXME:
self.graphml: ET.Element

# Addition of items ============================
def add_node(self, node_name, **kwargs):
Expand Down Expand Up @@ -1581,7 +1579,7 @@ def remove_edge(self, edge_id):
del self.edges[edge_id]
self.num_edges -= 1

# TODO: REMOVE / MODIFY CUSTOM PROPERTIES FUNCTIONALITY
# TODO: ADD FUNCTIONALITY TO REMOVE / MODIFY CUSTOM PROPERTIES

# Graph functionalities ===========================
def construct_graphml(self):
Expand Down Expand Up @@ -1786,7 +1784,6 @@ def process_node(parent, input_node):
if info is not None:
info = re.sub(r"<!\[CDATA\[", "", info) # unneeded schema
info = re.sub(r"\]\]>", "", info) # unneeded schema
print("info:", info)

the_key = data_node.attrib.get("key")

Expand All @@ -1813,7 +1810,7 @@ def process_node(parent, input_node):
if proxy is not None:
realizer = proxy.find("Realizers")

group_nodes = realizer.findall("GroupNode") # TODO: When are there multiple?
group_nodes = realizer.findall("GroupNode")

for group_node in group_nodes:
geom_node = group_node.find("Geometry")
Expand Down Expand Up @@ -1856,16 +1853,13 @@ def process_node(parent, input_node):
# group_init_dict["aaaa"] = group_state_node.attrib.get("closedWidth",None)
# group_init_dict["aaaa"] = group_state_node.attrib.get("innerGraphDisplayEnabled",None)

# TODO: GATHER THE MULTIPLE GROUP NODES

break

else:
info = data_node.text
if info is not None:
info = re.sub(r"<!\[CDATA\[", "", info) # unneeded schema
info = re.sub(r"\]\]>", "", info) # unneeded schema
print("info:", info)

the_key = data_node.attrib.get("key")

Expand Down Expand Up @@ -1935,7 +1929,6 @@ def process_node(parent, input_node):
if info is not None:
info = re.sub(r"<!\[CDATA\[", "", info) # unneeded schema
info = re.sub(r"\]\]>", "", info) # unneeded schema
print("info:", info)

the_key = data_node.attrib.get("key")

Expand All @@ -1944,7 +1937,7 @@ def process_node(parent, input_node):
edge_init_dict[info_type] = info

# bendstyle_node = polylineedge.find("BendStyle")
# edge_init_dict["smoothed"] = linestyle_node.attrib.get("smoothed") # FIXME
# edge_init_dict["smoothed"] = linestyle_node.attrib.get("smoothed") # TODO: ADD THIS

# TODO:
# CUSTOM PROPERTIES
Expand Down Expand Up @@ -2039,7 +2032,7 @@ def start_subprocess(command):
# Start the subprocess
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pid = process.pid
print(f"Started process with PID: {pid}")
# print(f"Started process with PID: {pid}")
return process
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
Expand Down Expand Up @@ -2119,6 +2112,5 @@ def xml_to_simple_string(file_path) -> str:
graph_str = graph_str.replace("xml:", "") # unneeded namespace prefix
graph_str = graph_str.replace("yfiles.", "") # unneeded namespace prefix
graph_str = re.sub(" {1,}", " ", graph_str) # reducing redundant spaces
# print(graph_str) # debug

return graph_str
15 changes: 5 additions & 10 deletions tests/test_yedextended.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,11 @@ def test_round_trip():
os.remove(FILE)

graph = yed.Graph()
print(graph.stringify_graph())
print(graph.custom_properties)

graph.add_node("a")
graph.add_node("b")
graph.add_edge("a", "b") # .add_label("a_b") #TODO: NEEDS LABEL TESTING

# print(graph.stringify_graph())

graph_file = graph.persist_graph(FILE)
graph_after = yed.Graph().from_existing_graph(graph_file)
assert graph.stringify_graph() == graph_after.stringify_graph()
Expand Down Expand Up @@ -464,13 +461,12 @@ def test_from_existing_graph():
with pytest.raises(FileNotFoundError):
yed.Graph().from_existing_graph("not_existing_file")

test_graph = yed.Graph().from_existing_graph("examples\\yed_created_edges.graphml") # TODO:
test_graph = yed.Graph().from_existing_graph("examples\\yed_created_edges.graphml")
test_graph_stats = test_graph.gather_graph_stats()
assert test_graph_stats.all_nodes["n0"].url is not None


def test_create_graph_with_url_description():
# FIXME:
FILE1 = "test.graphml"

graph1 = yed.Graph()
Expand Down Expand Up @@ -508,12 +504,11 @@ def test_create_graph_with_url_description():
def test_create_edge_w_o_nodes():
graph1 = yed.Graph()
graph1.add_edge("a", "b")
# FIXME:
assert graph1.nodes["a"] is not None
assert graph1.nodes["b"] is not None


def test_removes():
# FIXME:

graph1 = yed.Graph()

# first level nodes
Expand Down Expand Up @@ -704,7 +699,7 @@ def get_filtered_sheet_values(sheet):
os.remove(excel1.TEMP_EXCEL_SHEET)


def test_bulk_data_management(): # FIXME:
def test_bulk_data_management():
graph1 = yed.Graph()

# first level nodes
Expand Down

0 comments on commit 80820d8

Please sign in to comment.