Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Julien Veyssier
funkwhale
Commits
2b0f7f6d
Commit
2b0f7f6d
authored
Jun 10, 2018
by
Eliot Berriot
Browse files
Merge branch '297-linting' into 'develop'
Resolve "Add some linting for Python code" Closes
#297
See merge request
!242
parents
e953468e
7f5e9d64
Changes
181
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
2b0f7f6d
...
...
@@ -3,13 +3,39 @@ variables:
IMAGE
:
$IMAGE_NAME:$CI_COMMIT_REF_NAME
IMAGE_LATEST
:
$IMAGE_NAME:latest
PIP_CACHE_DIR
:
"
$CI_PROJECT_DIR/pip-cache"
PYTHONDONTWRITEBYTECODE
:
"
true"
stages
:
-
lint
-
test
-
build
-
deploy
black
:
image
:
python:3.6
stage
:
lint
variables
:
GIT_STRATEGY
:
fetch
before_script
:
-
pip install black
script
:
-
black --check --diff api/
flake8
:
image
:
python:3.6
stage
:
lint
variables
:
GIT_STRATEGY
:
fetch
before_script
:
-
pip install flake8
script
:
-
flake8 -v api
cache
:
key
:
"
$CI_PROJECT_ID__flake8_pip_cache"
paths
:
-
"
$PIP_CACHE_DIR"
test_api
:
services
:
-
postgres:9.4
...
...
@@ -108,7 +134,7 @@ pages:
tags
:
-
docker
docker_
develop
:
docker_
release
:
stage
:
deploy
before_script
:
-
docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
...
...
@@ -119,8 +145,9 @@ docker_develop:
-
docker push $IMAGE
only
:
-
develop@funkwhale/funkwhale
-
tags@funkwhale/funkwhale
tags
:
-
d
in
d
-
d
ocker-buil
d
build_api
:
# Simply publish a zip containing api/ directory
...
...
@@ -135,19 +162,3 @@ build_api:
-
tags@funkwhale/funkwhale
-
master@funkwhale/funkwhale
-
develop@funkwhale/funkwhale
docker_release
:
stage
:
deploy
before_script
:
-
docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
-
cp -r front/dist api/frontend
-
cd api
script
:
-
docker build -t $IMAGE -t $IMAGE_LATEST .
-
docker push $IMAGE
-
docker push $IMAGE_LATEST
only
:
-
tags@funkwhale/funkwhale
tags
:
-
dind
api/config/api_urls.py
View file @
2b0f7f6d
from
django.conf.urls
import
include
,
url
from
dynamic_preferences.api.viewsets
import
GlobalPreferencesViewSet
from
rest_framework
import
routers
from
rest_framework.urlpatterns
import
format_suffix_patterns
from
django.conf.urls
import
include
,
url
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
from
rest_framework_jwt
import
views
as
jwt_views
from
dynamic_preferences.api.viewsets
import
GlobalPreferencesViewSet
from
dynamic_preferences.users.viewsets
import
UserPreferencesViewSet
router
=
routers
.
SimpleRouter
()
router
.
register
(
r
"settings"
,
GlobalPreferencesViewSet
,
base_name
=
"settings"
)
...
...
api/config/asgi.py
View file @
2b0f7f6d
import
django
import
os
import
django
from
.routing
import
application
# noqa
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"config.settings.production"
)
django
.
setup
()
from
.routing
import
application
api/config/routing.py
View file @
2b0f7f6d
from
django.conf.urls
import
url
from
channels.auth
import
AuthMiddlewareStack
from
channels.routing
import
ProtocolTypeRouter
,
URLRouter
from
django.conf.urls
import
url
from
funkwhale_api.common.auth
import
TokenAuthMiddleware
from
funkwhale_api.instance
import
consumers
application
=
ProtocolTypeRouter
(
{
# Empty for now (http->django views is added by default)
...
...
api/config/settings/common.py
View file @
2b0f7f6d
...
...
@@ -10,8 +10,9 @@ https://docs.djangoproject.com/en/dev/ref/settings/
"""
from
__future__
import
absolute_import
,
unicode_literals
from
urllib.parse
import
urlsplit
import
os
import
datetime
from
urllib.parse
import
urlparse
,
urlsplit
import
environ
from
celery.schedules
import
crontab
...
...
@@ -21,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
:
...
...
@@ -315,7 +315,6 @@ CACHE_DEFAULT = "redis://127.0.0.1:6379/0"
CACHES
=
{
"default"
:
env
.
cache_url
(
"CACHE_URL"
,
default
=
CACHE_DEFAULT
)}
CACHES
[
"default"
][
"BACKEND"
]
=
"django_redis.cache.RedisCache"
from
urllib.parse
import
urlparse
cache_url
=
urlparse
(
CACHES
[
"default"
][
"LOCATION"
])
CHANNEL_LAYERS
=
{
...
...
@@ -332,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
...
...
@@ -351,8 +350,6 @@ CELERYBEAT_SCHEDULE = {
}
}
import
datetime
JWT_AUTH
=
{
"JWT_ALLOW_REFRESH"
:
True
,
"JWT_EXPIRATION_DELTA"
:
datetime
.
timedelta
(
days
=
7
),
...
...
api/config/settings/local.py
View file @
2b0f7f6d
...
...
@@ -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
...
...
api/config/settings/production.py
View file @
2b0f7f6d
...
...
@@ -11,9 +11,6 @@ Production Configurations
"""
from
__future__
import
absolute_import
,
unicode_literals
from
django.utils
import
six
from
.common
import
*
# noqa
# SECRET CONFIGURATION
...
...
api/config/urls.py
View file @
2b0f7f6d
...
...
@@ -5,7 +5,6 @@ from django.conf import settings
from
django.conf.urls
import
include
,
url
from
django.conf.urls.static
import
static
from
django.contrib
import
admin
from
django.views.generic
import
TemplateView
from
django.views
import
defaults
as
default_views
urlpatterns
=
[
...
...
api/config/wsgi.py
View file @
2b0f7f6d
...
...
@@ -15,11 +15,9 @@ framework.
"""
import
os
from
django.core.wsgi
import
get_wsgi_application
from
whitenoise.django
import
DjangoWhiteNoise
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
...
...
api/funkwhale_api/activity/views.py
View file @
2b0f7f6d
...
...
@@ -4,8 +4,7 @@ from rest_framework.response import Response
from
funkwhale_api.common.permissions
import
ConditionalAuthentication
from
funkwhale_api.favorites.models
import
TrackFavorite
from
.
import
serializers
from
.
import
utils
from
.
import
serializers
,
utils
class
ActivityViewSet
(
viewsets
.
GenericViewSet
):
...
...
api/funkwhale_api/common/auth.py
View file @
2b0f7f6d
from
urllib.parse
import
parse_qs
import
jwt
from
django.contrib.auth.models
import
AnonymousUser
from
django.utils.encoding
import
smart_text
from
rest_framework
import
exceptions
from
rest_framework_jwt.settings
import
api_settings
from
rest_framework_jwt.authentication
import
BaseJSONWebTokenAuthentication
from
funkwhale_api.users.models
import
User
...
...
api/funkwhale_api/common/authentication.py
View file @
2b0f7f6d
from
django.utils.encoding
import
smart_text
from
django.utils.translation
import
ugettext
as
_
from
rest_framework
import
exceptions
from
rest_framework_jwt
import
authentication
from
rest_framework_jwt.settings
import
api_settings
...
...
api/funkwhale_api/common/consumers.py
View file @
2b0f7f6d
from
channels.generic.websocket
import
JsonWebsocketConsumer
from
funkwhale_api.common
import
channels
...
...
api/funkwhale_api/common/fields.py
View file @
2b0f7f6d
import
django_filters
from
django.db
import
models
from
funkwhale_api.music
import
utils
PRIVACY_LEVEL_CHOICES
=
[
(
"me"
,
"Only me"
),
(
"followers"
,
"Me and my followers"
),
...
...
api/funkwhale_api/common/management/commands/script.py
View file @
2b0f7f6d
...
...
@@ -41,7 +41,6 @@ class Command(BaseCommand):
script
[
"entrypoint"
](
self
,
**
options
)
def
show_help
(
self
):
indentation
=
4
self
.
stdout
.
write
(
""
)
self
.
stdout
.
write
(
"Available scripts:"
)
self
.
stdout
.
write
(
"Launch with: python manage.py <script_name>"
)
...
...
api/funkwhale_api/common/permissions.py
View file @
2b0f7f6d
import
operator
from
django.conf
import
settings
from
django.http
import
Http404
from
rest_framework.permissions
import
BasePermission
from
funkwhale_api.common
import
preferences
...
...
api/funkwhale_api/common/preferences.py
View file @
2b0f7f6d
from
django.conf
import
settings
from
django
import
forms
from
dynamic_preferences
import
serializers
from
dynamic_preferences
import
types
from
django.conf
import
settings
from
dynamic_preferences
import
serializers
,
types
from
dynamic_preferences.registries
import
global_preferences_registry
...
...
api/funkwhale_api/common/scripts/__init__.py
View file @
2b0f7f6d
from
.
import
django_permissions_to_user_permissions
from
.
import
test
api/funkwhale_api/common/scripts/django_permissions_to_user_permissions.py
View file @
2b0f7f6d
...
...
@@ -2,10 +2,10 @@
Convert django permissions to user permissions in the database,
following the work done in #152.
"""
from
django.contrib.auth.models
import
Permission
from
django.db.models
import
Q
from
funkwhale_api.users
import
models
from
django.contrib.auth.models
import
Permission
from
funkwhale_api.users
import
models
mapping
=
{
"dynamic_preferences.change_globalpreferencemodel"
:
"settings"
,
...
...
api/funkwhale_api/common/serializers.py
View file @
2b0f7f6d
...
...
@@ -40,7 +40,6 @@ class ActionSerializer(serializers.Serializer):
return
value
def
validate_objects
(
self
,
value
):
qs
=
None
if
value
==
"all"
:
return
self
.
queryset
.
all
().
order_by
(
"id"
)
if
type
(
value
)
in
[
list
,
tuple
]:
...
...
Prev
1
2
3
4
5
…
10
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment