Skip to content

Commit 4e07f29

Browse files
committed
Fix all flake8 issues
1 parent d1d1a32 commit 4e07f29

18 files changed

Lines changed: 57 additions & 48 deletions

libmuscle/python/libmuscle/manager/instance_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def run(self) -> None:
6161
class InstanceManager:
6262
"""Instantiates and manages running instances"""
6363
def __init__(
64-
self, configuration: Configuration, run_dir: RunDir,
64+
self, configuration: Configuration, run_dir: RunDir,
6565
instance_registry: InstanceRegistry, mlp_location: str) -> None:
6666
"""Create an InstanceManager.
6767
@@ -83,7 +83,7 @@ def __init__(
8383

8484
self._instantiator = NativeInstantiator(
8585
self._resources_in, self._requests_out, self._results_in,
86-
self._log_records_in, self._run_dir.path,
86+
self._log_records_in, self._run_dir.path,
8787
mlp_location=self._mlp_location)
8888
self._instantiator.start()
8989

libmuscle/python/libmuscle/manager/instantiator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ def __init__(
105105
self.stdout_path = stdout_path
106106
self.stderr_path = stderr_path
107107

108+
108109
class MonitorRequest(InstantiatorRequest):
109110
"""Requests monitoring a process."""
110111
def __init__(self, instance: str, hostname: str, pid: int) -> None:
111112
self.instance = instance
112113
self.hostname = hostname
113114
self.pid = pid
114115

116+
115117
class CancelAllRequest(InstantiatorRequest):
116118
"""Requests stopping all running processes."""
117119
pass

libmuscle/python/libmuscle/manager/manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ def __init__(
8989
self._server = MMPServer(
9090
self._logger, self._profile_store, self._configuration,
9191
self._instance_registry, self._topology_store,
92-
self._snapshot_registry, self._deadlock_detector, run_dir,
92+
self._snapshot_registry, self._deadlock_detector, run_dir,
9393
instance_manager=self._instance_manager)
9494

95-
9695
if self._instance_manager:
9796
self._instance_manager.set_manager_location(
9897
self.get_server_location())

libmuscle/python/libmuscle/manager/mlp_server.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
from typing import Any, Dict, List, Tuple, cast
44

55
import msgpack
6-
from ymmsl import Operator, Port, Reference
6+
from ymmsl import Reference
77

8-
from libmuscle.logging import LogLevel
98
from libmuscle.manager.logger import Logger
109
from libmuscle.manager.profile_store import ProfileStore
1110
from libmuscle.mcp.protocol import RequestType, ResponseType
1211
from libmuscle.mcp.tcp_transport_server import TcpTransportServer
1312
from libmuscle.mcp.transport_server import RequestHandler
14-
from libmuscle.profiling import (
15-
ProfileEvent, ProfileEventType, ProfileTimestamp)
16-
from libmuscle.timestamp import Timestamp
13+
from libmuscle.profiling import (ProfileTimestamp, ProfileEvent,
14+
ProfileEventType)
1715

1816

1917
_logger = logging.getLogger(__name__)
@@ -73,19 +71,20 @@ def _report_usage_events(
7371
7472
status (ResponseType): SUCCESS
7573
"""
76-
events : List[Tuple[str, ProfileEvent]] = []
74+
events: List[Tuple[str, ProfileEvent]] = []
7775
for instance_id, (cpu_usage, memory_usage) in usage.items():
7876
time = ProfileTimestamp()
7977
prof_event = ProfileEvent(ProfileEventType.RESOURCE_USAGE,
80-
start_time=time, stop_time=time,
81-
cpu_percent=cpu_usage, memory_usage=memory_usage)
78+
start_time=time, stop_time=time,
79+
cpu_percent=cpu_usage, memory_usage=memory_usage)
8280
events.append((instance_id, prof_event))
8381

8482
for event in events:
8583
self._profile_store.add_event(Reference(event[0]), event[1])
8684

8785
return [ResponseType.SUCCESS.value]
8886

87+
8988
class MLPServer:
9089
"""The MUSCLE Logging Protocol server.
9190

libmuscle/python/libmuscle/manager/mmp_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ def _register_instance(
179179
instance = Reference(instance_id)
180180

181181
if self._instance_manager:
182-
self._instance_manager._requests_out.put(MonitorRequest(instance_id, hostname, pid))
183-
182+
self._instance_manager._requests_out.put(
183+
MonitorRequest(instance_id, hostname, pid))
184+
184185
try:
185186
self._instance_registry.add(instance, locations, port_objs, pid, hostname)
186187

libmuscle/python/libmuscle/manager/profile_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def add_event(
110110
Args:
111111
event: The event to add.
112112
"""
113-
_logger.debug(f"Add profile event for instance {instance_id}, cpu: {event.cpu_percent}, memory: {event.memory_usage}")
113+
_logger.debug(f"Add profile event for instance {instance_id}, \
114+
cpu: {event.cpu_percent}, memory: {event.memory_usage}")
114115

115116
self._queue.put((instance_id, [event]))
116117
if _SYNCHED:

libmuscle/python/libmuscle/manager/test/test_mlp_request_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import msgpack
22
from ymmsl import Reference
33

4-
from libmuscle.logging import LogLevel
54
from libmuscle.manager.mlp_server import MLPRequestHandler
65
from libmuscle.mcp.protocol import RequestType, ResponseType
76

@@ -11,13 +10,12 @@ def test_create_servicer(logger, profile_store):
1110

1211

1312
def test_report_usage(logger, profile_store):
14-
profile_store.store_instances([Reference('instance1'),Reference('instance2'),Reference('instance3')])
13+
profile_store.store_instances([Reference('instance1'), Reference('instance2')])
1514
handler = MLPRequestHandler(logger, profile_store)
1615

1716
usage = {
1817
"instance1": (0.1, 1024),
1918
"instance2": (0.2, 2048),
20-
"instance3": (0.3, 3072),
2119
}
2220

2321
request = [
@@ -29,4 +27,4 @@ def test_report_usage(logger, profile_store):
2927

3028
decoded_result = msgpack.unpackb(result, raw=False)
3129

32-
assert decoded_result[0] == ResponseType.SUCCESS.value
30+
assert decoded_result[0] == ResponseType.SUCCESS.value

libmuscle/python/libmuscle/manager/test/test_profile_database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def t(offset: int) -> ProfileTimestamp:
7575
ProfileEventType.RECEIVE_WAIT, t(2600), t(2870),
7676
Port('in', Operator.O_I), None, None, 1000000, 0.0),
7777
ProfileEvent(
78-
ProfileEventType.RESOURCE_USAGE, start_time=t(2700), stop_time=t(2800),
79-
cpu_percent=12.5, memory_usage=1024000),
78+
ProfileEventType.RESOURCE_USAGE, start_time=t(2700),
79+
stop_time=t(2800), cpu_percent=12.5, memory_usage=1024000),
8080
ProfileEvent(ProfileEventType.SHUTDOWN_WAIT, t(10000), t(11000)),
8181
ProfileEvent(ProfileEventType.DEREGISTER, t(11000), t(11100))]
8282

@@ -141,14 +141,14 @@ def test_time_taken(db_file):
141141
assert 200.0 == db.time_taken(etype='DEREGISTER', aggregate='sum')
142142
assert 600.0 == db.time_taken(etype='SEND', aggregate='sum')
143143

144+
144145
def test_resource_usage_event(db_file):
145146
with ProfileDatabase(db_file) as db:
146147
cur = db._get_cursor()
147-
cur.execute(f"SELECT * FROM usage_events WHERE event_type_oid = '{ProfileEventType.RESOURCE_USAGE.value}'")
148+
cur.execute(f"SELECT * FROM usage_events WHERE event_type_oid = \
149+
'{ProfileEventType.RESOURCE_USAGE.value}'")
148150
rows = cur.fetchall()
149151
assert len(rows) == 1
150152
# Check columns (cpu_percent is 2nd to last, memory_usage is last)
151153
assert rows[0][-2] == 12.5
152154
assert rows[0][-1] == 1024000
153-
154-

libmuscle/python/libmuscle/mlp_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Any, Dict, List, Tuple
1+
from typing import Any, Dict, List, Tuple
22
from logging import Logger
33

44
import msgpack
@@ -30,7 +30,8 @@ def close(self) -> None:
3030
self._transport_client.close()
3131

3232
def report_usage(self, pids: List[Tuple[str, int]], logger: Logger) -> None:
33-
"""Report usage of resources of processes with given (instance_id, pid) on this node.
33+
"""Report usage of resources of processes with given (instance_id, pid)
34+
on this node.
3435
3536
Args:
3637
pids: List of (instance_id, pid) tuples

libmuscle/python/libmuscle/native_instantiator/agent/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, node_name: str, server_location: str, mlp_location: str) -> N
3131
self._process_manager = ProcessManager()
3232

3333
self._node_name = node_name
34-
self._monitor_pids : List[Tuple[str, int]] = []
34+
self._monitor_pids: List[Tuple[str, int]] = []
3535

3636
_logger.info(f'Connecting to manager at {server_location}')
3737
self._server = MAPClient(self._node_name, server_location)
@@ -65,7 +65,6 @@ def run(self) -> None:
6565
shutting_down = True
6666
_logger.info('Agent shutting down')
6767

68-
6968
finished = self._process_manager.get_finished()
7069
if finished:
7170
for name, exit_code in finished:

0 commit comments

Comments
 (0)