Lint codebase and add CI job

main
Georg Krause 2022-02-06 11:59:20 +01:00
parent 9c9d3927bb
commit 5a4631fa22
No known key found for this signature in database
GPG Key ID: FD479B9A4D48E632
5 changed files with 31 additions and 8 deletions

View File

@ -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

View File

@ -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")

View File

@ -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"],
}

View File

@ -28,6 +28,9 @@ mopidy.ext =
funkwhale = mopidy_funkwhale:Extension
[options.extras_require]
lint =
black
test =
pytest
pytest-cov

View File

@ -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(),
)