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

Switch to Buildarr v0.8 #69

Merged
merged 3 commits into from
May 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
hooks:
- id: mypy
additional_dependencies:
- buildarr==0.7.1
- buildarr==0.8.0b1
- types-requests==2.31.0.20240406
- repo: https://github.com/pdm-project/pdm
rev: "2.15.1"
Expand Down
37 changes: 19 additions & 18 deletions buildarr_sonarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,28 @@ def dump_config(url: Url, api_key: str) -> int:
url_base = url.path

instance_config = SonarrInstanceConfig(
**{ # type: ignore[arg-type]
"hostname": hostname,
"port": port,
"protocol": protocol,
"url_base": url_base,
},
hostname=hostname,
port=port,
protocol=protocol, # type: ignore[arg-type]
url_base=url_base,
)

click.echo(
SonarrManager()
.from_remote(
instance_config=instance_config,
secrets=SonarrSecrets.get_from_url(
hostname=hostname,
port=port,
protocol=protocol,
url_base=url_base,
api_key=api_key if api_key else None,
),
)
.yaml(exclude_unset=True),
(
SonarrManager()
.from_remote(
instance_config=instance_config,
secrets=SonarrSecrets.get_from_url(
hostname=hostname,
port=port,
protocol=protocol,
url_base=url_base,
api_key=api_key if api_key else None,
),
)
.model_dump_yaml(exclude_unset=True)
),
nl=False,
)

return 0
57 changes: 18 additions & 39 deletions buildarr_sonarr/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from buildarr.config import ConfigPlugin
from buildarr.types import NonEmptyStr, Port
from pydantic import validator
from typing_extensions import Self

from ..types import SonarrApiKey, SonarrProtocol
Expand All @@ -42,29 +41,23 @@
if TYPE_CHECKING:
from ..secrets import SonarrSecrets

class _SonarrInstanceConfig(ConfigPlugin[SonarrSecrets]): ...

else:

class _SonarrInstanceConfig(ConfigPlugin): ...


class SonarrSettingsConfig(SonarrConfigBase):
"""
Sonarr settings, used to configure a remote Sonarr instance.
"""

media_management = SonarrMediaManagementSettingsConfig() # type: ignore[call-arg]
profiles = SonarrProfilesSettingsConfig()
quality = SonarrQualitySettingsConfig()
indexers = SonarrIndexersSettingsConfig() # type: ignore[call-arg]
download_clients = SonarrDownloadClientsSettingsConfig()
import_lists = SonarrImportListsSettingsConfig()
connect = SonarrConnectSettingsConfig()
metadata = SonarrMetadataSettingsConfig()
tags = SonarrTagsSettingsConfig()
general = SonarrGeneralSettingsConfig()
ui = SonarrUISettingsConfig()
media_management: SonarrMediaManagementSettingsConfig = SonarrMediaManagementSettingsConfig()
profiles: SonarrProfilesSettingsConfig = SonarrProfilesSettingsConfig()
quality: SonarrQualitySettingsConfig = SonarrQualitySettingsConfig()
indexers: SonarrIndexersSettingsConfig = SonarrIndexersSettingsConfig()
download_clients: SonarrDownloadClientsSettingsConfig = SonarrDownloadClientsSettingsConfig()
import_lists: SonarrImportListsSettingsConfig = SonarrImportListsSettingsConfig()
connect: SonarrConnectSettingsConfig = SonarrConnectSettingsConfig()
metadata: SonarrMetadataSettingsConfig = SonarrMetadataSettingsConfig()
tags: SonarrTagsSettingsConfig = SonarrTagsSettingsConfig()
general: SonarrGeneralSettingsConfig = SonarrGeneralSettingsConfig()
ui: SonarrUISettingsConfig = SonarrUISettingsConfig()

def update_remote(
self,
Expand Down Expand Up @@ -182,7 +175,7 @@ def delete_remote(self, tree: str, secrets: SonarrSecrets, remote: Self) -> bool
)


class SonarrInstanceConfig(_SonarrInstanceConfig):
class SonarrInstanceConfig(ConfigPlugin["SonarrSecrets"]):
"""
By default, Buildarr will look for a single instance at `http://sonarr:8989`.
Most configurations are different, and to accommodate those, you can configure
Expand Down Expand Up @@ -222,7 +215,7 @@ class SonarrInstanceConfig(_SonarrInstanceConfig):
```
"""

hostname: NonEmptyStr = "sonarr" # type: ignore[assignment]
hostname: NonEmptyStr = "sonarr"
"""
Hostname of the Sonarr instance to connect to.

Expand All @@ -240,27 +233,17 @@ class SonarrInstanceConfig(_SonarrInstanceConfig):
```
"""

port: Port = 8989 # type: ignore[assignment]
port: Port = 8989
"""
Port number of the Sonarr instance to connect to.
"""

protocol: SonarrProtocol = "http" # type: ignore[assignment]
protocol: SonarrProtocol = "http"
"""
Communication protocol to use to connect to Sonarr.
"""

url_base: Optional[str] = None
"""
The URL path the Sonarr instance API is available under, if behind a reverse proxy.

API URLs are rendered like this: `<protocol>://<hostname>:<port><url_base>/api/v3/...`

When unset, the URL root will be used as the API endpoint
(e.g. `<protocol>://<hostname>:<port>/api/v3/...`).

*Added in version 0.6.3.*
"""
# url_base is defined in the configuration plugin base class.

api_key: Optional[SonarrApiKey] = None
"""
Expand All @@ -270,7 +253,7 @@ class SonarrInstanceConfig(_SonarrInstanceConfig):
This can only be done on Sonarr instances with authentication disabled.
"""

image: NonEmptyStr = "lscr.io/linuxserver/sonarr" # type: ignore[assignment]
image: NonEmptyStr = "lscr.io/linuxserver/sonarr"
"""
The default Docker image URI when generating a Docker Compose file.
"""
Expand All @@ -290,10 +273,6 @@ class SonarrInstanceConfig(_SonarrInstanceConfig):
Configuration options for Sonarr itself are set within this structure.
"""

@validator("url_base")
def validate_url_base(cls, value: Optional[str]) -> Optional[str]:
return f"/{value.strip('/')}" if value and value.strip("/") else None

def uses_trash_metadata(self) -> bool:
if self.settings.quality.uses_trash_metadata():
return True
Expand All @@ -305,7 +284,7 @@ def uses_trash_metadata(self) -> bool:
def render(self) -> Self:
if not self.uses_trash_metadata():
return self
copy = self.copy(deep=True)
copy = self.model_copy(deep=True)
copy._render()
return copy

Expand Down
Loading