From 5a4631fa22977011bc3efcf02c9d0c5456fbe2c3 Mon Sep 17 00:00:00 2001 From: Georg Krause Date: Sun, 6 Feb 2022 11:59:20 +0100 Subject: [PATCH] Lint codebase and add CI job --- .gitlab-ci.yml | 11 +++++++++++ mopidy_funkwhale/client.py | 8 ++++++-- mopidy_funkwhale/library.py | 6 ++++-- setup.cfg | 3 +++ setup.py | 11 +++++++---- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49bc5cf..401ffc2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,19 @@ stages: + - lint - test - build - publish +lint: + stage: lint + image: python:3.10 + before_script: + - pip install .[lint] + script: + - black . + tags: + - docker + test: stage: test image: python:3 diff --git a/mopidy_funkwhale/client.py b/mopidy_funkwhale/client.py index a32dbd2..930a8c0 100644 --- a/mopidy_funkwhale/client.py +++ b/mopidy_funkwhale/client.py @@ -78,7 +78,9 @@ class APIClient(object): ) self.session.verify = config["funkwhale"].get("verify_cert", True) - self.exclude_compilation_artists = self.config["funkwhale"].get("exclude_compilation_artists", True) + self.exclude_compilation_artists = self.config["funkwhale"].get( + "exclude_compilation_artists", True + ) @property def use_oauth(self): @@ -151,7 +153,9 @@ def get_token(config): return None try: token_data = json.loads(raw) - token_data["expires_in"] = token_data["expires_at"] - datetime.timestamp(datetime.now()) + token_data["expires_in"] = token_data["expires_at"] - datetime.timestamp( + datetime.now() + ) return token_data except (TypeError, ValueError): logger.error("Cannot decode token data, you may need to relogin") diff --git a/mopidy_funkwhale/library.py b/mopidy_funkwhale/library.py index 041c133..cd3187f 100644 --- a/mopidy_funkwhale/library.py +++ b/mopidy_funkwhale/library.py @@ -293,7 +293,7 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider): logger.debug("Handling libraries route: %s", remaining) payload = self.backend.client.list_libraries( - {"ordering": "name", "page_size": 50} + {"ordering": "name", "page_size": 50} ) uri_prefix = "funkwhale:directory:artists:by-library" libraries = [ @@ -378,7 +378,9 @@ class FunkwhaleLibraryProvider(backend.LibraryProvider): client = self.backend.client config = { "track": lambda id: [client.get_track(id)], - "album": lambda id: client.list_tracks({"album": id, "ordering": "position"})["results"], + "album": lambda id: client.list_tracks( + {"album": id, "ordering": "position"} + )["results"], "artist": lambda id: client.list_tracks({"artist": id})["results"], } diff --git a/setup.cfg b/setup.cfg index 19ef8c2..6e29800 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,9 @@ mopidy.ext = funkwhale = mopidy_funkwhale:Extension [options.extras_require] +lint = + black + test = pytest pytest-cov diff --git a/setup.py b/setup.py index 3938606..bf95d78 100644 --- a/setup.py +++ b/setup.py @@ -4,24 +4,27 @@ import codecs import os from setuptools import setup + def read(rel_path): here = os.path.abspath(os.path.dirname(__file__)) - with codecs.open(os.path.join(here, rel_path), 'r') as fp: + with codecs.open(os.path.join(here, rel_path), "r") as fp: return fp.read() + def get_version(): - tag = os.getenv('CI_COMMIT_TAG', None) + tag = os.getenv("CI_COMMIT_TAG", None) if tag: return tag for line in read("mopidy_funkwhale/__init__.py").splitlines(): - if line.startswith('__version__'): + if line.startswith("__version__"): delim = '"' if '"' in line else "'" version = line.split(delim)[1] - iid = os.getenv('CI_PIPELINE_IID', 0) + iid = os.getenv("CI_PIPELINE_IID", 0) return "{}.dev{}".format(version, iid) raise RuntimeError("Unable to find version string.") + setup( version=get_version(), )