Skip to content

Commit

Permalink
modernize with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhoherd committed Nov 19, 2024
1 parent b53cc8a commit b3dd1cb
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 505 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

47 changes: 9 additions & 38 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
---
exclude: "(venv|.vscode)" # regex
repos:
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: text-unicode-replacement-char
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
- id: prettier
args: ["--print-width=135"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.4.10"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.4"
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
args:
- "--fix"
- "--exit-non-zero-on-fix"
- "--unsafe-fixes"
- id: ruff-format
- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
rev: 1.7.10
hooks:
- id: bandit
args: ["-s", "B101"]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-byte-order-marker
- id: check-case-conflict
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ clean: ## Delete build artifacts

.PHONY: poetry-clean
poetry-clean: ## Delete poetry virtualenv
poetry env list 2>/dev/null | awk '{print $$1}' | xargs -n1 poetry env remove || true
poetry env remove --all
rm -fv .requirements

.PHONY: wheel
Expand All @@ -53,21 +53,17 @@ wheel: ## Build a wheel

.PHONY: test
test: ## Run tests
tox
poetry run pytest tests

.PHONY: requirements-dev
requirements-dev: .requirements-dev ## Install dev requirements
.requirements-dev:
pip3 install --user --upgrade poetry
poetry run pip install --quiet --upgrade pip setuptools wheel
poetry install
touch .requirements-dev .requirements

.PHONY: requirements
requirements: .requirements ## Install requirements
.requirements:
pip3 install --user --upgrade poetry
poetry run pip install --quiet --upgrade pip setuptools wheel
poetry install --no-dev
touch .requirements

Expand Down
15 changes: 1 addition & 14 deletions plexdl/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""plexdl CLI."""

import datetime
import logging
import sys

import humanize
Expand All @@ -15,24 +14,13 @@

from plexdl.plexdl import Client


def get_logger(ctx, param, value):
"""Get logger and return verbosity value."""
logging.basicConfig(format="%(message)s")
log = logging.getLogger("plexdl")
if value > 0:
log.setLevel("DEBUG") # https://docs.python.org/3.9/library/logging.html#logging-levels
return value


app = typer.Typer(help=__doc__, context_settings={"max_content_width": 9999})


@app.command()
def get_server_info(
username: str = typer.Argument(None, envvar="PLEXDL_USERNAME"),
password: str = typer.Argument(None, envvar="PLEXDL_PASSWORD"),
debug: bool = typer.Argument(False, envvar="PLEXDL_DEBUG"),
):
"""Show info about servers available to your account."""
p = MyPlexAccount(
Expand Down Expand Up @@ -73,7 +61,7 @@ def get_server_info(
print(f" publicAddressMatches: {server.publicAddressMatches}")
print(f" sourceTitle: {server.sourceTitle}")
print(f" synced: {server.synced}")
print("")
print()


@app.command()
Expand All @@ -86,7 +74,6 @@ def search(
show_ratings: bool = typer.Option(False, "--show-ratings", help="Show ratings for each result"),
show_metadata: bool = typer.Option(False, "--show-metadata", help="Show file and codec metadata for each file in each result"),
include_relays: bool = typer.Option(False, "--include-relays", help="Output relay servers along with direct servers"),
verbose: bool = typer.Option(False, "--verbose", "-v"),
debug: bool = typer.Option(False, "--debug"),
):
"""Search for media in servers that are available to your account."""
Expand Down
7 changes: 3 additions & 4 deletions plexdl/plexdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import locale
import logging
from typing import List
from typing import ClassVar

import humanfriendly
import requests
Expand All @@ -29,7 +29,7 @@ def __init__(self, **kwargs):
self.username = kwargs["username"]
self.account = MyPlexAccount(self.username, self.password)

available_servers: List[PlexServer] = []
available_servers: ClassVar[list[PlexServer]] = []

@staticmethod
def print_item_info(self, item, access_token):
Expand Down Expand Up @@ -110,8 +110,7 @@ def main(self):
if self.relay is False:
log.debug(f"Skipping {this_server_connection.friendlyName} relay")
continue
else:
relay_status = " (relay)"
relay_status = " (relay)"
print("\n")
print("=" * 79)
print(f'Server: "{this_server_connection.friendlyName}"{relay_status}')
Expand Down
Loading

0 comments on commit b3dd1cb

Please sign in to comment.