From 0cee45c3433e487e81eeebb0b15cfcd1ea02d5f1 Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Fri, 1 Mar 2024 14:01:01 +0100 Subject: [PATCH] upgrade to black==24.2.0, reformat (#1374) --- CHANGELOG.rst | 1 + adminalerts/forms.py | 6 +-- adminalerts/models.py | 8 ++-- adminalerts/tests/test_views.py | 1 + appalerts/plugins.py | 1 - config/settings/base.py | 13 +++--- config/wsgi.py | 1 + filesfolders/views.py | 24 +++++++---- filesfolders/views_api.py | 8 ++-- projectroles/app_settings.py | 30 ++++++------- projectroles/constants.py | 1 - projectroles/forms.py | 30 +++++++------ .../management/commands/cleanappsettings.py | 8 ++-- projectroles/plugins.py | 8 ++-- projectroles/remote_projects.py | 42 +++++++++++-------- projectroles/tests/test_models.py | 30 +++++++------ projectroles/tests/test_templatetags.py | 18 ++++---- projectroles/tests/test_views.py | 30 ++++++------- projectroles/views.py | 14 ++++--- requirements/test.txt | 3 +- sodarcache/management/commands/deletecache.py | 8 ++-- timeline/tests/test_ui.py | 1 + timeline/views_ajax.py | 1 + userprofile/forms.py | 8 ++-- 24 files changed, 168 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 75342764..de738d28 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -22,6 +22,7 @@ Changed - Upgrade minimum PostgreSQL version to v12 (#1074) - Upgrade to PostgreSQL v16 in CI (#1074) - Upgrade general Python dependencies (#1374) + - Reformat with ``black==24.2.0`` (#1374) Removed ------- diff --git a/adminalerts/forms.py b/adminalerts/forms.py index b0e5f637..75f6a510 100644 --- a/adminalerts/forms.py +++ b/adminalerts/forms.py @@ -40,9 +40,9 @@ def __init__(self, current_user=None, *args, **kwargs): # Creation if not self.instance.pk: - self.fields[ - 'date_expire' - ].initial = timezone.now() + timezone.timedelta(days=1) + self.fields['date_expire'].initial = ( + timezone.now() + timezone.timedelta(days=1) + ) # Updating else: # self.instance.pk # Set description value as raw markdown diff --git a/adminalerts/models.py b/adminalerts/models.py index 851e829c..1770a99a 100644 --- a/adminalerts/models.py +++ b/adminalerts/models.py @@ -73,9 +73,11 @@ class AdminAlert(models.Model): def __str__(self): return '{}{}'.format( self.message, - ' [ACTIVE]' - if (self.active and self.date_expire > timezone.now()) - else '', + ( + ' [ACTIVE]' + if (self.active and self.date_expire > timezone.now()) + else '' + ), ) def __repr__(self): diff --git a/adminalerts/tests/test_views.py b/adminalerts/tests/test_views.py index 54490fab..f0317933 100644 --- a/adminalerts/tests/test_views.py +++ b/adminalerts/tests/test_views.py @@ -1,4 +1,5 @@ """Tests for UI views in the adminalerts app""" + from django.urls import reverse from django.utils import timezone diff --git a/appalerts/plugins.py b/appalerts/plugins.py index 643fa304..d0c7fb19 100644 --- a/appalerts/plugins.py +++ b/appalerts/plugins.py @@ -1,6 +1,5 @@ """Plugins for the appalerts app""" - # Projectroles dependency from projectroles.plugins import SiteAppPluginPoint, BackendPluginPoint diff --git a/config/settings/base.py b/config/settings/base.py index 29130bd6..0b29fdf2 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -7,6 +7,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.2/ref/settings/ """ + import environ import os @@ -365,9 +366,9 @@ AUTH_LDAP_CA_CERT_FILE = env.str('AUTH_LDAP_CA_CERT_FILE', None) AUTH_LDAP_CONNECTION_OPTIONS = {**LDAP_DEFAULT_CONN_OPTIONS} if AUTH_LDAP_CA_CERT_FILE: - AUTH_LDAP_CONNECTION_OPTIONS[ - ldap.OPT_X_TLS_CACERTFILE - ] = AUTH_LDAP_CA_CERT_FILE + AUTH_LDAP_CONNECTION_OPTIONS[ldap.OPT_X_TLS_CACERTFILE] = ( + AUTH_LDAP_CA_CERT_FILE + ) AUTH_LDAP_CONNECTION_OPTIONS[ldap.OPT_X_TLS_NEWCTX] = 0 AUTH_LDAP_USER_FILTER = env.str( 'AUTH_LDAP_USER_FILTER', '(sAMAccountName=%(user)s)' @@ -398,9 +399,9 @@ AUTH_LDAP2_CA_CERT_FILE = env.str('AUTH_LDAP2_CA_CERT_FILE', None) AUTH_LDAP2_CONNECTION_OPTIONS = {**LDAP_DEFAULT_CONN_OPTIONS} if AUTH_LDAP2_CA_CERT_FILE: - AUTH_LDAP2_CONNECTION_OPTIONS[ - ldap.OPT_X_TLS_CACERTFILE - ] = AUTH_LDAP2_CA_CERT_FILE + AUTH_LDAP2_CONNECTION_OPTIONS[ldap.OPT_X_TLS_CACERTFILE] = ( + AUTH_LDAP2_CA_CERT_FILE + ) AUTH_LDAP2_CONNECTION_OPTIONS[ldap.OPT_X_TLS_NEWCTX] = 0 AUTH_LDAP2_USER_FILTER = env.str( 'AUTH_LDAP2_USER_FILTER', '(sAMAccountName=%(user)s)' diff --git a/config/wsgi.py b/config/wsgi.py index 42ae5374..d6df6b04 100644 --- a/config/wsgi.py +++ b/config/wsgi.py @@ -13,6 +13,7 @@ framework. """ + import os import sys diff --git a/filesfolders/views.py b/filesfolders/views.py index 55e6bea2..dc764d7c 100644 --- a/filesfolders/views.py +++ b/filesfolders/views.py @@ -212,9 +212,11 @@ def get_success_url(self): tl_event.add_object( obj=self.object, label=obj_type, - name=self.object.get_path() - if isinstance(self.object, Folder) - else self.object.name, + name=( + self.object.get_path() + if isinstance(self.object, Folder) + else self.object.name + ), ) messages.success( @@ -843,12 +845,16 @@ def _finalize_edit(self, edit_count, target_folder, **kwargs): self.batch_action, edit_count, edit_suffix, - '({} failed)'.format(len(self.failed)) - if len(self.failed) > 0 - else '', - 'to {target_folder}' - if self.batch_action == 'move' and target_folder - else '', + ( + '({} failed)'.format(len(self.failed)) + if len(self.failed) > 0 + else '' + ), + ( + 'to {target_folder}' + if self.batch_action == 'move' and target_folder + else '' + ), ), extra_data=extra_data, status_type='OK' if edit_count > 0 else 'FAILED', diff --git a/filesfolders/views_api.py b/filesfolders/views_api.py index bfc75175..4420c132 100644 --- a/filesfolders/views_api.py +++ b/filesfolders/views_api.py @@ -97,9 +97,11 @@ def perform_destroy(self, instance): tl_event.add_object( obj=instance, label=obj_type, - name=instance.get_path() - if isinstance(instance, Folder) - else instance.name, + name=( + instance.get_path() + if isinstance(instance, Folder) + else instance.name + ), ) diff --git a/projectroles/app_settings.py b/projectroles/app_settings.py index a6b50d14..d6b5411c 100644 --- a/projectroles/app_settings.py +++ b/projectroles/app_settings.py @@ -454,26 +454,26 @@ def get_defaults(cls, scope, project=None, user=None, post_safe=False): for plugin in app_plugins: p_settings = cls.get_definitions(scope, plugin=plugin) for s_key in p_settings: - ret[ - 'settings.{}.{}'.format(plugin.name, s_key) - ] = cls.get_default( - plugin.name, + ret['settings.{}.{}'.format(plugin.name, s_key)] = ( + cls.get_default( + plugin.name, + s_key, + project=project, + user=user, + post_safe=post_safe, + ) + ) + + p_settings = cls.get_definitions(scope, app_name='projectroles') + for s_key in p_settings: + ret['settings.{}.{}'.format('projectroles', s_key)] = ( + cls.get_default( + 'projectroles', s_key, project=project, user=user, post_safe=post_safe, ) - - p_settings = cls.get_definitions(scope, app_name='projectroles') - for s_key in p_settings: - ret[ - 'settings.{}.{}'.format('projectroles', s_key) - ] = cls.get_default( - 'projectroles', - s_key, - project=project, - user=user, - post_safe=post_safe, ) return ret diff --git a/projectroles/constants.py b/projectroles/constants.py index def85f57..b9be37cf 100644 --- a/projectroles/constants.py +++ b/projectroles/constants.py @@ -1,6 +1,5 @@ """SODAR constants definition and helper functions""" - # Global SODAR constants SODAR_CONSTANTS = { # Project roles diff --git a/projectroles/forms.py b/projectroles/forms.py index 42eb14bc..f2fb9a36 100644 --- a/projectroles/forms.py +++ b/projectroles/forms.py @@ -407,9 +407,11 @@ def _set_app_setting_widget(self, app_name, s_field, s_key, s_val): values = s_val['options'](project=self.instance) self.fields[s_field] = forms.ChoiceField( choices=[ - (str(value[0]), str(value[1])) - if isinstance(value, tuple) - else (str(value), str(value)) + ( + (str(value[0]), str(value[1])) + if isinstance(value, tuple) + else (str(value), str(value)) + ) for value in values ], **setting_kwargs @@ -418,9 +420,11 @@ def _set_app_setting_widget(self, app_name, s_field, s_key, s_val): values = s_val['options'](project=None) self.fields[s_field] = forms.ChoiceField( choices=[ - (str(value[0]), str(value[1])) - if isinstance(value, tuple) - else (str(value), str(value)) + ( + (str(value[0]), str(value[1])) + if isinstance(value, tuple) + else (str(value), str(value)) + ) for value in values ], **setting_kwargs @@ -428,9 +432,11 @@ def _set_app_setting_widget(self, app_name, s_field, s_key, s_val): else: self.fields[s_field] = forms.ChoiceField( choices=[ - (int(option), int(option)) - if s_val['type'] == 'INTEGER' - else (option, option) + ( + (int(option), int(option)) + if s_val['type'] == 'INTEGER' + else (option, option) + ) for option in s_val['options'] ], **setting_kwargs @@ -662,9 +668,9 @@ def __init__(self, project=None, current_user=None, *args, **kwargs): self.initial['owner'] = parent_project.get_owner().user else: self.initial['owner'] = self.current_user - self.fields[ - 'owner' - ].label_from_instance = lambda x: x.get_form_label(email=True) + self.fields['owner'].label_from_instance = ( + lambda x: x.get_form_label(email=True) + ) # Hide owner select widget for regular users if not self.current_user.is_superuser: self.fields['owner'].widget = forms.HiddenInput() diff --git a/projectroles/management/commands/cleanappsettings.py b/projectroles/management/commands/cleanappsettings.py index 3f3c5ba9..93e68021 100644 --- a/projectroles/management/commands/cleanappsettings.py +++ b/projectroles/management/commands/cleanappsettings.py @@ -28,9 +28,11 @@ def get_setting_str(db_setting): return '.'.join( [ 'settings', - 'projectroles' - if db_setting.app_plugin is None - else db_setting.app_plugin.name, + ( + 'projectroles' + if db_setting.app_plugin is None + else db_setting.app_plugin.name + ), db_setting.name, ] ) diff --git a/projectroles/plugins.py b/projectroles/plugins.py index b5cbb4b9..63c85647 100644 --- a/projectroles/plugins.py +++ b/projectroles/plugins.py @@ -667,9 +667,11 @@ def get_active_plugins(plugin_type='project_app', custom_order=False): ] return sorted( ret, - key=lambda x: x.plugin_ordering - if custom_order and plugin_type == 'project_app' - else x.name, + key=lambda x: ( + x.plugin_ordering + if custom_order and plugin_type == 'project_app' + else x.name + ), ) return None diff --git a/projectroles/remote_projects.py b/projectroles/remote_projects.py index d39d9cf4..d37de149 100644 --- a/projectroles/remote_projects.py +++ b/projectroles/remote_projects.py @@ -105,9 +105,9 @@ def _add_parent_categories(cls, sync_data, category, project_level): cat_data = { 'title': category.title, 'type': PROJECT_TYPE_CATEGORY, - 'parent_uuid': str(category.parent.sodar_uuid) - if category.parent - else None, + 'parent_uuid': ( + str(category.parent.sodar_uuid) if category.parent else None + ), 'description': category.description, 'readme': category.readme.raw, } @@ -192,15 +192,17 @@ def _add_app_setting(cls, sync_data, app_setting, all_defs, add_user_name): 'type': app_setting.type, 'value': app_setting.value, 'value_json': app_setting.value_json, - 'app_plugin': app_setting.app_plugin.name - if app_setting.app_plugin - else None, - 'project_uuid': str(app_setting.project.sodar_uuid) - if app_setting.project - else None, - 'user_uuid': str(app_setting.user.sodar_uuid) - if app_setting.user - else None, + 'app_plugin': ( + app_setting.app_plugin.name if app_setting.app_plugin else None + ), + 'project_uuid': ( + str(app_setting.project.sodar_uuid) + if app_setting.project + else None + ), + 'user_uuid': ( + str(app_setting.user.sodar_uuid) if app_setting.user else None + ), 'local': local, } if add_user_name: @@ -260,9 +262,11 @@ def get_source_data(self, target_site, req_version=None): logger.error( 'Failed to add app setting "{}.settings.{}" ' '(UUID={}): {} '.format( - a.app_plugin.name - if a.app_plugin - else 'projectroles', + ( + a.app_plugin.name + if a.app_plugin + else 'projectroles' + ), a.name, a.sodar_uuid, ex, @@ -1236,9 +1240,11 @@ def sync_remote_data(self, site, remote_data, request=None): except Exception as ex: logger.error( 'Failed to set app setting "{}.setting.{}" ({}): {}'.format( - a_data['app_plugin'] - if a_data['app_plugin'] - else 'projectroles', + ( + a_data['app_plugin'] + if a_data['app_plugin'] + else 'projectroles' + ), a_data['name'], a_uuid, ex, diff --git a/projectroles/tests/test_models.py b/projectroles/tests/test_models.py index 17ac68f0..3ca24e92 100644 --- a/projectroles/tests/test_models.py +++ b/projectroles/tests/test_models.py @@ -137,12 +137,14 @@ def make_invite( 'role': role, 'issuer': issuer, 'message': message, - 'date_expire': date_expire - if date_expire - else ( - timezone.now() - + timezone.timedelta( - days=settings.PROJECTROLES_INVITE_EXPIRY_DAYS + 'date_expire': ( + date_expire + if date_expire + else ( + timezone.now() + + timezone.timedelta( + days=settings.PROJECTROLES_INVITE_EXPIRY_DAYS + ) ) ), 'secret': secret or SECRET, @@ -171,9 +173,11 @@ def make_setting( ): """Make and save a AppSetting""" values = { - 'app_plugin': None - if app_name == 'projectroles' - else get_app_plugin(app_name).get_model(), + 'app_plugin': ( + None + if app_name == 'projectroles' + else get_app_plugin(app_name).get_model() + ), 'project': project, 'name': name, 'type': setting_type, @@ -231,9 +235,11 @@ def make_remote_project( 'site': site, 'level': level, 'date_access': date_access, - 'project': project - if project - else Project.objects.filter(sodar_uuid=project_uuid).first(), + 'project': ( + project + if project + else Project.objects.filter(sodar_uuid=project_uuid).first() + ), } remote_project = RemoteProject(**values) remote_project.save() diff --git a/projectroles/tests/test_templatetags.py b/projectroles/tests/test_templatetags.py index caba7462..43d60a66 100644 --- a/projectroles/tests/test_templatetags.py +++ b/projectroles/tests/test_templatetags.py @@ -389,12 +389,12 @@ def test_include_invalid_url(self): # TODO: Replace with get_app_plugin once implemented for backend plugins backend_plugin = get_active_plugins('backend')[0] - type( - backend_plugin - ).javascript_url = 'example_backend_app/js/NOT_EXISTING_JS.js' - type( - backend_plugin - ).css_url = 'example_backend_app/css/NOT_EXISTING_CSS.css' + type(backend_plugin).javascript_url = ( + 'example_backend_app/js/NOT_EXISTING_JS.js' + ) + type(backend_plugin).css_url = ( + 'example_backend_app/css/NOT_EXISTING_CSS.css' + ) self.assertEqual( c_tags.get_backend_include(backend_plugin.name, 'js'), '' @@ -408,9 +408,9 @@ def test_get_backend_include(self): # TODO: Replace with get_app_plugin once implemented for backend plugins backend_plugin = get_active_plugins('backend')[0] - type( - backend_plugin - ).javascript_url = 'example_backend_app/js/greeting.js' + type(backend_plugin).javascript_url = ( + 'example_backend_app/js/greeting.js' + ) type(backend_plugin).css_url = 'example_backend_app/css/greeting.css' self.assertEqual( diff --git a/projectroles/tests/test_views.py b/projectroles/tests/test_views.py index 359ad5b0..9c963bc3 100644 --- a/projectroles/tests/test_views.py +++ b/projectroles/tests/test_views.py @@ -910,12 +910,12 @@ def _get_post_app_settings(cls, project, user): ps['settings.example_project_app.project_str_setting'] = 'test' ps['settings.example_project_app.project_bool_setting'] = True ps['settings.example_project_app.project_json_setting'] = '{}' - ps[ - 'settings.example_project_app.project_callable_setting' - ] = 'No project or user for callable' - ps[ - 'settings.example_project_app.project_callable_setting_options' - ] = str(project.sodar_uuid) + ps['settings.example_project_app.project_callable_setting'] = ( + 'No project or user for callable' + ) + ps['settings.example_project_app.project_callable_setting_options'] = ( + str(project.sodar_uuid) + ) ps['settings.projectroles.ip_restrict'] = True ps['settings.projectroles.ip_allowlist'] = '["192.168.1.1"]' return ps @@ -1161,9 +1161,9 @@ def test_post_project_custom_validation(self): values.update( app_settings.get_all(project=self.project, post_safe=True) ) - values[ - 'settings.example_project_app.project_str_setting' - ] = INVALID_SETTING_VALUE + values['settings.example_project_app.project_str_setting'] = ( + INVALID_SETTING_VALUE + ) with self.login(self.user): response = self.client.post(self.url, values) self.assertEqual(response.status_code, 200) @@ -1372,13 +1372,13 @@ def test_post_remote(self): values['settings.example_project_app.project_int_setting'] = 0 values['settings.example_project_app.project_int_setting_options'] = 0 values['settings.example_project_app.project_str_setting'] = 'test' - values[ - 'settings.example_project_app.project_str_setting_options' - ] = 'string1' + values['settings.example_project_app.project_str_setting_options'] = ( + 'string1' + ) values['settings.example_project_app.project_bool_setting'] = True - values[ - 'settings.example_project_app.project_callable_setting' - ] = 'No project or user for callable' + values['settings.example_project_app.project_callable_setting'] = ( + 'No project or user for callable' + ) values[ 'settings.example_project_app.project_callable_setting_options' ] = str(self.project.sodar_uuid) diff --git a/projectroles/views.py b/projectroles/views.py index 034abb53..afee39eb 100644 --- a/projectroles/views.py +++ b/projectroles/views.py @@ -3145,9 +3145,11 @@ def post(self, request, *args, **kwargs): 'project': Project.objects.get( sodar_uuid=project_uuid ), - 'old_level': REMOTE_LEVEL_NONE - if not remote_obj - else remote_obj.level, + 'old_level': ( + REMOTE_LEVEL_NONE + if not remote_obj + else remote_obj.level + ), 'new_level': v, } ) @@ -3188,9 +3190,9 @@ def post(self, request, *args, **kwargs): modifying_access.append( { 'project': project.get_log_title(), - 'old_level': REMOTE_LEVEL_NONE - if not old_level - else old_level, + 'old_level': ( + REMOTE_LEVEL_NONE if not old_level else old_level + ), 'new_level': v, } ) diff --git a/requirements/test.txt b/requirements/test.txt index 52826be2..909f4b3b 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -22,8 +22,7 @@ tblib==3.0.0 beautifulsoup4==4.12.3 # Black for formatting -# TODO: Update and reformat -black==23.1.0 +black==24.2.0 # Coveralls for coverage reporting # TODO: See if we can update this AND coverage diff --git a/sodarcache/management/commands/deletecache.py b/sodarcache/management/commands/deletecache.py index efd99ce8..140b4c86 100644 --- a/sodarcache/management/commands/deletecache.py +++ b/sodarcache/management/commands/deletecache.py @@ -61,8 +61,10 @@ def handle(self, *args, **options): 'Deleted {} cached data item{} from {}'.format( item_count, 's' if item_count != 1 else '', - 'project {}'.format(project.get_log_title()) - if project - else 'all projects', + ( + 'project {}'.format(project.get_log_title()) + if project + else 'all projects' + ), ) ) diff --git a/timeline/tests/test_ui.py b/timeline/tests/test_ui.py index 2acc07b4..5e0e9e8d 100644 --- a/timeline/tests/test_ui.py +++ b/timeline/tests/test_ui.py @@ -1,4 +1,5 @@ """UI tests for the timeline app""" + import json from django.urls import reverse diff --git a/timeline/views_ajax.py b/timeline/views_ajax.py index 8b56892e..8426cfa5 100644 --- a/timeline/views_ajax.py +++ b/timeline/views_ajax.py @@ -1,4 +1,5 @@ """Ajax API views for the timeline app""" + import html from django.http import HttpResponseForbidden diff --git a/userprofile/forms.py b/userprofile/forms.py index f3a0d585..494f62f6 100644 --- a/userprofile/forms.py +++ b/userprofile/forms.py @@ -59,9 +59,11 @@ def __init__(self, *args, **kwargs): if callable(s_val['options']): self.fields[s_field] = forms.ChoiceField( choices=[ - (str(value[0]), str(value[1])) - if isinstance(value, tuple) - else (str(value), str(value)) + ( + (str(value[0]), str(value[1])) + if isinstance(value, tuple) + else (str(value), str(value)) + ) for value in s_val['options']( user=self.user )