Skip to content

Commit

Permalink
Use pykka.traversable() instead of magic attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Dec 8, 2019
1 parent 5ed142a commit 96d78f9
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 31 deletions.
4 changes: 1 addition & 3 deletions mopidy/audio/actor.py
Expand Up @@ -142,8 +142,6 @@ def _add(self, element):


class SoftwareMixer:
pykka_traversable = True

def __init__(self, mixer):
self._mixer = mixer
self._element = None
Expand Down Expand Up @@ -452,7 +450,7 @@ def __init__(self, config, mixer):
self._signals = utils.Signals()

if mixer and self._config["audio"]["mixer"] == "software":
self.mixer = SoftwareMixer(mixer)
self.mixer = pykka.traversable(SoftwareMixer(mixer))

def on_start(self):
self._thread = threading.current_thread()
Expand Down
17 changes: 8 additions & 9 deletions mopidy/backend.py
@@ -1,5 +1,7 @@
import logging

import pykka

from mopidy import listener

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -44,9 +46,9 @@ class Backend:
#: List of URI schemes this backend can handle.
uri_schemes = []

# Because the providers is marked as pykka_traversible, we can't get() them
# from another actor, and need helper methods to check if the providers are
# set or None.
# Because the providers is marked as pykka.traversable(), we can't get()
# them from another actor, and need helper methods to check if the
# providers are set or None.

def has_library(self):
return self.library is not None
Expand All @@ -65,15 +67,14 @@ def ping(self):
return True


@pykka.traversable
class LibraryProvider:

"""
:param backend: backend the controller is a part of
:type backend: :class:`mopidy.backend.Backend`
"""

pykka_traversable = True

root_directory = None
"""
:class:`mopidy.models.Ref.directory` instance with a URI and name set
Expand Down Expand Up @@ -149,6 +150,7 @@ def search(self, query=None, uris=None, exact=False):
pass


@pykka.traversable
class PlaybackProvider:

"""
Expand All @@ -158,8 +160,6 @@ class PlaybackProvider:
:type backend: :class:`mopidy.backend.Backend`
"""

pykka_traversable = True

def __init__(self, audio, backend):
self.audio = audio
self.backend = backend
Expand Down Expand Up @@ -284,6 +284,7 @@ def get_time_position(self):
return self.audio.get_position().get()


@pykka.traversable
class PlaylistsProvider:

"""
Expand All @@ -295,8 +296,6 @@ class PlaylistsProvider:
:type backend: :class:`mopidy.backend.Backend` instance
"""

pykka_traversable = True

def __init__(self, backend):
self.backend = backend

Expand Down
18 changes: 11 additions & 7 deletions mopidy/core/actor.py
Expand Up @@ -52,14 +52,18 @@ def __init__(self, config=None, mixer=None, backends=None, audio=None):

self.backends = Backends(backends)

self.library = LibraryController(backends=self.backends, core=self)
self.history = HistoryController()
self.mixer = MixerController(mixer=mixer)
self.playback = PlaybackController(
audio=audio, backends=self.backends, core=self
self.library = pykka.traversable(
LibraryController(backends=self.backends, core=self)
)
self.playlists = PlaylistsController(backends=self.backends, core=self)
self.tracklist = TracklistController(core=self)
self.history = pykka.traversable(HistoryController())
self.mixer = pykka.traversable(MixerController(mixer=mixer))
self.playback = pykka.traversable(
PlaybackController(audio=audio, backends=self.backends, core=self)
)
self.playlists = pykka.traversable(
PlaylistsController(backends=self.backends, core=self)
)
self.tracklist = pykka.traversable(TracklistController(core=self))

self.audio = audio

Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/history.py
Expand Up @@ -9,8 +9,6 @@


class HistoryController:
pykka_traversable = True

def __init__(self):
self._history = []

Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/library.py
Expand Up @@ -31,8 +31,6 @@ def _backend_error_handling(backend, reraise=None):


class LibraryController:
pykka_traversable = True

def __init__(self, backends, core):
self.backends = backends
self.core = core
Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/mixer.py
Expand Up @@ -26,8 +26,6 @@ def _mixer_error_handling(mixer):


class MixerController:
pykka_traversable = True

def __init__(self, mixer):
self._mixer = mixer

Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/playback.py
Expand Up @@ -11,8 +11,6 @@


class PlaybackController:
pykka_traversable = True

def __init__(self, audio, backends, core):
# TODO: these should be internal
self.backends = backends
Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/playlists.py
Expand Up @@ -30,8 +30,6 @@ def _backend_error_handling(backend, reraise=None):


class PlaylistsController:
pykka_traversable = True

def __init__(self, backends, core):
self.backends = backends
self.core = core
Expand Down
2 changes: 0 additions & 2 deletions mopidy/core/tracklist.py
Expand Up @@ -11,8 +11,6 @@


class TracklistController:
pykka_traversable = True

def __init__(self, core):
self.core = core
self._next_tlid = 1
Expand Down

0 comments on commit 96d78f9

Please sign in to comment.