Skip to content

Commit

Permalink
Incorporate PR feedback
Browse files Browse the repository at this point in the history
Incorporate feedback regarding the quality of the code (fix typos, remove comments/ unused packages, fix naming)
  • Loading branch information
maxhoerstr committed Aug 23, 2024
1 parent f180401 commit e6a9bca
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 28 deletions.
4 changes: 0 additions & 4 deletions pfdl_scheduler/petri_net/drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ def draw_clusters(clust, attr):
attr["style"] = DEFAULT_CLUSTER_STYLE


def draw_clusters(clust, attr):
attr["style"] = ""


def draw_petri_net(net, file_path, file_ending=".png"):
"""Calls the draw method form the Snakes module on the given PetriNet."""
with draw_lock:
Expand Down
10 changes: 4 additions & 6 deletions pfdl_scheduler/petri_net/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# standard libraries
import copy
from typing import Any, Callable, Dict, List, OrderedDict, Tuple
from typing import Any, Callable, Dict, List, OrderedDict
import uuid
import functools
import json
Expand Down Expand Up @@ -229,7 +229,6 @@ def generate_statements(
if multiple_statements:
if i < len(statements) - 1:
current_connection_uuid = create_transition("connection", "", self.net, node)
# node.cluster.add_child(Cluster(current_connection_uuid))
else:
current_connection_uuid = last_connection_uuid
else:
Expand All @@ -248,7 +247,7 @@ def generate_statements(
if isinstance(statement, Service):
connection_uuids = [self.generate_service(*args)]
elif isinstance(statement, TaskCall):
connection_uuids, new_task_context = self.generate_task_call(*args)
connection_uuids = self.generate_task_call(*args)
elif isinstance(statement, Parallel):
connection_uuids = [self.generate_parallel(*args)]
elif isinstance(statement, CountingLoop):
Expand Down Expand Up @@ -347,7 +346,7 @@ def generate_task_call(
for last_connection_uuid in last_connection_uuids:
self.add_callback(last_connection_uuid, self.callbacks.task_finished, new_task_context)

return last_connection_uuids, new_task_context
return last_connection_uuids

def generate_parallel(
self,
Expand Down Expand Up @@ -570,7 +569,7 @@ def generate_parallel_loop(
parallel_loop_node,
)
cluster = Cluster([parallel_loop_started])
# node.cluster.add_child(cluster)

parallel_loop_node.cluster = cluster
self.net.add_output(parallel_loop_started, first_transition_uuid, Value(1))
self.net.add_input(parallel_loop_started, second_transition_uuid, Value(1))
Expand Down Expand Up @@ -617,7 +616,6 @@ def remove_place_on_runtime(self, place_uuid: str) -> None:
place_uuid: The uuid as string of the task which should be removed from the net.
"""
if self.net.has_place(place_uuid):
# self.net.clusters._nodes.add(place_uuid)
self.net.remove_place(place_uuid)
if self.draw_net:
draw_petri_net(self.net, self.path_for_image)
Expand Down
2 changes: 1 addition & 1 deletion pfdl_scheduler/petri_net/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def draw_petri_net(self) -> None:
If the `draw_net` flag is set, this method will save the petri net in a "temp" folder
inside the root folder of the project. The petri net is saved as an image and as a dot
file to allow further processing. The dot file contains also the "call_tree" a tree
file to allow further processing. The dot file also contains the "call_tree", a tree
structure that describes the call hierarchy of PFDL tasks.
Args:
Expand Down
4 changes: 0 additions & 4 deletions pfdl_scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ def __init__(
file_name=self.scheduler_uuid,
)
self.setup_scheduling(draw_petri_net)

# enable logging
# self.attach(LogEntryObserver(self.scheduler_uuid))

if dashboard_host_address != "":
self.attach(
DashboardObserver(dashboard_host_address, self.scheduler_uuid, pfdl_string)
Expand Down
4 changes: 2 additions & 2 deletions pfdl_scheduler/utils/log_entry_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class LogEntryObserver(Observer):

def __init__(self, scheduler_uuid: str):
logging.basicConfig(
filename="temp/" + scheduler_uuid + ".log",
encoding="utf-8",
filename=LOG_FILE_LOCATION + scheduler_uuid + LOG_FILE_FORMAT,
encoding=LOG_FILE_ENCODING,
level=logging.DEBUG,
filemode=LOG_FILE_FILEMODE,
)
Expand Down
2 changes: 1 addition & 1 deletion pfdl_scheduler/utils/parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def write_tokens_to_file(token_stream: CommonTokenStream) -> None:
file.write(token_text + "\n")


def extract_content_and_file_path(program):
def extract_content_and_file_path(program: str) -> Tuple[str, str]:
"""Extracts the file path and loads the PFDL string for a given program.
Args:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_files/scheduling/task_synchronisation.pfdl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Struct CuttingResult
sheet_parts: SheetPart[]
End

Struct TransportOrderStep_Struct
Struct TransportOrderStep
location: string
End

Expand Down Expand Up @@ -50,13 +50,13 @@ Task cuttingTask
End

Task transport
Transport_Service
Transport
In
TransportOrderStep_Struct
TransportOrderStep
{
"location": "start"
}
TransportOrderStep_Struct
TransportOrderStep
{
"location": "goal"
}
Expand Down
7 changes: 1 addition & 6 deletions tests/unit_test/test_pfdl_tree_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

# standard libraries
import unittest
from unittest.mock import MagicMock, Mock
from unittest.mock import MagicMock
from unittest.mock import patch
from pfdl_scheduler.model.parallel import Parallel


# local sources
from pfdl_scheduler.validation.error_handler import ErrorHandler
from pfdl_scheduler.parser.PFDLParser import PFDLParser
from pfdl_scheduler.parser.PFDLParserVisitor import PFDLParserVisitor
from pfdl_scheduler.model.process import Process
from pfdl_scheduler.model.struct import Struct
from pfdl_scheduler.model.task import Task
Expand All @@ -36,10 +35,8 @@

from pfdl_scheduler.parser.pfdl_tree_visitor import (
PFDLTreeVisitor,
PRIMITIVE_DATATYPES,
IN_KEY,
OUT_KEY,
START_TASK,
)

from antlr4 import ParserRuleContext
Expand Down Expand Up @@ -719,8 +716,6 @@ def test_initializeArray(self):

# without length
with patch.object(self.visitor, "visitArray", return_value=-1):
array = Array("string")
array.length = 10
self.assertEqual(
self.visitor.initializeArray(array_context, variable_type), Array("string")
)
Expand Down

0 comments on commit e6a9bca

Please sign in to comment.