Skip to content

Commit

Permalink
moved all abstracts to __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolinski committed Mar 13, 2019
1 parent 2dedff4 commit 27b71ea
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion trakt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, Optional

from trakt.api import TraktApi
from trakt.core.abstract.abstract_models import AbstractBaseModel
from trakt.core.abstract import AbstractBaseModel
from trakt.version import __version__ # NOQA


Expand Down
2 changes: 1 addition & 1 deletion trakt/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from trakt.config import Config, DefaultConfig
from trakt.core.abstract.abstract_api import AbstractApi
from trakt.core.abstract import AbstractApi
from trakt.core.components import HttpComponent, OathComponent
from trakt.core.executors import Executor

Expand Down
44 changes: 41 additions & 3 deletions trakt/core/abstract/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
from trakt.core.abstract.abstract_api import AbstractApi
from trakt.core.abstract.abstract_component import AbstractComponent
from trakt.core.abstract.abstract_models import AbstractBaseModel
from __future__ import annotations

from typing import Any, Dict, Type, TypeVar, cast

import jsons


class AbstractApi:
pass


class AbstractComponent:
name: str = "base_component"
client: AbstractApi

def __init__(self, client: AbstractApi) -> None:
self.client = client


class _AbstractFromJson:
pass


T = TypeVar("T", bound=_AbstractFromJson)


class AbstractBaseModel(_AbstractFromJson):
_client = AbstractApi()

@classmethod
def from_json(cls: Type[T], data: Dict[str, Any]) -> T:
obj = jsons.load(data, cls)
return cast(T, obj)

@classmethod
def set_client(cls, client: AbstractApi) -> None:
cls._client = client

@property
def client(self) -> AbstractApi:
return self._client
2 changes: 0 additions & 2 deletions trakt/core/abstract/abstract_api.py

This file was deleted.

9 changes: 0 additions & 9 deletions trakt/core/abstract/abstract_component.py

This file was deleted.

30 changes: 0 additions & 30 deletions trakt/core/abstract/abstract_models.py

This file was deleted.

8 changes: 4 additions & 4 deletions trakt/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


class ClientError(Exception):
pass


class NotAuthenticated(ClientError):
def __init__(self, message: str, errors: Optional[List[Exception]] = None) -> None:
super().__init__(message)
if not errors:
errors = []
self.errors = errors


class NotAuthenticated(ClientError):
...
17 changes: 13 additions & 4 deletions trakt/core/executors.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from typing import List

from trakt.core.abstract import AbstractApi
from trakt.core.restpaths import Path


class Executor:
params: List[str]
client: AbstractApi
paths: List[Path]

def __init__(self, client, module):
def __init__(self, client: AbstractApi, module: str) -> None:
self.params = [module]
self.client = client
self.paths = []

def __getattr__(self, param):
def __getattr__(self, param: str) -> "Executor":
self.params.append(param)

return self

def __repr__(self) -> str:
return f'Executor(params={".".join(self.params)})'

def __call__(self, *args, **kwargs):
return repr(self)

def __repr__(self):
return f'Executor(params={".".join(self.params)})'
def install(self, paths):
if isinstance(paths, list):
self.paths.extend(paths)
else:
self.paths.append(paths)
2 changes: 1 addition & 1 deletion trakt/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from typing import Dict, List, Optional, Type, Union

from trakt.core.abstract.abstract_models import AbstractBaseModel
from trakt.core.abstract import AbstractBaseModel

MediaForeignIDType = Type[Union[int, str, None]]

Expand Down

0 comments on commit 27b71ea

Please sign in to comment.