Make noisicaa.node_db pylint and mypy clean.

looper
Ben Niemann 5 years ago
parent 7e62bc0749
commit 8c2f4b046f

@ -64,22 +64,6 @@ class TestAudioProcClient(
pass
class NodeDBClientImpl(object):
def __init__(self, event_loop, server):
super().__init__()
self.event_loop = event_loop
self.server = server
async def setup(self):
pass
async def cleanup(self):
pass
class NodeDBClient(node_db.NodeDBClientMixin, NodeDBClientImpl):
pass
UNSET = object()
class CallbackServer(ipc.Server):
@ -137,7 +121,7 @@ class PlayerTest(
await self.callback_server.setup()
node_db_address = await self.process_manager_client.call('CREATE_NODE_DB_PROCESS')
self.node_db_client = NodeDBClient(self.loop, self.callback_server)
self.node_db_client = node_db.NodeDBClient(self.loop, self.callback_server)
await self.node_db_client.setup()
await self.node_db_client.connect(node_db_address)

@ -156,22 +156,6 @@ class AudioProcClient(audioproc.AudioProcClientMixin, AudioProcClientImpl):
pass
class NodeDBClientImpl(object):
def __init__(self, event_loop, server):
super().__init__()
self.event_loop = event_loop
self.server = server
async def setup(self):
pass
async def cleanup(self):
pass
class NodeDBClient(node_db.NodeDBClientMixin, NodeDBClientImpl):
pass
class ProjectProcess(core.SessionHandlerMixin, core.ProcessBase):
session_cls = Session
@ -214,7 +198,7 @@ class ProjectProcess(core.SessionHandlerMixin, core.ProcessBase):
node_db_address = await self.manager.call(
'CREATE_NODE_DB_PROCESS')
self.node_db = NodeDBClient(self.event_loop, self.server)
self.node_db = node_db.NodeDBClient(self.event_loop, self.server)
await self.node_db.setup()
await self.node_db.connect(node_db_address)

@ -18,7 +18,7 @@
#
# @end:license
from .client import NodeDBClientMixin
from .client import NodeDBClient
from .node_description_pb2 import (
NotSupportedReasons,
ProcessorDescription,

@ -20,75 +20,76 @@
#
# @end:license
# TODO: mypy-unclean
import asyncio
import logging
from typing import Dict, Iterable, Set # pylint: disable=unused-import
from noisicaa import core
from noisicaa.core import ipc
from . import mutations
from . import node_description_pb2
logger = logging.getLogger(__name__)
class NodeDBClientMixin(object):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._stub = None
self._session_id = None
self._nodes = {}
class NodeDBClient(object):
def __init__(self, event_loop: asyncio.AbstractEventLoop, server: ipc.Server) -> None:
self.event_loop = event_loop
self.server = server
self.listeners = core.CallbackRegistry()
self.__stub = None # type: ipc.Stub
self.__session_id = None # type: str
self.__nodes = {} # type: Dict[str, node_description_pb2.NodeDescription]
@property
def nodes(self):
def nodes(self) -> Iterable[node_description_pb2.NodeDescription]:
return sorted(
self._nodes.items(), key=lambda i: i[1].display_name)
self.__nodes.items(), key=lambda i: i[1].display_name)
def get_node_description(self, uri):
return self._nodes[uri]
def get_node_description(self, uri: str) -> node_description_pb2.NodeDescription:
return self.__nodes[uri]
async def setup(self):
await super().setup()
self.server.add_command_handler(
'NODEDB_MUTATION', self.handle_mutation)
async def setup(self) -> None:
self.server.add_command_handler('NODEDB_MUTATION', self.__handle_mutation)
async def cleanup(self):
async def cleanup(self) -> None:
await self.disconnect()
await super().cleanup()
async def connect(self, address, flags=None):
assert self._stub is None
self._stub = ipc.Stub(self.event_loop, address)
await self._stub.connect()
self._session_id = await self._stub.call(
async def connect(self, address: str, flags: Set[str] = None) -> None:
assert self.__stub is None
self.__stub = ipc.Stub(self.event_loop, address)
await self.__stub.connect()
self.__session_id = await self.__stub.call(
'START_SESSION', self.server.address, flags)
async def disconnect(self, shutdown=False):
if self._session_id is not None:
async def disconnect(self, shutdown: bool = False) -> None:
if self.__session_id is not None:
try:
await self._stub.call('END_SESSION', self._session_id)
await self.__stub.call('END_SESSION', self.__session_id)
except ipc.ConnectionClosed:
logger.info("Connection already closed.")
self._session_id = None
self.__session_id = None
if self._stub is not None:
if self.__stub is not None:
if shutdown:
await self.shutdown()
await self._stub.close()
self._stub = None
await self.__stub.close()
self.__stub = None
async def shutdown(self):
await self._stub.call('SHUTDOWN')
async def shutdown(self) -> None:
await self.__stub.call('SHUTDOWN')
async def start_scan(self):
return await self._stub.call('START_SCAN', self._session_id)
async def start_scan(self) -> None:
await self.__stub.call('START_SCAN', self.__session_id)
def handle_mutation(self, mutation):
def __handle_mutation(self, mutation: mutations.Mutation) -> None:
logger.info("Mutation received: %s", mutation)
if isinstance(mutation, mutations.AddNodeDescription):
assert mutation.uri not in self._nodes
self._nodes[mutation.uri] = mutation.description
assert mutation.uri not in self.__nodes
self.__nodes[mutation.uri] = mutation.description
else:
raise ValueError(mutation)

@ -30,29 +30,13 @@ from . import process
from . import client
class TestClientImpl(object):
def __init__(self, event_loop):
super().__init__()
self.event_loop = event_loop
self.server = ipc.Server(self.event_loop, 'client', socket_dir=TEST_OPTS.TMP_DIR)
async def setup(self):
await self.server.setup()
async def cleanup(self):
await self.server.cleanup()
class TestClient(client.NodeDBClientMixin, TestClientImpl):
pass
class NodeDBClientTest(unittest.AsyncTestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.process = None
self.process_task = None
self.client_server = None
self.client = None
async def setup_testcase(self):
@ -62,7 +46,10 @@ class NodeDBClientTest(unittest.AsyncTestCase):
self.process_task = self.loop.create_task(
self.process.run())
self.client = TestClient(self.loop)
self.client_server = ipc.Server(self.loop, 'client', socket_dir=TEST_OPTS.TMP_DIR)
await self.client_server.setup()
self.client = client.NodeDBClient(self.loop, self.client_server)
await self.client.setup()
await self.client.connect(self.process.server.address)
@ -70,6 +57,8 @@ class NodeDBClientTest(unittest.AsyncTestCase):
if self.client is not None:
await self.client.disconnect(shutdown=True)
await self.client.cleanup()
if self.client_server is not None:
await self.client_server.cleanup()
if self.process is not None:
if self.process_task is not None:
await self.process.shutdown()

@ -20,8 +20,6 @@
#
# @end:license
# TODO: pylint-unclean
import logging
import os
import os.path
@ -38,14 +36,14 @@ logger = logging.getLogger(__name__)
class CSoundScanner(scanner.Scanner):
def scan(self):
rootdir = os.path.join(constants.DATA_DIR, 'csound')
for dirpath, dirnames, filenames in os.walk(rootdir):
for dirpath, _, filenames in os.walk(rootdir):
for filename in filenames:
if not filename.endswith('.csnd'):
continue
uri = 'builtin://csound/%s' % filename[:-5]
path = os.path.join(rootdir, filename)
path = os.path.join(dirpath, filename)
logger.info("Loading csound node %s from %s", uri, path)
tree = ElementTree.parse(path)
@ -93,25 +91,25 @@ class CSoundScanner(scanner.Scanner):
port_desc.bypass_port = bypass_elem.get('port')
if (port_desc.direction == node_db.PortDescription.INPUT
and port_desc.type == node_db.PortDescription.EVENTS):
and port_desc.type == node_db.PortDescription.EVENTS):
csound_elem = port_elem.find('csound')
if csound_elem is not None:
port_desc.csound_instr = csound_elem.get('instr')
if (port_desc.direction == node_db.PortDescription.INPUT
and port_desc.type == node_db.PortDescription.KRATE_CONTROL):
and port_desc.type == node_db.PortDescription.KRATE_CONTROL):
float_control_elem = port_elem.find('float-control')
if float_control_elem is not None:
value_desc = port_desc.float_value
min = float_control_elem.get('min')
if min is not None:
value_desc.min = float(min)
max = float_control_elem.get('max')
if max is not None:
value_desc.max = float(max)
default = float_control_elem.get('default')
if default is not None:
value_desc.default = float(default)
min_value = float_control_elem.get('min')
if min_value is not None:
value_desc.min = float(min_value)
max_value = float_control_elem.get('max')
if max_value is not None:
value_desc.max = float(max_value)
default_value = float_control_elem.get('default')
if default_value is not None:
value_desc.default = float(default_value)
csound_desc = desc.csound

@ -20,8 +20,6 @@
#
# @end:license
# TODO: pylint-unclean
import logging
import os
import os.path
@ -39,12 +37,12 @@ class LadspaScanner(scanner.Scanner):
def scan(self):
# TODO: support configurable searchpaths
rootdir = os.environ.get('LADSPA_PATH', '/usr/lib/ladspa')
for dirpath, dirnames, filenames in os.walk(rootdir):
for dirpath, _, filenames in os.walk(rootdir):
for filename in filenames:
if not filename.endswith('.so'):
continue
path = os.path.join(rootdir, filename)
path = os.path.join(dirpath, filename)
logger.info("Loading LADSPA plugins from %s", path)
try:
@ -53,7 +51,7 @@ class LadspaScanner(scanner.Scanner):
logger.warning("Failed to load LADSPA library %s: %s", path, exc)
continue
for descriptor in lib.descriptors:
for descriptor in lib.descriptors: # pylint: disable=not-an-iterable
uri = 'ladspa://%s/%s' % (filename, descriptor.label)
logger.info("Adding LADSPA plugin %s", uri)

@ -20,10 +20,13 @@
#
# @end:license
from typing import Iterable, Tuple
from noisicaa import node_db
class Scanner(object):
def __init__(self):
def __init__(self) -> None:
pass
def scan(self):
def scan(self) -> Iterable[Tuple[str, node_db.NodeDescription]]:
raise NotImplementedError

@ -21,10 +21,12 @@
# @end:license
import logging
from typing import cast, Set, Dict, List # pylint: disable=unused-import
from noisicaa import core
from .private import db
from . import process_base
from . import mutations
logger = logging.getLogger(__name__)
@ -32,46 +34,47 @@ logger = logging.getLogger(__name__)
class Session(core.CallbackSessionMixin, core.SessionBase):
async_connect = False
def __init__(self, client_address, flags, **kwargs):
def __init__(self, client_address: str, flags: Set[str], **kwargs) -> None:
super().__init__(callback_address=client_address, **kwargs)
self.flags = flags or set()
self.__flags = flags or set()
async def publish_mutation(self, mutation):
async def publish_mutation(self, mutation: mutations.Mutation) -> None:
await self.callback('NODEDB_MUTATION', mutation)
def async_publish_mutation(self, mutation):
def async_publish_mutation(self, mutation: mutations.Mutation) -> None:
self.async_callback('NODEDB_MUTATION', mutation)
class NodeDBProcess(process_base.NodeDBProcessBase):
session_cls = Session
def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.db = db.NodeDB()
async def setup(self):
async def setup(self) -> None:
await super().setup()
self.db.setup()
async def cleanup(self):
async def cleanup(self) -> None:
self.db.cleanup()
await super().cleanup()
def publish_mutation(self, mutation):
def publish_mutation(self, mutation: mutations.Mutation) -> None:
for session in self.sessions:
session = cast(Session, session)
session.async_publish_mutation(mutation)
async def session_started(self, session):
async def session_started(self, session: core.SessionBase) -> None:
session = cast(Session, session)
# Send initial mutations to build up the current pipeline
# state.
for mutation in self.db.initial_mutations():
await session.publish_mutation(mutation)
async def handle_start_scan(self, session_id):
async def handle_start_scan(self, session_id: str) -> None:
self.get_session(session_id)
return self.db.start_scan()
self.db.start_scan()
class NodeDBSubprocess(core.SubprocessMixin, NodeDBProcess):

@ -87,22 +87,6 @@ class AudioProcClient(
self.__app.onPipelineStatus(status)
class NodeDBClientImpl(object):
def __init__(self, event_loop, server):
super().__init__()
self.event_loop = event_loop
self.server = server
async def setup(self):
pass
async def cleanup(self):
pass
class NodeDBClient(node_db.NodeDBClientMixin, NodeDBClientImpl):
pass
class InstrumentDBClientImpl(object):
def __init__(self, event_loop, server):
super().__init__()
@ -213,11 +197,9 @@ class BaseEditorApp(object):
pass
async def createNodeDB(self):
node_db_address = await self.process.manager.call(
'CREATE_NODE_DB_PROCESS')
node_db_address = await self.process.manager.call('CREATE_NODE_DB_PROCESS')
self.node_db = NodeDBClient(
self.process.event_loop, self.process.server)
self.node_db = node_db.NodeDBClient(self.process.event_loop, self.process.server)
await self.node_db.setup()
await self.node_db.connect(node_db_address)

Loading…
Cancel
Save