From a631b79d227b8dd4b114b8d1043f3714fcee3e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 11 Oct 2022 13:17:19 +0300 Subject: [PATCH 1/3] Monkey patch trakt UserList with a type field --- plextraktsync/factory.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plextraktsync/factory.py b/plextraktsync/factory.py index dfaa669e11..80e779f41a 100644 --- a/plextraktsync/factory.py +++ b/plextraktsync/factory.py @@ -7,6 +7,8 @@ class Factory: def trakt_api(self): from plextraktsync.trakt_api import TraktApi + self.monkey_patch_trakt() + config = self.run_config() trakt = TraktApi(batch_delay=config.batch_delay) @@ -159,6 +161,24 @@ def config(self): return Config() + @staticmethod + def monkey_patch_trakt(): + from collections import namedtuple + + import trakt.users + + # Add `type` to UserList named tuple: + # - https://github.com/moogar0880/PyTrakt/pull/206 + # Monkey patch the class: + # - https://stackoverflow.com/a/28500620/2314626 + # - https://stackoverflow.com/a/62160225/2314626 + UserListTuple = namedtuple('UserList', trakt.users.UserList._fields + ('type',)) + + class UserList(UserListTuple, trakt.users.UserList): + pass + + trakt.users.UserList = UserList + factory = Factory() logger = factory.logger From 3b60c78f96732c3098fce03bb880986324858b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 17 Oct 2022 01:56:02 +0300 Subject: [PATCH 2/3] Create copy of UserList to prevent recursion --- plextraktsync/factory.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plextraktsync/factory.py b/plextraktsync/factory.py index 80e779f41a..97381baaf9 100644 --- a/plextraktsync/factory.py +++ b/plextraktsync/factory.py @@ -172,9 +172,10 @@ def monkey_patch_trakt(): # Monkey patch the class: # - https://stackoverflow.com/a/28500620/2314626 # - https://stackoverflow.com/a/62160225/2314626 - UserListTuple = namedtuple('UserList', trakt.users.UserList._fields + ('type',)) + UserListOriginal = trakt.users.UserList + UserListTuple = namedtuple('UserList', UserListOriginal._fields + ('type',)) - class UserList(UserListTuple, trakt.users.UserList): + class UserList(UserListTuple, UserListOriginal): pass trakt.users.UserList = UserList From 7f781681aed2c9ce5622b8f6e1a6259454fea7af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 14 Oct 2022 15:25:03 +0300 Subject: [PATCH 3/3] Remove exception catching to capture a trace --- plextraktsync/cli.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plextraktsync/cli.py b/plextraktsync/cli.py index e8a5372237..e6ebb44c1b 100644 --- a/plextraktsync/cli.py +++ b/plextraktsync/cli.py @@ -23,13 +23,7 @@ def wrap(*args, **kwargs): name = fn.__name__ module = importlib.import_module(f".commands.{name}", package=__package__) cmd = getattr(module, name) - - try: - cmd(*args, **kwargs) - except RuntimeError as e: - from click import ClickException - - raise ClickException(f"Error running {name} command: {str(e)}") + cmd(*args, **kwargs) return wrap