Skip to content

Commit

Permalink
Converts formatted strings to f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pritchardn committed May 25, 2022
1 parent 14931a9 commit 9d53642
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 59 deletions.
50 changes: 19 additions & 31 deletions daliuge-common/dlg/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def stop(self):
self._POST("/stop")

def cancelSession(self, sessionId):
self._POST("/sessions/%s/cancel" % quote(sessionId))
self._POST(f"/sessions/{quote(sessionId)}/cancel")

def create_session(self, sessionId):
"""
Expand All @@ -67,7 +67,7 @@ def deploy_session(self, sessionId, completed_uids=[]):
content = None
if completed_uids:
content = {"completed": ",".join(completed_uids)}
self._post_form("/sessions/%s/deploy" % (quote(sessionId),), content)
self._post_form(f"/sessions/{quote(sessionId)}/deploy", content)
logger.debug(
"Successfully deployed session %s on %s:%s", sessionId, self.host, self.port
)
Expand All @@ -78,7 +78,7 @@ def append_graph(self, sessionId, graphSpec):
but checking that the graph looks correct
"""
self._post_json(
"/sessions/%s/graph/append" % (quote(sessionId),),
f"/sessions/{quote(sessionId)}/graph/append",
graphSpec,
compress=compress,
)
Expand All @@ -93,7 +93,7 @@ def destroy_session(self, sessionId):
"""
Destroys session `sessionId`
"""
self._DELETE("/sessions/%s" % (quote(sessionId),))
self._DELETE(f"/sessions/{quote(sessionId)}")
logger.debug(
"Successfully deleted session %s on %s:%s", sessionId, self.host, self.port
)
Expand All @@ -103,7 +103,7 @@ def graph_status(self, sessionId):
Returns a dictionary where the keys are DROP UIDs and the values are
their corresponding status.
"""
ret = self._get_json("/sessions/%s/graph/status" % (quote(sessionId),))
ret = self._get_json(f"/sessions/{quote(sessionId)}/graph/status")
logger.debug(
"Successfully read graph status from session %s on %s:%s",
sessionId,
Expand All @@ -117,7 +117,7 @@ def graph(self, sessionId):
Returns a dictionary where the key are the DROP UIDs, and the values are
the DROP specifications.
"""
graph = self._get_json("/sessions/%s/graph" % (quote(sessionId),))
graph = self._get_json(f"/sessions/{quote(sessionId)}/graph")
logger.debug(
"Successfully read graph (%d nodes) from session %s on %s:%s",
len(graph),
Expand All @@ -144,7 +144,7 @@ def session(self, sessionId):
"""
Returns the details of sessions `sessionId`
"""
session = self._get_json("/sessions/%s" % (quote(sessionId),))
session = self._get_json(f"/sessions/{quote(sessionId)}")
logger.debug(
"Successfully read session %s from %s:%s", sessionId, self.host, self.port
)
Expand All @@ -154,7 +154,7 @@ def session_status(self, sessionId):
"""
Returns the status of session `sessionId`
"""
status = self._get_json("/sessions/%s/status" % (quote(sessionId),))
status = self._get_json(f"/sessions/{quote(sessionId)}/status")
logger.debug(
"Successfully read session %s status (%s) from %s:%s",
sessionId,
Expand All @@ -168,7 +168,7 @@ def session_repro_status(self, sessionId):
"""
Returns the reproducibility status of session `sessionId`.
"""
status = self._get_json("/sessions/%s/repro/status" % (quote(sessionId),))
status = self._get_json(f"/sessions/{quote(sessionId)}/repro/status")
logger.debug(
"Successfully read session %s reproducibility status (%s) from %s:%s",
sessionId,
Expand All @@ -182,7 +182,7 @@ def session_repro_data(self, sessionId):
"""
Returns the graph-wide reproducibility information of session `sessionId`.
"""
data = self._get_json("/sessions/%s/repro/data" % (quote(sessionId),))
data = self._get_json(f"/sessions/{quote(sessionId)}/repro/data")
logger.debug(
"Successfully read session %s reproducibility data from %s:%s",
sessionId,
Expand All @@ -195,7 +195,7 @@ def graph_size(self, sessionId):
"""
Returns the size of the graph of session `sessionId`
"""
count = self._get_json("/sessions/%s/graph/size" % (quote(sessionId)))
count = self._get_json(f"/sessions/{quote(sessionId)}/graph/size")
logger.debug(
"Successfully read session %s graph size (%d) from %s:%s",
sessionId,
Expand Down Expand Up @@ -228,11 +228,11 @@ def __init__(

def add_node_subscriptions(self, sessionId, node_subscriptions):
self._post_json(
"/sessions/%s/subscriptions" % (quote(sessionId),), node_subscriptions
f"/sessions/{quote(sessionId)}/subscriptions", node_subscriptions
)

def trigger_drops(self, sessionId, drop_uids):
self._post_json("/sessions/%s/trigger" % (quote(sessionId),), drop_uids)
self._post_json(f"/sessions/{quote(sessionId)}/trigger", drop_uids)

def shutdown_node_manager(self):
self._GET("/shutdown")
Expand All @@ -246,10 +246,10 @@ def nodes(self):
return self._get_json("/nodes")

def add_node(self, node):
self._POST("/nodes/%s" % (node,), content=None)
self._POST(f"/nodes/{node}", content=None)

def remove_node(self, node):
self._DELETE("/nodes/%s" % (node,))
self._DELETE(f"/nodes/{node}")


class DataIslandManagerClient(CompositeManagerClient):
Expand Down Expand Up @@ -277,7 +277,7 @@ def __init__(

def create_island(self, island_host, nodes):
self._post_json(
"/managers/%s/dataisland" % (quote(island_host)), {"nodes": nodes}
f"/managers/{quote(island_host)}/dataisland", {"nodes": nodes}
)

def dims(self):
Expand All @@ -287,29 +287,17 @@ def add_dim(self, dim):
self._POST(f"/islands/{dim}", content=None)

def remove_dim(self, dim):
self._DELETE("/islands/%s" % (dim,))
self._DELETE(f"/islands/{dim}")

def add_node_to_dim(self, dim, nm):
"""
Adds a nm to a dim
"""
self._POST(
"managers/%s/nodes/%s"
% (
dim,
nm,
),
content=None,
)
f"managers/{dim}/nodes/{nm}", content=None, )

def remove_node_from_dim(self, dim, nm):
"""
Removes a nm from a dim
"""
self._DELETE(
"managers/%s/nodes/%s"
% (
dim,
nm,
)
)
self._DELETE(f"managers/{dim}/nodes/{nm}")
34 changes: 13 additions & 21 deletions daliuge-engine/dlg/manager/composite_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ class allows for multiple levels of hierarchy seamlessly.
__metaclass__ = abc.ABCMeta

def __init__(
self,
dmPort,
partitionAttr,
subDmId,
dmHosts=[],
pkeyPath=None,
dmCheckTimeout=10,
self,
dmPort,
partitionAttr,
subDmId,
dmHosts=[],
pkeyPath=None,
dmCheckTimeout=10,
):
"""
Creates a new CompositeManager. The sub-DMs it manages are to be located
Expand Down Expand Up @@ -239,7 +239,7 @@ def dmAt(self, host, port=None):

if not self.check_dm(host, port):
raise SubManagerException(
"Manager expected but not running in %s:%d" % (host, port)
f"Manager expected but not running in {host}:{port}"
)

port = port or self._dmPort
Expand Down Expand Up @@ -288,10 +288,7 @@ def replicate(self, sessionId, f, action, collect=None, iterable=None, port=None
iterable,
)
if thrExs:
msg = "More than one error occurred while %s on session %s" % (
action,
sessionId,
)
msg = f"More than one error occurred while {action} on session {sessionId}"
raise SubManagerException(msg, thrExs)

#
Expand Down Expand Up @@ -364,19 +361,14 @@ def addGraphSpec(self, sessionId, graphSpec):
graphSpec.pop()
for dropSpec in graphSpec:
if self._partitionAttr not in dropSpec:
msg = "Drop %s doesn't specify a %s attribute" % (
dropSpec["oid"],
self._partitionAttr,
)
msg = f"Drop {dropSpec.get('oid', None)} doesn't specify a {self._partitionAttr} " \
f"attribute"
raise InvalidGraphException(msg)

partition = dropSpec[self._partitionAttr]
if partition not in self._dmHosts:
msg = "Drop %s's %s %s does not belong to this DM" % (
dropSpec["oid"],
self._partitionAttr,
partition,
)
msg = f"Drop {dropSpec.get('oid', None)}'s {self._partitionAttr} {partition} " \
f"does not belong to this DM"
raise InvalidGraphException(msg)

perPartition[partition].append(dropSpec)
Expand Down
14 changes: 7 additions & 7 deletions daliuge-engine/dlg/manager/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def removeCMNode(self, node):
@daliuge_aware
def getNodeSessions(self, node):
if node not in self.dm.nodes:
raise Exception("%s not in current list of nodes" % (node,))
raise Exception(f"{node} not in current list of nodes")
with NodeManagerClient(host=node) as dm:
return dm.sessions()

Expand Down Expand Up @@ -527,28 +527,28 @@ def getLogFile(self, sessionId):
@daliuge_aware
def getNodeSessionInformation(self, node, sessionId):
if node not in self.dm.nodes:
raise Exception("%s not in current list of nodes" % (node,))
raise Exception(f"{node} not in current list of nodes")
with NodeManagerClient(host=node) as dm:
return dm.session(sessionId)

@daliuge_aware
def getNodeSessionStatus(self, node, sessionId):
if node not in self.dm.nodes:
raise Exception("%s not in current list of nodes" % (node,))
raise Exception(f"{node} not in current list of nodes")
with NodeManagerClient(host=node) as dm:
return dm.session_status(sessionId)

@daliuge_aware
def getNodeGraph(self, node, sessionId):
if node not in self.dm.nodes:
raise Exception("%s not in current list of nodes" % (node,))
raise Exception(f"{node} not in current list of nodes")
with NodeManagerClient(host=node) as dm:
return dm.graph(sessionId)

@daliuge_aware
def getNodeGraphStatus(self, node, sessionId):
if node not in self.dm.nodes:
raise Exception("%s not in current list of nodes" % (node,))
raise Exception(f"{node} not in current list of nodes")
with NodeManagerClient(host=node) as dm:
return dm.graph_status(sessionId)

Expand Down Expand Up @@ -639,7 +639,7 @@ def addNM(self, host, node):
with RestClient(host=host, port=port, timeout=10, url_prefix="/api") as c:
return json.loads(
c._POST(
"/nodes/%s" % (node,),
f"/nodes/{node}",
).read()
)

Expand All @@ -648,7 +648,7 @@ def removeNM(self, host, node):
port = constants.ISLAND_DEFAULT_REST_PORT
logger.debug("Removing NM %s from DIM %s", (node, host))
with RestClient(host=host, port=port, timeout=10, url_prefix="/api") as c:
return json.loads(c._DELETE("/nodes/%s" % (node,)).read())
return json.loads(c._DELETE(f"/nodes/{node}").read())

@daliuge_aware
def getNMInfo(self, host):
Expand Down

0 comments on commit 9d53642

Please sign in to comment.