Skip to content

Commit

Permalink
[BACKEND] Remove subscription __value__ (#856)
Browse files Browse the repository at this point in the history
Removes the deprecated `__value__` field in the subscriptions file (different from `__preset__` which is NOT deprecated). This was very short-lived, and most likely not used.
  • Loading branch information
jmbannon authored Dec 27, 2023
1 parent 008bcf1 commit 1375a0f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 204 deletions.
13 changes: 0 additions & 13 deletions src/ytdl_sub/config/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ytdl_sub.config.defaults import DEFAULT_LOCK_DIRECTORY
from ytdl_sub.config.defaults import MAX_FILE_NAME_BYTES
from ytdl_sub.prebuilt_presets import PREBUILT_PRESETS
from ytdl_sub.subscriptions.utils import SUBSCRIPTION_VALUE_CONFIG_KEY
from ytdl_sub.validators.file_path_validators import FFmpegFileValidator
from ytdl_sub.validators.file_path_validators import FFprobeFileValidator
from ytdl_sub.validators.strict_dict_validator import StrictDictValidator
Expand Down Expand Up @@ -107,7 +106,6 @@ class ConfigOptions(StrictDictValidator):
"ffprobe_path",
"file_name_max_bytes",
"experimental",
SUBSCRIPTION_VALUE_CONFIG_KEY,
}

def __init__(self, name: str, value: Any):
Expand Down Expand Up @@ -142,9 +140,6 @@ def __init__(self, name: str, value: Any):
self._file_name_max_bytes = self._validate_key(
key="file_name_max_bytes", validator=IntValidator, default=MAX_FILE_NAME_BYTES
)
self._subscription_value = self._validate_key_if_present(
key=SUBSCRIPTION_VALUE_CONFIG_KEY, validator=StringValidator
)

@property
def working_directory(self) -> str:
Expand Down Expand Up @@ -237,14 +232,6 @@ def ffprobe_path(self) -> str:
"""
return self._ffprobe_path.value

@property
def subscription_value(self) -> Optional[str]:
"""
Sets the :ref:`subscription value` for subscription
files that use this config.
"""
return self._subscription_value.value if self._subscription_value else None


class ConfigValidator(StrictDictValidator):
_optional_keys = {"configuration", "presets"}
Expand Down
37 changes: 2 additions & 35 deletions src/ytdl_sub/subscriptions/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
from typing import Any
from typing import Dict
from typing import List
from typing import Optional

from ytdl_sub.config.config_file import ConfigFile
from ytdl_sub.config.preset import Preset
from ytdl_sub.subscriptions.subscription_download import SubscriptionDownload
from ytdl_sub.subscriptions.subscription_validators import SubscriptionValidator
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.logger import Logger
from ytdl_sub.utils.yaml import load_yaml
from ytdl_sub.validators.validators import LiteralDictValidator

FILE_PRESET_APPLY_KEY = "__preset__"
FILE_SUBSCRIPTION_VALUE_KEY = "__value__"

logger = Logger.get("subscription")

Expand Down Expand Up @@ -70,36 +67,12 @@ def from_dict(cls, config: ConfigFile, preset_name: str, preset_dict: Dict) -> "
config=config,
)

@classmethod
def _maybe_get_subscription_value(
cls, config: ConfigFile, subscription_dict: Dict
) -> Optional[str]:
subscription_value_key: Optional[str] = config.config_options.subscription_value
if FILE_SUBSCRIPTION_VALUE_KEY in subscription_dict:
if not isinstance(subscription_dict[FILE_SUBSCRIPTION_VALUE_KEY], str):
raise ValidationException(
f"Using {FILE_SUBSCRIPTION_VALUE_KEY} in a subscription"
f"must be a string that corresponds to an override variable"
)

subscription_value_key = subscription_dict[FILE_SUBSCRIPTION_VALUE_KEY]

if subscription_value_key is not None:
logger.warning(
"Using %s in a subscription will eventually be deprecated in favor of writing "
"to the override variable `subscription_value`. Please update by Dec 2023.",
FILE_SUBSCRIPTION_VALUE_KEY,
)
return subscription_value_key

@classmethod
def from_file_path(
cls, config: ConfigFile, subscription_path: str | Path
) -> List["Subscription"]:
"""
Loads subscriptions from a file and applies ``__preset__`` to all of them if present.
If a subscription is in the form of key: value, it will set value to the override
variable defined in ``__value__``.
Loads subscriptions from a file.
Parameters
----------
Expand All @@ -121,9 +94,6 @@ def from_file_path(
subscription_dict = load_yaml(file_path=subscription_path)

has_file_preset = FILE_PRESET_APPLY_KEY in subscription_dict
file_subscription_value: Optional[str] = cls._maybe_get_subscription_value(
config=config, subscription_dict=subscription_dict
)

# If a file preset is present...
if has_file_preset:
Expand All @@ -138,9 +108,7 @@ def from_file_path(
config.presets.dict[FILE_PRESET_APPLY_KEY] = file_preset.dict

subscriptions_dict: Dict[str, Any] = {
key: obj
for key, obj in subscription_dict.items()
if key not in [FILE_PRESET_APPLY_KEY, FILE_SUBSCRIPTION_VALUE_KEY]
key: obj for key, obj in subscription_dict.items() if key not in [FILE_PRESET_APPLY_KEY]
}

subscriptions_dicts = SubscriptionValidator(
Expand All @@ -149,7 +117,6 @@ def from_file_path(
config=config,
presets=[],
indent_overrides=[],
subscription_value=file_subscription_value,
).subscription_dicts(
global_presets_to_apply=[FILE_PRESET_APPLY_KEY] if has_file_preset else []
)
Expand Down
8 changes: 0 additions & 8 deletions src/ytdl_sub/subscriptions/subscription_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def __init__(
config: ConfigFile,
presets: List[str],
indent_overrides: List[str],
subscription_value: Optional[str],
):
super().__init__(
name=name,
Expand All @@ -129,10 +128,6 @@ def __init__(
presets=presets,
indent_overrides=indent_overrides,
)

# TODO: Eventually delete in favor of {subscription_value}
if subscription_value:
self._overrides_to_add[subscription_value] = self.value
self._overrides_to_add[SUBSCRIPTION_VALUE] = self.value


Expand Down Expand Up @@ -234,7 +229,6 @@ def __init__(
config: ConfigFile,
presets: List[str],
indent_overrides: List[str],
subscription_value: Optional[str],
):
super().__init__(name=name, value=value, presets=presets, indent_overrides=indent_overrides)
self._children: List[SubscriptionOutput] = []
Expand All @@ -252,7 +246,6 @@ def __init__(
config=config,
presets=presets,
indent_overrides=indent_overrides,
subscription_value=subscription_value,
)
)
# Subscription defined as
Expand Down Expand Up @@ -294,7 +287,6 @@ def __init__(
config=config,
presets=presets + preset_indent_key.presets,
indent_overrides=indent_overrides + preset_indent_key.indent_overrides,
subscription_value=subscription_value,
)
)
else:
Expand Down
2 changes: 0 additions & 2 deletions src/ytdl_sub/subscriptions/utils.py

This file was deleted.

Loading

0 comments on commit 1375a0f

Please sign in to comment.