Skip to content

Commit

Permalink
chore: merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
marksie1988 committed Apr 17, 2023
2 parents 22c9099 + 4ff6086 commit e4db8ea
Show file tree
Hide file tree
Showing 10 changed files with 1,295 additions and 1,237 deletions.
26 changes: 9 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,13 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install Poetry
uses: snok/[email protected]
- name: Cache Poetry virtualenv
uses: actions/cache@v1
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
run: poetry install
if: steps.cache.outputs.cache-hit != 'true'
- name: Build
run: poetry build
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry nox
- name: Publish distribution 📦 to PyPI
run: poetry publish -u __token__ -p ${{ secrets.pypi_password }}
run: |
nox -rs release -- "$PYPI_PASSWORD"
env:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
9 changes: 9 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ def test_style(session: Session) -> None:
session.run("interrogate", "pyarr")


@nox.session(reuse_venv=True)
def release(session: Session) -> None:
"""Release a new version of the package"""
pypi_password = session.posargs[0]
session.run("poetry", "install", external=True)
session.run("poetry", "build", external=True)
session.run("poetry", "publish", "-u", "__token__", "-p", pypi_password)


@nox.session(reuse_venv=True)
def docs(session: Session) -> None:
"""Create local copy of docs for testing"""
Expand Down
2,430 changes: 1,215 additions & 1,215 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyarr/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ class PyarrMissingArgument(PyarrError):

class PyarrBadRequest(PyarrError):
"""Bad Request, possible bug."""


class PyarrServerError(PyarrError):
"""Server Error, missing or incorrect options."""

def __init__(self, message, response):
super().__init__(message)
self.response = response
9 changes: 8 additions & 1 deletion pyarr/lidarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ def add_album(
quality_profile_id: Optional[int] = None,
metadata_profile_id: Optional[int] = None,
monitored: bool = True,
artist_monitored: bool = True,
artist_monitor: LidarrArtistMonitor = "all",
artist_search_for_missing_albums: bool = False,
search_for_new_album: bool = False,
) -> JsonObject:
"""Adds an album to Lidarr
Expand All @@ -246,8 +248,10 @@ def add_album(
quality_profile_id (Optional[int], optional): Quality profile ID. Defaults to None.
metadata_profile_id (Optional[int], optional): Metadata profile ID. Defaults to None.
monitored (bool, optional): Should the album be monitored. Defaults to True.
artist_monitored (bool, optional): Should the album be monitored. Defaults to True.
artist_monitor (LidarrArtistMonitor, optional): What level to monitor the artist. Defaults to "all".
artist_search_for_missing_albums (bool, optional): Search for any missing albums by this artist. Defaults to False.
search_for_new_album (bool, optional): Search for new albums by this artist. Defaults to False.
Returns:
JsonObject: Dictionary with added record
Expand All @@ -267,15 +271,18 @@ def add_album(
"There is no Metadata Profile setup"
) from exception

album["id"] = 0
album["artist"]["metadataProfileId"] = metadata_profile_id
album["artist"]["qualityProfileId"] = quality_profile_id
album["artist"]["rootFolderPath"] = root_dir
album["artist"]["monitored"] = artist_monitored
album["artist"]["addOptions"] = {
"monitor": artist_monitor,
"searchForMissingAlbums": artist_search_for_missing_albums,
}
album["monitored"] = monitored
album["addOptions"] = {
"searchForNewAlbum": search_for_new_album,
}
return self._post("album", self.ver_uri, data=album)

def upd_album(self, data: JsonObject) -> JsonObject:
Expand Down
11 changes: 9 additions & 2 deletions pyarr/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PyarrConnectionError,
PyarrMethodNotAllowed,
PyarrResourceNotFound,
PyarrServerError,
PyarrUnauthorizedError,
)
from .types import _ReturnType
Expand Down Expand Up @@ -241,11 +242,17 @@ def _process_response(
)
if res.status_code == 404:
raise PyarrResourceNotFound("Resource not found")
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible")
if res.status_code == 405:
raise PyarrMethodNotAllowed(f"The endpoint {res.url} is not allowed")
if res.status_code == 500:
raise PyarrServerError(
f"Internal Server Error: {res.json()['message']}",
res.json(),
)
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible.")

print(res.status_code)
content_type = res.headers.get("Content-Type", "")
if "application/json" in content_type:
return res.json()
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyarr"
version = "4.2.0"
version = "5.1.0"
description = "Synchronous Sonarr, Radarr, Lidarr and Readarr API's for Python"
authors = ["Steven Marks <[email protected]>"]
license = "MIT"
Expand All @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries :: Python Modules"
]
packages = [
Expand Down Expand Up @@ -52,6 +53,7 @@ sphinx-toolbox = "^3.4.0"
enum-tools = "^0.9.0.post1"
pytest-rerunfailures = "^11.1.2"
nox = "^2022.11.21"
toml = "^0.10.2"

[tool.black]
line-length = 88
Expand Down
11 changes: 10 additions & 1 deletion sphinx-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import re
import sys

import toml

path = dirname(dirname(abspath(__file__)))
sys.path.append(path)
sys.path.append(join(path, "pyarr"))
Expand All @@ -13,8 +15,15 @@
copyright = "2021, Steven Marks, TotalDebug"
author = "Steven Marks, TotalDebug"


# The short X.Y version
version = "2.0"
def get_version():
with open("../pyproject.toml") as f:
config = toml.load(f)
return config["tool"]["poetry"]["version"]


version = get_version()
# The full version, including alpha/beta/rc tags
release = ""

Expand Down
2 changes: 2 additions & 0 deletions sphinx-docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sphinx_rtd_theme>=^1.2.0
toml>=^0.10.2
myst-parser>=^1.0.0
22 changes: 22 additions & 0 deletions tests/test_lidarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ def test_add_album(lidarr_client: LidarrAPI):
assert False

assert isinstance(data, dict)
assert data["title"] == "Wicked Words & Epic Tales: A Narrative Landscape"

items = lidarr_client.lookup(LIDARR_ALBUM_TERM)

for item in items:
if "album" in item:
album = item["album"]
data = lidarr_client.add_album(
album=album,
root_dir="/defaults/",
quality_profile_id=qual_profile[0]["id"],
metadata_profile_id=meta_profile[0]["id"],
monitored=False,
artist_monitor="latest",
artist_search_for_missing_albums=False,
)
break
if item == items[-1]:
assert False

assert isinstance(data, dict)
assert data["title"] == "DAWN"


def test_upd_album(lidarr_client: LidarrAPI):
Expand Down

0 comments on commit e4db8ea

Please sign in to comment.