Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade prowlarr-py, migrate to pydantic v2 #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion buildarr_prowlarr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def prowlarr_api_client(

configuration = Configuration(
host=secrets.host_url if secrets else host_url,
request_timeout=state.request_timeout,
)

root_logger = logging.getLogger()
Expand Down
44 changes: 22 additions & 22 deletions buildarr_prowlarr/config/settings/apps/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
from __future__ import annotations

from logging import getLogger
from typing import Any, Dict, Iterable, List, Literal, Mapping, Optional, Set, Union, cast
from typing import Any, ClassVar, Dict, Iterable, List, Literal, Mapping, Optional, Set, Union, cast

import prowlarr

from buildarr.config import RemoteMapEntry
from buildarr.state import state
from buildarr.types import BaseEnum, InstanceName, LowerCaseNonEmptyStr, NonEmptyStr, Password
from buildarr.types import BaseEnum, InstanceReference, LowerCaseNonEmptyStr, NonEmptyStr, Password
from packaging.version import Version
from pydantic import AnyHttpUrl, Field, SecretStr, validator
from typing_extensions import Annotated, Self
Expand Down Expand Up @@ -97,8 +97,8 @@ class Application(ProwlarrConfigBase):
This is used to associate the application with indexers.
"""

_implementation: str
_remote_map: List[RemoteMapEntry] = []
_implementation: ClassVar[str]
_remote_map: ClassVar[List[RemoteMapEntry]] = []

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -153,7 +153,7 @@ def _get_sync_category_options(
next(
(
f
for f in cast(List[prowlarr.Field], api_schema.fields)
for f in cast(List[prowlarr.ContractField], api_schema.fields)
if f.name == "syncCategories"
),
).select_options,
Expand Down Expand Up @@ -335,8 +335,8 @@ class LazylibrarianApplication(Application):
Default sync category values for this application type.
"""

_implementation: str = "LazyLibrarian"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "LazyLibrarian"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]


class LidarrApplication(ArrApplication):
Expand Down Expand Up @@ -365,8 +365,8 @@ class LidarrApplication(ArrApplication):
Default sync category values for this application type.
"""

_implementation: str = "Lidarr"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "Lidarr"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]


class MylarApplication(Application):
Expand All @@ -389,8 +389,8 @@ class MylarApplication(Application):
Default sync category values for this application type.
"""

_implementation: str = "Mylar"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "Mylar"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]


class RadarrApplication(ArrApplication):
Expand All @@ -409,7 +409,7 @@ class RadarrApplication(ArrApplication):
Type value associated with this kind of application.
"""

instance_name: Optional[InstanceName] = Field(None, plugin="radarr")
instance_name: Annotated[Optional[str], InstanceReference(plugin_name="radarr")] = None
"""
The name of the Radarr instance within Buildarr, if adding
a Buildarr-defined Radarr instance to this Prowlarr instance.
Expand Down Expand Up @@ -438,8 +438,8 @@ class RadarrApplication(ArrApplication):
Default sync category values for this application type.
"""

_implementation: str = "Radarr"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "Radarr"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]

@validator("api_key")
def validate_api_key(
Expand Down Expand Up @@ -489,8 +489,8 @@ class ReadarrApplication(ArrApplication):
Default sync category values for this application type.
"""

_implementation: str = "Readarr"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "Readarr"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]


class SonarrApplication(ArrApplication):
Expand All @@ -509,7 +509,7 @@ class SonarrApplication(ArrApplication):
Type value associated with this kind of application.
"""

instance_name: Optional[InstanceName] = Field(None, plugin="sonarr")
instance_name: Annotated[Optional[str], InstanceReference(plugin_name="sonarr")] = None
"""
The name of the Sonarr instance within Buildarr, if adding
a Buildarr-defined Sonarr instance to this Prowlarr instance.
Expand Down Expand Up @@ -549,7 +549,7 @@ class SonarrApplication(ArrApplication):
*New in version 0.4.0.*
"""

_implementation: str = "Sonarr"
_implementation: ClassVar[str] = "Sonarr"

@validator("api_key")
def validate_api_key(
Expand Down Expand Up @@ -625,12 +625,12 @@ class WhisparrApplication(ArrApplication):
Default sync category values for this application type.
"""

_implementation: str = "Whisparr"
_remote_map: List[RemoteMapEntry] = [("api_key", "apiKey", {"is_field": True})]
_implementation: ClassVar[str] = "Whisparr"
_remote_map: ClassVar[List[RemoteMapEntry]] = [("api_key", "apiKey", {"is_field": True})]


APPLICATION_TYPE_MAP = {
application_type._implementation: application_type # type: ignore[attr-defined]
str(application_type._implementation): application_type # type: ignore[attr-defined]
for application_type in (
LazylibrarianApplication,
LidarrApplication,
Expand Down Expand Up @@ -724,7 +724,7 @@ class ApplicationsSettings(ProwlarrConfigBase):
on WikiArr.
"""

delete_unmanaged: bool = False
delete_unmanaged: Annotated[bool, Field] = False
"""
Automatically delete application links not configured in Buildarr.

Expand Down
9 changes: 5 additions & 4 deletions buildarr_prowlarr/config/settings/apps/sync_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

from __future__ import annotations

from dataclasses import Field
from logging import getLogger
from typing import Any, Dict, List, Mapping
from typing import Any, ClassVar, Dict, List, Mapping

import prowlarr

from buildarr.config import RemoteMapEntry
from pydantic import PositiveInt
from typing_extensions import Self
from typing_extensions import Annotated, Self

from ....api import prowlarr_api_client
from ....secrets import ProwlarrSecrets
Expand Down Expand Up @@ -60,7 +61,7 @@ class SyncProfile(ProwlarrConfigBase):
The minimum number of seeders required by the application to download a release.
"""

_remote_map: List[RemoteMapEntry] = [
_remote_map: ClassVar[List[RemoteMapEntry]] = [
("enable_rss", "enableRss", {}),
("enable_interactive_search", "enableInteractiveSearch", {}),
("enable_automatic_search", "enableAutomaticSearch", {}),
Expand Down Expand Up @@ -148,7 +149,7 @@ class SyncProfilesSettings(ProwlarrConfigBase):
on WikiArr.
"""

delete_unmanaged: bool = False
delete_unmanaged: Annotated[bool, Field] = False
"""
Automatically delete indexer proxies not configured in Buildarr.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ProwlarrDownloadClientsSettings(ProwlarrConfigBase):
```
"""

delete_unmanaged: bool = False
delete_unmanaged: Annotated[bool, Field] = False
"""
Automatically delete download clients not defined in Buildarr.
"""
Expand Down
6 changes: 3 additions & 3 deletions buildarr_prowlarr/config/settings/download_clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import annotations

from logging import getLogger
from typing import Any, Dict, List, Mapping, Set
from typing import Any, ClassVar, Dict, List, Mapping, Set

import prowlarr

Expand Down Expand Up @@ -89,8 +89,8 @@ class DownloadClient(ProwlarrConfigBase):
If no tags are assigned, all media can use the client.
"""

_implementation: str
_remote_map: List[RemoteMapEntry] = []
_implementation: ClassVar[str]
_remote_map: ClassVar[List[RemoteMapEntry]] = []

@classmethod
def _get_base_remote_map(
Expand Down
34 changes: 17 additions & 17 deletions buildarr_prowlarr/config/settings/download_clients/torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from __future__ import annotations

from logging import getLogger
from typing import Any, Dict, List, Literal, Mapping, Optional, Set
from typing import Any, ClassVar, Dict, List, Literal, Mapping, Optional, Set

from buildarr.config import RemoteMapEntry
from buildarr.types import BaseEnum, LowerCaseNonEmptyStr, NonEmptyStr, Password, Port
Expand Down Expand Up @@ -213,8 +213,8 @@ class Aria2DownloadClient(TorrentDownloadClient):
Secret token to use to authenticate with the download client.
"""

_implementation: str = "Aria2"
_remote_map: List[RemoteMapEntry] = [
_implementation: ClassVar[str] = "Aria2"
_remote_map: ClassVar[List[RemoteMapEntry]] = [
("host", "host", {"is_field": True}),
("port", "port", {"is_field": True}),
("use_ssl", "useSsl", {"is_field": True}),
Expand Down Expand Up @@ -282,7 +282,7 @@ class DelugeDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "Deluge"
_implementation: ClassVar[str] = "Deluge"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -369,8 +369,8 @@ class DownloadstationTorrentDownloadClient(TorrentDownloadClient):
Leave blank, set to `null` or undefined to use the default download client location.
"""

_implementation: str = "TorrentDownloadStation"
_remote_map: List[RemoteMapEntry] = [
_implementation: ClassVar[str] = "TorrentDownloadStation"
_remote_map: ClassVar[List[RemoteMapEntry]] = [
("host", "host", {"is_field": True}),
("port", "port", {"is_field": True}),
("use_ssl", "useSsl", {"is_field": True}),
Expand Down Expand Up @@ -458,7 +458,7 @@ class FloodDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "Flood"
_implementation: ClassVar[str] = "Flood"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -580,7 +580,7 @@ class FreeboxDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "TorrentFreeboxDownload"
_implementation: ClassVar[str] = "TorrentFreeboxDownload"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -673,7 +673,7 @@ class HadoukenDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "Hadouken"
_implementation: ClassVar[str] = "Hadouken"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -776,7 +776,7 @@ class QbittorrentDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "QBittorrent"
_implementation: ClassVar[str] = "QBittorrent"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -896,7 +896,7 @@ class RtorrentDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "RTorrent"
_implementation: ClassVar[str] = "RTorrent"

@classmethod
def _get_base_remote_map(
Expand Down Expand Up @@ -962,8 +962,8 @@ class TorrentBlackholeDownloadClient(TorrentDownloadClient):
Extension to use for magnet links.
"""

_implementation: str = "TorrentBlackhole"
_remote_map: List[RemoteMapEntry] = [
_implementation: ClassVar[str] = "TorrentBlackhole"
_remote_map: ClassVar[List[RemoteMapEntry]] = [
("torrent_folder", "torrentFolder", {"is_field": True}),
("save_magnet_files", "saveMagnetFiles", {"is_field": True}),
("magnet_file_extension", "magnetFileExtension", {"is_field": True}),
Expand Down Expand Up @@ -1038,7 +1038,7 @@ class TransmissionDownloadClientBase(TorrentDownloadClient):
Add media to the download client in the Paused state.
"""

_remote_map: List[RemoteMapEntry] = [
_remote_map: ClassVar[List[RemoteMapEntry]] = [
("host", "host", {"is_field": True}),
("port", "port", {"is_field": True}),
("use_ssl", "useSsl", {"is_field": True}),
Expand Down Expand Up @@ -1089,7 +1089,7 @@ class TransmissionDownloadClient(TransmissionDownloadClientBase):
Type value associated with this kind of download client.
"""

_implementation: str = "Transmission"
_implementation: ClassVar[str] = "Transmission"


class VuzeDownloadClient(TransmissionDownloadClientBase):
Expand All @@ -1102,7 +1102,7 @@ class VuzeDownloadClient(TransmissionDownloadClientBase):
Type value associated with this kind of download client.
"""

_implementation: str = "Vuze"
_implementation: ClassVar[str] = "Vuze"


class UtorrentDownloadClient(TorrentDownloadClient):
Expand Down Expand Up @@ -1174,7 +1174,7 @@ class UtorrentDownloadClient(TorrentDownloadClient):
with the selected Prowlarr categories.
"""

_implementation: str = "UTorrent"
_implementation: ClassVar[str] = "UTorrent"

@classmethod
def _get_base_remote_map(
Expand Down
Loading
Loading