Skip to content

Commit

Permalink
chore(deps): bump python to 3.12, thunor core (#18)
Browse files Browse the repository at this point in the history
bump more dependencies including thunor core and associated
compatibility fixes.
  • Loading branch information
alubbock authored Aug 8, 2024
1 parent 452c4d9 commit 41d77d6
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.11-slim-bullseye AS thunorweb_base
MAINTAINER Alex Lubbock <[email protected]>
FROM python:3.12-slim-bullseye AS thunorweb_base
LABEL org.opencontainers.image.authors="[email protected]"
ENV PYTHONUNBUFFERED 1
ENV THUNOR_HOME=/thunor

Expand Down
1 change: 0 additions & 1 deletion config-examples/docker-compose.complete.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2.1'
services:
app:
extends:
Expand Down
1 change: 0 additions & 1 deletion config-examples/docker-compose.postgresonly.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2.1'
services:
postgres:
extends:
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-r thunor/requirements.txt
Django==4.2.15
django-allauth==0.52.0
django-allauth==64.0.0
django-crispy-forms==1.14.0
django-custom-user==1.1
django-guardian==2.4.0
django-invitations==2.0.0
django-invitations==2.1.0
django-redis==5.4.0
django-webpack-loader==0.6.0
uwsgi==2.0.22
psycopg2==2.9.5
django-redis==5.2.0
raven==6.10.0
psycopg2==2.9.9
sentry-sdk[django]==2.12.0
uwsgi==2.0.23
59 changes: 25 additions & 34 deletions thunordjango/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
"""

import os
import sentry_sdk
import sys
import thunorweb
from django.contrib import messages
import errno
import logging

logger = logging.getLogger(__name__)

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# This is where state-specific files are stored, like uploads/downloads and
# the SQLite database, if applicable
STATE_DIR = os.path.join(BASE_DIR, '_state')

# Load environment variables for .env file, if present
env_file = os.path.join(BASE_DIR, 'thunor-dev.env')
try:
Expand All @@ -46,6 +41,28 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ['DJANGO_DEBUG'].lower() == 'true'

# Initialise sentry error handler
sentry_sdk.init(
dsn=os.environ.get('DJANGO_SENTRY_DSN', None),
environment=os.environ.get('DJANGO_SENTRY_ENVIRONMENT',
'development' if DEBUG else 'production'),
release=thunorweb.__version__,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)


logger = logging.getLogger(__name__)

# This is where state-specific files are stored, like uploads/downloads and
# the SQLite database, if applicable
STATE_DIR = os.path.join(BASE_DIR, '_state')

if DEBUG:
# Add the thunor submodule to the path
sys.path.insert(0, os.path.join(BASE_DIR, 'thunor'))
Expand All @@ -68,7 +85,6 @@
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.staticfiles',
'raven.contrib.django.raven_compat',
'thunorweb.apps.ThunorConfig',
'custom_user',
'allauth',
Expand Down Expand Up @@ -99,6 +115,7 @@
# MIDDLEWARE += ['debug_panel.middleware.DebugPanelMiddleware']

MIDDLEWARE += [
'allauth.account.middleware.AccountMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
Expand Down Expand Up @@ -193,16 +210,6 @@
}


RAVEN_CONFIG = {
'dsn': os.environ.get('DJANGO_SENTRY_DSN', None),
# If you are using git, you can also automatically configure the
# release based on the git info.
'environment': os.environ.get('DJANGO_SENTRY_ENVIRONMENT',
'development' if DEBUG else 'production'),
'release': thunorweb.__version__,
}


AUTH_USER_MODEL = 'custom_user.EmailUser'
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
Expand Down Expand Up @@ -358,12 +365,6 @@
},
},
'handlers': {
'sentry': {
'level': 'DEBUG' if DEBUG else 'INFO',
'filters': ['require_debug_false'],
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
'tags': {},
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
Expand All @@ -373,23 +374,13 @@
'loggers': {
'root': {
'level': 'DEBUG' if DEBUG else 'INFO',
'handlers': ['sentry'],
'handlers': [],
},
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}

Expand Down
3 changes: 1 addition & 2 deletions thunordjango/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import os
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.wsgi import get_wsgi_application
try:
from uwsgidecorators import postfork
Expand All @@ -18,7 +17,7 @@

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "thunordjango.settings")

application = Sentry(get_wsgi_application())
application = get_wsgi_application()

@postfork
def initialise():
Expand Down
2 changes: 1 addition & 1 deletion thunorweb/plate_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def parse_platefile_synergy_neo(self, sep='\t'):
plate = self._plate_objects.get(plate_name, None)

# Each plate can have multiple assays
assays = re.split('\n\s*\n', barcode_and_rest[1])
assays = re.split(r'\n\s*\n', barcode_and_rest[1])

for a in assays:
a_strp = a.strip()
Expand Down
2 changes: 1 addition & 1 deletion thunorweb/templates/base-inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
{% load webpack_loader %}{% get_files 'raven' 'js' as raven_js %}
<script src="{{ raven_js.0.url }}" crossorigin="anonymous"></script>

<script>{% load raven %}{% load thunorweb_tags %}Raven.config('{% sentry_public_dsn %}', {
<script>{% load thunorweb_tags %}Raven.config('{% sentry_public_dsn %}', {
environment: '{% sentry_environment %}', release: '{% thunorweb_version %}'
}).install();
{% if user.is_authenticated %}Raven.setUserContext({email: '{{ user.email }}',
Expand Down
8 changes: 7 additions & 1 deletion thunorweb/templatetags/thunorweb_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
from django.utils.safestring import mark_safe
from django.conf import settings
from sentry_sdk import Hub

register = template.Library()

Expand All @@ -18,7 +19,12 @@ def jsonify(obj):

@register.simple_tag
def sentry_environment():
return settings.RAVEN_CONFIG['environment']
return Hub.current.client.options['environment']


@register.simple_tag
def sentry_public_dsn():
return Hub.current.client.options['dsn']


@register.simple_tag
Expand Down
42 changes: 21 additions & 21 deletions thunorweb/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ def test_rename_dataset(self):

resp = self.client.post(reverse('thunorweb:ajax_rename_dataset'),
{'datasetId': d.id, 'datasetName': 'test456'})
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

d.refresh_from_db()
self.assertEquals(d.name, 'test456')
self.assertEqual(d.name, 'test456')

def test_delete_dataset(self):
self.client.force_login(self.user)
d = HTSDataset.objects.create(owner=self.user, name='test2')

resp = self.client.post(reverse('thunorweb:ajax_delete_dataset'),
{'dataset_id': d.id})
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

self.assertIsNotNone(HTSDataset.objects.get(pk=d.id).deleted_date)

Expand All @@ -66,21 +66,21 @@ def test_delete_platefile(self):
self.client.force_login(self.user)
resp = self.client.post(reverse('thunorweb:ajax_delete_platefile'),
{'key': platefile_id})
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

def test_dataset_upload_page(self):
self.client.force_login(self.user)
resp = self.client.get(reverse('thunorweb:plate_upload',
args=[self.d.id]))
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

def test_download_hdf(self):
self.client.force_login(self.user)
resp = self.client.get(reverse('thunorweb:download_dataset_hdf5',
args=[self.d.id]))

self.assertEquals(resp.status_code, HTTP_OK)
self.assertEquals(resp['Content-Type'], 'application/x-hdf5')
self.assertEqual(resp.status_code, HTTP_OK)
self.assertEqual(resp['Content-Type'], 'application/x-hdf5')

def test_download_hdf_access(self):
self.check_view_access_status(
Expand All @@ -91,16 +91,16 @@ def test_download_dip_params_tsv(self):
resp = self.client.get(reverse('thunorweb:download_fit_params',
args=[self.d.id, 'dip']))

self.assertEquals(resp.status_code, HTTP_OK)
self.assertEquals(resp['Content-Type'], 'text/tab-separated-values')
self.assertEqual(resp.status_code, HTTP_OK)
self.assertEqual(resp['Content-Type'], 'text/tab-separated-values')

def test_download_viability_params_tsv(self):
self.client.force_login(self.user)
resp = self.client.get(reverse('thunorweb:download_fit_params',
args=[self.d.id, 'viability']))

self.assertEquals(resp.status_code, HTTP_OK)
self.assertEquals(resp['Content-Type'], 'text/tab-separated-values')
self.assertEqual(resp.status_code, HTTP_OK)
self.assertEqual(resp['Content-Type'], 'text/tab-separated-values')

def test_download_params_tsv_access(self):
for stat_type in ('dip', 'viability'):
Expand All @@ -123,10 +123,10 @@ def test_ajax_get_dataset_groupings(self):

def test_get_datasets_ajax(self):
url = reverse('thunorweb:ajax_get_datasets')
self.assertEquals(self.client.get(url).status_code, HTTP_UNAUTHORIZED)
self.assertEqual(self.client.get(url).status_code, HTTP_UNAUTHORIZED)

self.client.force_login(self.user)
self.assertEquals(self.client.get(url).status_code, HTTP_OK)
self.assertEqual(self.client.get(url).status_code, HTTP_OK)

def test_assign_group(self):
""" Make dataset public and check access"""
Expand All @@ -140,13 +140,13 @@ def test_assign_group(self):
'state': 'true'
}
)
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

# Log in as other user and check dataset access
self.client.force_login(self.other_user)
resp = self.client.get(reverse('thunorweb:view_dataset',
args=[self.d.id]))
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

# Dataset should be visible in the public datasets list
resp = self.client.get(reverse(
Expand All @@ -164,7 +164,7 @@ def test_assign_group(self):
'state': 'false'
}
)
self.assertEquals(resp.status_code, HTTP_NOT_FOUND)
self.assertEqual(resp.status_code, HTTP_NOT_FOUND)

# Revoke permission
self.client.force_login(self.user)
Expand All @@ -176,13 +176,13 @@ def test_assign_group(self):
'state': 'false'
}
)
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

# Check permission revoked as other user
self.client.force_login(self.other_user)
resp = self.client.get(reverse('thunorweb:view_dataset',
args=[self.d.id]))
self.assertEquals(resp.status_code, HTTP_NOT_FOUND)
self.assertEqual(resp.status_code, HTTP_NOT_FOUND)

resp = self.client.get(reverse(
'thunorweb:ajax_get_datasets_by_group', args=['Public']))
Expand All @@ -191,13 +191,13 @@ def test_assign_group(self):

def check_view_access_status(self, url):
resp = self.client.get(url)
self.assertEquals(resp.status_code, HTTP_REDIRECT)
self.assertEqual(resp.status_code, HTTP_REDIRECT)

self.client.force_login(self.user)
resp = self.client.get(url)
self.assertEquals(resp.status_code, HTTP_OK)
self.assertEqual(resp.status_code, HTTP_OK)

self.client.force_login(self.other_user)
resp = self.client.get(url)
self.assertEquals(resp.status_code, HTTP_NOT_FOUND)
self.assertEqual(resp.status_code, HTTP_NOT_FOUND)
self.client.logout()
Loading

0 comments on commit 41d77d6

Please sign in to comment.