Verified Commit d17ceec1 authored by Agate's avatar Agate 💬
Browse files

See #297: linting of various, uncommon errors

parent ab80dffe
from django.conf.urls import include, url
from dynamic_preferences.api.viewsets import GlobalPreferencesViewSet
from dynamic_preferences.users.viewsets import UserPreferencesViewSet
from rest_framework import routers
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework_jwt import views as jwt_views
from funkwhale_api.activity import views as activity_views
from funkwhale_api.instance import views as instance_views
from funkwhale_api.music import views
from funkwhale_api.playlists import views as playlists_views
from funkwhale_api.subsonic.views import SubsonicViewSet
......
......@@ -2,7 +2,7 @@ import os
import django
from .routing import application
from .routing import application # noqa
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
......
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.conf.urls import url
......
......@@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/dev/ref/settings/
from __future__ import absolute_import, unicode_literals
import datetime
import os
from urllib.parse import urlparse, urlsplit
import environ
......@@ -23,7 +22,6 @@ ROOT_DIR = environ.Path(__file__) - 3 # (/a/b/myfile.py - 3 = /)
APPS_DIR = ROOT_DIR.path("funkwhale_api")
env = environ.Env()
try:
env.read_env(ROOT_DIR.file(".env"))
except FileNotFoundError:
......@@ -333,12 +331,12 @@ CACHES["default"]["OPTIONS"] = {
}
########## CELERY
# CELERY
INSTALLED_APPS += ("funkwhale_api.taskapp.celery.CeleryConfig",)
CELERY_BROKER_URL = env(
"CELERY_BROKER_URL", default=env("CACHE_URL", default=CACHE_DEFAULT)
)
########## END CELERY
# END CELERY
# Location of root django.contrib.admin URL, use {% url 'admin:index' %}
# Your common stuff: Below this line define 3rd party library settings
......
......@@ -10,6 +10,7 @@ Local settings
from .common import * # noqa
# DEBUG
# ------------------------------------------------------------------------------
DEBUG = env.bool("DJANGO_DEBUG", default=True)
......@@ -49,10 +50,10 @@ INSTALLED_APPS += ("debug_toolbar",)
# ------------------------------------------------------------------------------
TEST_RUNNER = "django.test.runner.DiscoverRunner"
########## CELERY
# CELERY
# In development, all tasks will be executed locally by blocking until the task returns
CELERY_TASK_ALWAYS_EAGER = False
########## END CELERY
# END CELERY
# Your local stuff: Below this line define 3rd party library settings
......
......@@ -11,8 +11,6 @@ Production Configurations
"""
from __future__ import absolute_import, unicode_literals
from django.utils import six
from .common import * # noqa
# SECRET CONFIGURATION
......
......@@ -6,7 +6,6 @@ from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views import defaults as default_views
from django.views.generic import TemplateView
urlpatterns = [
# Django Admin, use {% url 'admin:index' %}
......
......@@ -35,7 +35,7 @@ def get_actor_data(actor_url):
response.raise_for_status()
try:
return response.json()
except:
except Exception:
raise ValueError("Invalid actor payload: {}".format(response.text))
......
......@@ -334,7 +334,7 @@ class FollowSerializer(serializers.Serializer):
return models.Follow.objects.get_or_create(
actor=self.validated_data["actor"],
target=self.validated_data["object"],
**kwargs,
**kwargs, # noqa
)[0]
def to_representation(self, instance):
......@@ -345,7 +345,6 @@ class FollowSerializer(serializers.Serializer):
"object": instance.target.url,
"type": "Follow",
}
return ret
class APIFollowSerializer(serializers.ModelSerializer):
......
from django import forms
from django.core import paginator
from django.db import transaction
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from django.urls import reverse
from rest_framework import mixins, response, viewsets
from rest_framework.decorators import detail_route, list_route
......@@ -144,7 +144,7 @@ class MusicFilesViewSet(FederationMixin, viewsets.GenericViewSet):
else:
try:
page_number = int(page)
except:
except Exception:
return response.Response({"page": ["Invalid page number"]}, status=400)
p = paginator.Paginator(
qs, preferences.get("federation__collection_page_size")
......
......@@ -259,13 +259,13 @@ class Work(APIModelMixin):
import_hooks = [import_lyrics, link_recordings]
def fetch_lyrics(self):
l = self.lyrics.first()
if l:
return l
lyric = self.lyrics.first()
if lyric:
return lyric
data = self.api.get(self.mbid, includes=["url-rels"])["work"]
l = import_lyrics(self, {}, data)
lyric = import_lyrics(self, {}, data)
return l
return lyric
class Lyrics(models.Model):
......@@ -606,7 +606,7 @@ def update_request_status(sender, instance, created, **kwargs):
if not instance.import_request:
return
if not created and not "status" in update_fields:
if not created and "status" not in update_fields:
return
r_status = instance.import_request.status
......
......@@ -256,7 +256,7 @@ def import_job_run(self, import_job, replace=False, use_acoustid=False):
if not settings.DEBUG:
try:
self.retry(exc=exc, countdown=30, max_retries=3)
except:
except Exception:
mark_errored(exc)
raise
mark_errored(exc)
......
......@@ -4,7 +4,7 @@ import urllib
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db import models, transaction
from django.db import transaction
from django.db.models import Count
from django.db.models.functions import Length
from django.utils import timezone
......
import os
import acoustid
from django.core.files import File
from django.db import transaction
from funkwhale_api.music import metadata, models
from funkwhale_api.providers.acoustid import get_acoustid_client
from funkwhale_api.taskapp import celery
@transaction.atomic
......@@ -49,33 +43,3 @@ def import_track_data_from_path(path):
defaults={"title": data.get("title"), "position": position},
)[0]
return track
def import_metadata_with_musicbrainz(path):
pass
@celery.app.task(name="audiofile.from_path")
def from_path(path):
acoustid_track_id = None
try:
client = get_acoustid_client()
result = client.get_best_match(path)
acoustid_track_id = result["id"]
except acoustid.WebServiceError:
track = import_track_data_from_path(path)
except (TypeError, KeyError):
track = import_metadata_without_musicbrainz(path)
else:
track, created = models.Track.get_or_create_from_api(
mbid=result["recordings"][0]["id"]
)
if track.files.count() > 0:
raise ValueError("File already exists for track {}".format(track.pk))
track_file = models.TrackFile(track=track, acoustid_track_id=acoustid_track_id)
track_file.audio_file.save(os.path.basename(path), File(open(path, "rb")))
track_file.save()
return track_file
......@@ -24,7 +24,7 @@ class RadioSessionFactory(factory.django.DjangoModelFactory):
@registry.register(name="radios.CustomRadioSession")
class RadioSessionFactory(factory.django.DjangoModelFactory):
class CustomRadioSessionFactory(factory.django.DjangoModelFactory):
user = factory.SubFactory(UserFactory)
radio_type = "custom"
custom_radio = factory.SubFactory(
......
......@@ -175,7 +175,6 @@ class TagFilter(RadioFilter):
"type": "list",
"subtype": "string",
"autocomplete": reverse_lazy("api:v1:tags-list"),
"autocomplete_qs": "",
"autocomplete_fields": {
"remoteValues": "results",
"name": "name",
......
......@@ -456,6 +456,6 @@ class SubsonicViewSet(viewsets.GenericViewSet):
{"error": {"code": 0, "message": "Invalid payload"}}
)
if serializer.validated_data["submission"]:
l = serializer.save()
record.send(l)
listening = serializer.save()
record.send(listening)
return response.Response({})
......@@ -90,7 +90,8 @@ class User(AbstractUser):
perms[p] = v
return perms
def has_permissions(self, *perms, operator="and"):
def has_permissions(self, *perms, **kwargs):
operator = kwargs.pop("operator", "and")
if operator not in ["and", "or"]:
raise ValueError("Invalid operator {}".format(operator))
permissions = self.get_permissions()
......
[flake8]
max-line-length = 120
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,tests/data,tests/music/conftest.py
ignore = F405,W503,E203
[isort]
skip_glob = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
......
search = {}
......@@ -13,7 +11,7 @@ search["8 bit adventure"] = {
"etag": '"gMxXHe-zinKdE9lTnzKu8vjcmDI/GxK-wHBWUYfrJsd1dijBPTufrVE"',
"snippet": {
"liveBroadcastContent": "none",
"description": "Make sure to apply adhesive evenly before use. GET IT HERE: http://adhesivewombat.bandcamp.com/album/marsupial-madness Facebook: ...",
"description": "Description",
"channelId": "UCps63j3krzAG4OyXeEyuhFw",
"title": "AdhesiveWombat - 8 Bit Adventure",
"channelTitle": "AdhesiveWombat",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment