From: Marcel van der Veldt Date: Tue, 5 Apr 2022 10:13:36 +0000 (+0200) Subject: fix python3.9 compatibility X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=889081a668eff9bb8a88c2e279338f2dbd00488b;p=music-assistant-server.git fix python3.9 compatibility --- diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c392e6ed..8514e504 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Test with Pre-commit and Tox +name: Test with Pre-commit on: push: @@ -24,11 +24,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get install -y --no-install-recommends libsndfile1 libtag1v5 libtag1-dev python -m pip install --upgrade pip - pip install tox tox-gh-actions pre-commit + pip install pre-commit pre-commit install-hooks - - name: Lint with pre-commit + - name: Lint/test with pre-commit run: pre-commit run --all-files - - name: Test with tox - run: tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2326ddea..f538b161 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,3 +25,13 @@ repos: - id: mypy additional_dependencies: [types-all] exclude: ^examples/ + - repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: ["-rn", "-sn", "--rcfile=pylintrc", "--fail-on=I"] + exclude: ^examples/|^.venv/|^.vscode/ + diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index 3e9ffe30..a908fbdc 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -1,4 +1,5 @@ """Various helpers for audio manipulation.""" +from __future__ import annotations import asyncio import logging diff --git a/music_assistant/helpers/cache.py b/music_assistant/helpers/cache.py index 404b016d..a6444708 100644 --- a/music_assistant/helpers/cache.py +++ b/music_assistant/helpers/cache.py @@ -1,4 +1,5 @@ """Provides a simple stateless caching system.""" +from __future__ import annotations import asyncio import functools diff --git a/music_assistant/helpers/compare.py b/music_assistant/helpers/compare.py index c86f670e..55a7ff29 100644 --- a/music_assistant/helpers/compare.py +++ b/music_assistant/helpers/compare.py @@ -1,4 +1,6 @@ """Several helper/utils to compare objects.""" +from __future__ import annotations + import re from typing import TYPE_CHECKING, List diff --git a/music_assistant/helpers/datetime.py b/music_assistant/helpers/datetime.py index 3373c0bf..402e833f 100644 --- a/music_assistant/helpers/datetime.py +++ b/music_assistant/helpers/datetime.py @@ -1,4 +1,5 @@ """Helpers for date and time.""" +from __future__ import annotations import datetime diff --git a/music_assistant/helpers/images.py b/music_assistant/helpers/images.py index fe0d691e..c6b92207 100644 --- a/music_assistant/helpers/images.py +++ b/music_assistant/helpers/images.py @@ -1,4 +1,5 @@ """Utilities for image manipulation and retrieval.""" +from __future__ import annotations from io import BytesIO diff --git a/music_assistant/helpers/json.py b/music_assistant/helpers/json.py index 4a3b1a37..7065cc5b 100644 --- a/music_assistant/helpers/json.py +++ b/music_assistant/helpers/json.py @@ -1,4 +1,5 @@ """Various helpers for web requests.""" +from __future__ import annotations import asyncio diff --git a/music_assistant/helpers/process.py b/music_assistant/helpers/process.py index eed32d62..76979dc2 100644 --- a/music_assistant/helpers/process.py +++ b/music_assistant/helpers/process.py @@ -4,6 +4,7 @@ Implementation of a (truly) non blocking subprocess. The subprocess implementation in asyncio can (still) sometimes cause deadlocks, even when properly handling reading/writes from different tasks. """ +from __future__ import annotations import asyncio import logging diff --git a/music_assistant/helpers/typing.py b/music_assistant/helpers/typing.py index 0debc056..1caf05f9 100644 --- a/music_assistant/helpers/typing.py +++ b/music_assistant/helpers/typing.py @@ -1,4 +1,5 @@ """Typing helper.""" +from __future__ import annotations from typing import TYPE_CHECKING, Any, List, Optional diff --git a/music_assistant/helpers/util.py b/music_assistant/helpers/util.py index 6743b733..43a59913 100755 --- a/music_assistant/helpers/util.py +++ b/music_assistant/helpers/util.py @@ -1,4 +1,6 @@ """Helper and utility functions.""" +from __future__ import annotations + import asyncio import functools import os diff --git a/music_assistant/providers/qobuz.py b/music_assistant/providers/qobuz.py index 669949e7..5432de93 100644 --- a/music_assistant/providers/qobuz.py +++ b/music_assistant/providers/qobuz.py @@ -1,4 +1,5 @@ """Qobuz musicprovider support for MusicAssistant.""" +from __future__ import annotations import datetime import hashlib diff --git a/music_assistant/providers/spotify/__init__.py b/music_assistant/providers/spotify/__init__.py index 68cc568a..1c343f02 100644 --- a/music_assistant/providers/spotify/__init__.py +++ b/music_assistant/providers/spotify/__init__.py @@ -1,4 +1,6 @@ """Spotify musicprovider support for MusicAssistant.""" +from __future__ import annotations + import asyncio import json import os diff --git a/music_assistant/providers/tunein.py b/music_assistant/providers/tunein.py index d5496ac7..f392aa4e 100644 --- a/music_assistant/providers/tunein.py +++ b/music_assistant/providers/tunein.py @@ -1,4 +1,6 @@ """Tune-In musicprovider support for MusicAssistant.""" +from __future__ import annotations + from typing import List, Optional from asyncio_throttle import Throttler diff --git a/pylintrc b/pylintrc new file mode 100644 index 00000000..0b60c452 --- /dev/null +++ b/pylintrc @@ -0,0 +1,69 @@ +[MASTER] +ignore=tests +ignore-patterns=app_vars +# Use a conservative default here; 2 should speed up most setups and not hurt +# any too bad. Override on command line as appropriate. +jobs=2 +persistent=no +suggestion-mode=yes +extension-pkg-whitelist=taglib + +[BASIC] +good-names=id,i,j,k,ex,Run,_,fp,T,ev + +[MESSAGES CONTROL] +# Reasons disabled: +# format - handled by black +# locally-disabled - it spams too much +# duplicate-code - unavoidable +# cyclic-import - doesn't test if both import on load +# abstract-class-little-used - prevents from setting right foundation +# unused-argument - generic callbacks and setup methods create a lot of warnings +# too-many-* - are not enforced for the sake of readability +# too-few-* - same as too-many-* +# abstract-method - with intro of async there are always methods missing +# inconsistent-return-statements - doesn't handle raise +# too-many-ancestors - it's too strict. +# wrong-import-order - isort guards this +# fixme - project is in development phase +disable= + format, + abstract-class-little-used, + abstract-method, + cyclic-import, + duplicate-code, + inconsistent-return-statements, + locally-disabled, + not-context-manager, + too-few-public-methods, + too-many-ancestors, + too-many-arguments, + too-many-branches, + too-many-instance-attributes, + too-many-lines, + too-many-locals, + too-many-public-methods, + too-many-return-statements, + too-many-statements, + too-many-boolean-expressions, + unused-argument, + wrong-import-order, + fixme +# enable useless-suppression temporarily every now and then to clean them up +enable= + use-symbolic-message-instead + +[REPORTS] +score=no + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=15 + +[TYPECHECK] +# For attrs +ignored-classes=_CountingAttr + +[FORMAT] +expected-line-ending-format=LF \ No newline at end of file diff --git a/setup.py b/setup.py index addbe2be..e05b2d05 100644 --- a/setup.py +++ b/setup.py @@ -28,15 +28,13 @@ PROJECT_URLS = { } PROJECT_DIR = Path(__file__).parent.resolve() README_FILE = PROJECT_DIR / "README.rst" +REQUIREMENTS_FILE = PROJECT_DIR / "requirements.txt" PACKAGES = find_packages(exclude=["tests", "tests.*"]) PACKAGE_FILES = [] for (path, directories, filenames) in os.walk("music_assistant/"): for filename in filenames: PACKAGE_FILES.append(os.path.join("..", path, filename)) -with open("requirements.txt") as f: - REQUIRES = f.read().splitlines() - setup( name=PROJECT_PACKAGE_NAME, version=PROJECT_VERSION, @@ -50,7 +48,7 @@ setup( packages=PACKAGES, include_package_data=True, zip_safe=False, - install_requires=REQUIRES, + install_requires=REQUIREMENTS_FILE.read_text(encoding="utf-8"), python_requires=f">={PROJECT_REQ_PYTHON_VERSION}", test_suite="tests", entry_points={ diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 41bc3bf1..00000000 --- a/tox.ini +++ /dev/null @@ -1,28 +0,0 @@ -[tox] -envlist = py39, py310, lint, mypy -skip_missing_interpreters = True - -[gh-actions] -python = - 3.9: py39, lint, mypy - 3.10: py310 - -[testenv:lint] -basepython = python3 -ignore_errors = True -commands = - black --check ./ - flake8 music_assistant tests - pylint music_assistant tests - pydocstyle music_assistant tests -deps = - -rrequirements_lint.txt - -rrequirements_test.txt - -[testenv:mypy] -basepython = python3 -ignore_errors = True -commands = - mypy music_assistant -deps = - -rrequirements_lint.txt \ No newline at end of file