Skip to content
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 .github/workflows/test-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]

env:
COVERAGE_TOTAL: 100
Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ keywords = [
"Reddit",
"Audio",
]
requires-python=">=3.9"
requires-python=">=3.10"
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -30,7 +30,6 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -50,7 +49,7 @@ dependencies = [
"python-dateutil",
"PyYAML",
"requests",
"spotipy",
"spotify-tools",
"tqdm",
"youtube-dl"
]
Expand Down Expand Up @@ -89,6 +88,12 @@ djtools = "djtools:main"
[tool.uv]
default-groups = ["dev"]

[tool.uv.sources]
spotify-tools = { path = "vendor/spotify_tools-0.0.1-py3-none-any.whl" }

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/djtools"]

Expand Down
60 changes: 6 additions & 54 deletions src/djtools/spotify/config.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,21 @@
"""This module contains the configuration object for the spotify package.
"""Configuration object for the spotify package.

The attributes of this configuration object correspond with the "spotify" key
of config.yaml
of config.yaml.
"""

import logging
from enum import Enum
from typing import List

from pydantic import BaseModel, NonNegativeInt
import yaml

from djtools.configs.config_formatter import BaseConfigFormatter
from djtools.spotify.enums import SubredditPeriod, SubredditType


logger = logging.getLogger(__name__)


class SubredditPeriod(Enum):
# pylint: disable=missing-class-docstring
ALL = "all"
DAY = "day"
HOUR = "hour"
MONTH = "month"
WEEK = "week"
YEAR = "year"


def subreddit_period_representer(dumper, data):
# pylint: disable=missing-function-docstring
return dumper.represent_scalar("!SubredditPeriod", data.value)


def subreddit_period_constructor(loader, node):
# pylint: disable=missing-function-docstring
return SubredditPeriod(loader.construct_scalar(node))


yaml.add_representer(SubredditPeriod, subreddit_period_representer)
yaml.add_constructor("!SubredditPeriod", subreddit_period_constructor)


class SubredditType(Enum):
# pylint: disable=missing-class-docstring
CONTROVERSIAL = "controversial"
HOT = "hot"
NEW = "new"
RISING = "rising"
TOP = "top"


def subreddit_type_representer(dumper, data):
# pylint: disable=missing-function-docstring
return dumper.represent_scalar("!SubredditType", data.value)


def subreddit_type_constructor(loader, node):
# pylint: disable=missing-function-docstring
return SubredditType(loader.construct_scalar(node))


yaml.add_representer(SubredditType, subreddit_type_representer)
yaml.add_constructor("!SubredditType", subreddit_type_constructor)


class SubredditConfig(BaseModel):
"""Configuration object for spotify_playlists."""

Expand Down Expand Up @@ -95,8 +48,7 @@ def __init__(self, *args, **kwargs):
"""Constructor.

Raises:
RuntimeError: Spotify API credentials must exit.
RuntimeError: Spotify API credentials must be valid.
RuntimeError: Spotify API credentials must exist and be valid.
RuntimeError: Reddit API credentials must exist.
"""
super().__init__(*args, **kwargs)
Expand All @@ -117,8 +69,8 @@ def __init__(self, *args, **kwargs):
"spotify_username set to valid values, you cannot use "
"spotify_playlists or spotify_playlist_from_upload"
)

if self.spotify_playlists or self.spotify_playlist_from_upload:
# pylint: disable=cyclic-import
from djtools.spotify.helpers import get_spotify_client

spotify = get_spotify_client(self)
Expand Down
58 changes: 58 additions & 0 deletions src/djtools/spotify/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Enumerations for the spotify package.

This module contains enum types used by the spotify config and helpers
to avoid cyclic imports.
"""

from enum import Enum

import yaml


class SubredditPeriod(Enum):
"""Time period for subreddit queries."""

ALL = "all"
DAY = "day"
HOUR = "hour"
MONTH = "month"
WEEK = "week"
YEAR = "year"


def subreddit_period_representer(dumper, data):
"""YAML representer for SubredditPeriod."""
return dumper.represent_scalar("!SubredditPeriod", data.value)


def subreddit_period_constructor(loader, node):
"""YAML constructor for SubredditPeriod."""
return SubredditPeriod(loader.construct_scalar(node))


yaml.add_representer(SubredditPeriod, subreddit_period_representer)
yaml.add_constructor("!SubredditPeriod", subreddit_period_constructor)


class SubredditType(Enum):
"""Type of subreddit sort."""

CONTROVERSIAL = "controversial"
HOT = "hot"
NEW = "new"
RISING = "rising"
TOP = "top"


def subreddit_type_representer(dumper, data):
"""YAML representer for SubredditType."""
return dumper.represent_scalar("!SubredditType", data.value)


def subreddit_type_constructor(loader, node):
"""YAML constructor for SubredditType."""
return SubredditType(loader.construct_scalar(node))


yaml.add_representer(SubredditType, subreddit_type_representer)
yaml.add_constructor("!SubredditType", subreddit_type_constructor)
Loading