Skip to content

Commit

Permalink
Add pre-commit config and fix all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 27, 2024
1 parent 5d96d44 commit 6c5ada9
Show file tree
Hide file tree
Showing 203 changed files with 1,149 additions and 1,171 deletions.
49 changes: 36 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
# do not touch the migration files at all: these are auto-generated by Django
exclude: \/migrations\/

repos:
- repo: https://github.com/pycqa/isort
rev: '5.10.1'
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v1.6.0'
hooks:
- id: autopep8
- repo: https://github.com/pycqa/flake8
rev: '3.9.2'
hooks:
- id: flake8
exclude: ^.*/migrations/.*$
- repo: meta
hooks:
- id: check-hooks-apply
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-ast
- id: check-json
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
exclude: \.html$|\.txt$
- id: trailing-whitespace
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.56.0
hooks:
- id: eslint
args: [--fix, --color]
additional_dependencies:
- [email protected]
- [email protected]
- [email protected]
- repo: https://github.com/crate-ci/typos
rev: v1.23.6
hooks:
- id: typos
exclude: daiquiri/metadata/settings.py
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The core developers are:
Yori Fournier <[email protected]>
Kirill Makan <[email protected]>

We apreciate contributions from:
We appreciate contributions from:

Fernando Campos
Harry Enke
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ If you are a maintainer and you want to review a Pull-Request please follow the
* Fetch the PR in your local-repository with: `git fetch origin pull/<PR-ID>/head:pr/<PR-ID> && git checkout pr/<PR-ID>`
* Perform the unit-tests of daiquiri
* Perform the instance-tests on the test-instance (dq-dev + test-app)
* Perform the instance-tests on the conserned services (dq-dev + service-app)
* Perform the instance-tests on the concerned services (dq-dev + service-app)
* Report any failure to the author of the pull-request

1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and
limitations under the License.


This code contains code derived from several other projects, which are distibuted
This code contains code derived from several other projects, which are distributed
under the following licenses:


Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

Today, the publication of research data plays an important role in astronomy
and astrophysics. On the one hand, dedicated surveys like SDSS and RAVE, data
intensive instruments like LOFAR, or massive simulations like Millennium and
MultiDark are initially planned to release their data for the community.
On the other hand, more traditionally oriented research projects strive to
intensive instruments like LOFAR, or massive simulations like Millennium and
MultiDark are initially planned to release their data for the community.
On the other hand, more traditionally oriented research projects strive to
publish their data as a key requirement demanded by the funding agencies.

The common approach is to publish this data via dedicated web sites. This
Expand Down Expand Up @@ -61,11 +61,11 @@ in Python. The following requirements are mandatory:

* Python `>=3.9`
* PostgreSQL `>=14`, MySQL `>=5.6`
* RabbitMQ `>=3.5` (for asyncronous tasks like the query queue)
* RabbitMQ `>=3.5` (for asynchronous tasks like the query queue)

For demonstration, development or testing purposes, Daiquiri can be installed
on Linux, macOS, or even Windows. If you, however, intent to set up a production
enviroment, serving Daiquiri over a Network or the Internet, we strongly suggest
environment, serving Daiquiri over a Network or the Internet, we strongly suggest
that you use a recent Linux distribution, namely:

* Debian 11
Expand Down Expand Up @@ -95,4 +95,3 @@ main documentation.
## Documentation

**Main documentation**: [django-daiquiri.github.io](https://django-daiquiri.github.io)

3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest

from django.conf import settings
from django.contrib.admin.utils import flatten
from django.core.management import call_command
Expand All @@ -10,7 +11,7 @@


@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
def django_db_setup(django_db_setup, django_db_blocker): # noqa: PT004
from django.test import TestCase
TestCase.multi_db = True
TestCase.databases = ('default', 'data', 'tap', 'oai')
Expand Down
6 changes: 3 additions & 3 deletions daiquiri/auth/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def is_safe_url(self, url):
return url_has_allowed_host_and_scheme(url, allowed_hosts=settings.ALLOWED_HOSTS)

def save_user(self, request, user, form, commit=True):
super(DaiquiriAccountAdapter, self).save_user(request, user, form)
super().save_user(request, user, form)

if settings.AUTH_WORKFLOW:
user.save()
Expand All @@ -29,7 +29,7 @@ def login(self, request, user):
if settings.AUTH_WORKFLOW and user.profile.is_pending:
raise ImmediateHttpResponse(HttpResponseRedirect(reverse('account_pending')))
else:
super(DaiquiriAccountAdapter, self).login(request, user)
super().login(request, user)

def is_open_for_signup(self, request):
return settings.AUTH_SIGNUP
Expand All @@ -39,4 +39,4 @@ class DaiquiriSocialAccountAdapter(DefaultSocialAccountAdapter):

def authentication_error(self, request, provider_id, error=None, exception=None, extra_context=None):
logger.error([provider_id, error, exception])
super(DaiquiriSocialAccountAdapter, self).authentication_error(request, provider_id, error, exception, extra_context)
super().authentication_error(request, provider_id, error, exception, extra_context)
4 changes: 2 additions & 2 deletions daiquiri/auth/assets/js/components/ShowModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ShowModal = ({ modal, profile, details }) => {
{
!isEmpty(details) && !isEmpty(profile.details) && (
<>
<div className="modal-seperator"></div>
<div className="modal-separator"></div>
<div className="row">
{
details.map((detail, detailIndex) => (
Expand All @@ -67,7 +67,7 @@ const ShowModal = ({ modal, profile, details }) => {
</>
)
}
<div className="modal-seperator"></div>
<div className="modal-separator"></div>
<div className="row">
<div className="col-md-6 mb-3 mb-md-0">
<dl>
Expand Down
4 changes: 2 additions & 2 deletions daiquiri/auth/assets/js/components/UpdateModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const UpdateModal = ({ modal, values, errors, details, groups, setValues, onSubm
{
!isEmpty(details) && (
<>
<div className="modal-seperator"></div>
<div className="modal-separator"></div>
<div className="row">
{
details.map((detail, detailIndex) => (
Expand Down Expand Up @@ -85,7 +85,7 @@ const UpdateModal = ({ modal, values, errors, details, groups, setValues, onSubm
{
!isEmpty(groups) && (
<>
<div className="modal-seperator"></div>
<div className="modal-separator"></div>
<strong className="d-block mb-2">{gettext('Groups')}</strong>
{
groups.map((group, groupIndex) => (
Expand Down
6 changes: 3 additions & 3 deletions daiquiri/auth/assets/js/components/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import UpdateModal from './UpdateModal.js'
import ConfirmModal from './ConfirmModal.js'

const Users = () => {
const initalParams = {
const initialParams = {
ordering: '-user__date_joined'
}

const [params, setParams] = useState(initalParams)
const [params, setParams] = useState(initialParams)

const showModal = useModal()
const updateModal = useModal()
Expand Down Expand Up @@ -61,7 +61,7 @@ const Users = () => {
}

const handleReset = () => {
setParams(initalParams)
setParams(initialParams)
}

const handleOrdering = (column) => {
Expand Down
8 changes: 4 additions & 4 deletions daiquiri/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
from django.urls import reverse

from daiquiri.core.forms import HoneypotField
from daiquiri.core.utils import get_detail_fields, sanitize_str
Expand All @@ -29,7 +29,7 @@ class Meta:
fields = ()

def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

for key, field in get_detail_fields(settings.AUTH_DETAIL_KEYS):
if self.instance.details and key in self.instance.details:
Expand All @@ -46,7 +46,7 @@ def save(self, *args, **kwargs):
for detail_key in settings.AUTH_DETAIL_KEYS:
self.instance.details[detail_key['key']] = self.cleaned_data[detail_key['key']]

return super(ProfileForm, self).save(*args, **kwargs)
return super().save(*args, **kwargs)


class SignupForm(ProfileForm):
Expand All @@ -59,7 +59,7 @@ class SignupForm(ProfileForm):
field_order = ['username', 'email', 'password1', 'password2']

def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

# add a consent field, the label is added in the template
if settings.AUTH_TERMS_OF_USE:
Expand Down
46 changes: 22 additions & 24 deletions daiquiri/auth/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@

from django.conf import settings
from django.contrib.auth.models import User
from django.db.models.signals import m2m_changed, post_delete, post_save
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete, m2m_changed

from allauth.account.signals import email_confirmed, password_changed, password_reset

from .models import Profile

from .signals import (
user_activated,
user_confirmed,
user_created,
user_updated,
user_deleted,
user_disabled,
user_enabled,
user_groups_updated,
user_confirmed,
user_rejected,
user_activated,
user_disabled,
user_enabled
user_updated,
)

from .utils import (
send_request_confirmation,
send_request_activation,
send_notify_confirmation,
send_notify_rejection,
send_notify_activation,
send_activation,
send_notify_activation,
send_notify_confirmation,
send_notify_password_changed,
send_notify_rejection,
send_request_activation,
send_request_confirmation,
)

logger = logging.getLogger(__name__)
Expand All @@ -45,20 +43,20 @@ def post_save_user(sender, **kwargs):
profile.save()

user_created.send(sender=User, user=user)
logger.info('user \'%s\' created.' % user.username)
logger.info('user \'%s\' created.', user.username)

elif kwargs['update_fields'] is None:
# a login triggers this handler with update_fields=last_login
user_updated.send(sender=User, user=user)
logger.info('user \'%s\' updated.' % user.username)
logger.info('user \'%s\' updated.', user.username)


@receiver(post_delete, sender=User)
def post_delete_user(sender, **kwargs):
if not kwargs.get('raw', False):
user = kwargs['instance']
user_deleted.send(sender=User, user=user)
logger.info('user \'%s\' deleted.' % user.username)
logger.info('user \'%s\' deleted.', user.username)


@receiver(m2m_changed, sender=User.groups.through)
Expand All @@ -69,7 +67,7 @@ def m2m_changed_user(sender, **kwargs):
# fire the signal only one per change
if kwargs['action'] in ('post_add', 'post_remove', 'post_clear'):
user_groups_updated.send(sender=User, user=user)
logger.info('groups for user \'%s\' updated.' % user.username)
logger.info('groups for user \'%s\' updated.', user.username)


@receiver(email_confirmed)
Expand All @@ -80,7 +78,7 @@ def email_confirmed_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['email_address'].user

logger.info('user \'%s\' validated his/her email address.' % user.username)
logger.info('user \'%s\' validated his/her email address.', user.username)

if settings.AUTH_WORKFLOW:
user = kwargs['email_address'].user
Expand All @@ -100,7 +98,7 @@ def user_confirmed_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' confirmed by \'%s\'.' % (user.username, request.user.username))
logger.info('user \'%s\' confirmed by \'%s\'.', (user.username, request.user.username))
if settings.AUTH_WORKFLOW:
send_notify_confirmation(request, user)

Expand All @@ -113,7 +111,7 @@ def user_rejected_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' rejected by \'%s\'.' % (user.username, request.user.username))
logger.info('user \'%s\' rejected by \'%s\'.', (user.username, request.user.username))
if settings.AUTH_WORKFLOW:
send_notify_rejection(request, user)

Expand All @@ -126,7 +124,7 @@ def user_activated_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' activated by \'%s\'.' % (user.username, request.user.username))
logger.info('user \'%s\' activated by \'%s\'.', (user.username, request.user.username))
if settings.AUTH_WORKFLOW:
send_notify_activation(request, user)
send_activation(request, user)
Expand All @@ -140,7 +138,7 @@ def user_disabled_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' disabled by \'%s\'.' % (user.username, request.user.username))
logger.info('user \'%s\' disabled by \'%s\'.', (user.username, request.user.username))


@receiver(user_enabled)
Expand All @@ -151,7 +149,7 @@ def user_enabled_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' enabled by \'%s\'.' % (user.username, request.user.username))
logger.info('user \'%s\' enabled by \'%s\'.', (user.username, request.user.username))


@receiver(password_changed)
Expand All @@ -163,6 +161,6 @@ def password_changed_handler(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' changed his/her password.' % user.username)
logger.info('user \'%s\' changed his/her password.', user.username)
if settings.AUTH_WORKFLOW == 'confirmation':
send_notify_password_changed(request, user)
Loading

0 comments on commit 6c5ada9

Please sign in to comment.