Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add ruff format github workflow #731

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/black.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/ruff-formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#SPDX-FileCopyrightText: 2023 Birger Schacht
#SPDX-License-Identifier: MIT
name: Run ruff Linter

on: [push, pull_request]

jobs:
ruff:
uses: acdh-oeaw/prosnet-workflows/.github/workflows/[email protected]
with:
src: "."
options: "format --check"
22 changes: 9 additions & 13 deletions apis_core/api_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def generic_serializer_creation_factory():
select_related.append(f.name)

class TemplateSerializer(GenericHyperlinkedModelSerializer):

id = serializers.ReadOnlyField()
if getattr(settings, "APIS_API_ID_WRITABLE", False):
id = serializers.IntegerField()
Expand All @@ -209,7 +208,6 @@ class TemplateSerializer(GenericHyperlinkedModelSerializer):
_app_label = app_label

class Meta:

model = entity
exclude = exclude_lst_fin

Expand Down Expand Up @@ -239,9 +237,9 @@ def __init__(self, *args, **kwargs):
many=ck_many, read_only=True
)

TemplateSerializer.__name__ = (
TemplateSerializer.__qualname__
) = f"{entity_str.title().replace(' ', '')}Serializer"
TemplateSerializer.__name__ = TemplateSerializer.__qualname__ = (
f"{entity_str.title().replace(' ', '')}Serializer"
)

class TemplateSerializerRetrieve(TemplateSerializer):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -312,9 +310,9 @@ def __init__(self, *args, **kwargs):
"IntegerField",
"AutoField",
]:
filter_fields[
f"{field.name}__{f2.name}"
] = allowed_fields_filter[f2.__class__.__name__]
filter_fields[f"{field.name}__{f2.name}"] = (
allowed_fields_filter[f2.__class__.__name__]
)
continue
if field.__class__.__name__ in allowed_fields_filter.keys():
filter_fields[field.name] = allowed_fields_filter[
Expand All @@ -330,14 +328,12 @@ def __init__(self, *args, **kwargs):
filter_fields[f1[0]] = f1[1]

class MetaFilter(object):

model = entity
fields = filter_fields

filterset_dict["Meta"] = MetaFilter

class TemplateViewSet(ListViewObjectFilterMixin, viewsets.ModelViewSet):

_select_related = select_related
_prefetch_rel = prefetch_rel
pagination_class = CustomPagination
Expand Down Expand Up @@ -397,9 +393,9 @@ def list_viewset(self, request):
def dispatch(self, request, *args, **kwargs):
return super(self.__class__, self).dispatch(request, *args, **kwargs)

TemplateViewSet.__name__ = (
TemplateViewSet.__qualname__
) = f"Generic{entity_str.title().replace(' ', '')}ViewSet"
TemplateViewSet.__name__ = TemplateViewSet.__qualname__ = (
f"Generic{entity_str.title().replace(' ', '')}ViewSet"
)

serializers_dict[TemplateSerializer] = TemplateSerializer
views[f"{entity_str.lower().replace(' ', '')}"] = TemplateViewSet
Expand Down
1 change: 1 addition & 0 deletions apis_core/apis_entities/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dal_select2.widgets import Select2WidgetMixin as DALSelect2WidgetMixin
from django import forms


# "Rewrite" select2 widgets from Django Autocomplete Light so
# that they don't use Django's admin-provided jQuery, which
# causes errors with jQuery provided by us.
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_entities/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0002_remove_tempentityclass_text"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0003_remove_tempentityclass_source"),
]
Expand Down
4 changes: 1 addition & 3 deletions apis_core/apis_entities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def to_representation(self, obj):
<tr><th>Entity</th> <td><a href='{}'>Link</a></td></tr>
</table>
<button class='small-button' onclick='expand_node("{}", {})'>expand</button>
</div>""".format(
str(obj), ent_obj, ent_url, ent_obj, obj.pk
)
</div>""".format(str(obj), ent_obj, ent_url, ent_obj, obj.pk)
r = {
"type": ent_obj.lower(),
"label": str(obj),
Expand Down
6 changes: 3 additions & 3 deletions apis_core/apis_entities/serializers_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def add_relation_label(self, obj):
cm = obj.__class__.__name__
res_1 = dict()
res_1["id"] = obj.relation_type.pk
res_1[
"url"
] = f"{base_uri}{reverse('apis_core:apis_api:{}relation-detail'.format(cm).lower(), kwargs={'pk': obj.relation_type.pk},)}"
res_1["url"] = (
f"{base_uri}{reverse('apis_core:apis_api:{}relation-detail'.format(cm).lower(), kwargs={'pk': obj.relation_type.pk},)}"
)
if self.reverse and len(obj.relation_type.label_reverse) > 0:
res_1["label"] = obj.relation_type.label_reverse
elif self.reverse:
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_metainfo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0002_auto_20220201_1241"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0003_auto_20220218_1530"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0004_auto_20230310_0804"),
]
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_metainfo/migrations/0006_delete_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0002_remove_tempentityclass_text"),
("apis_metainfo", "0005_delete_uricandidate"),
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_metainfo/migrations/0007_delete_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_entities", "0003_remove_tempentityclass_source"),
("apis_metainfo", "0006_delete_text"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("apis_metainfo", "0007_delete_source"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0008_alter_rootobject_self_contenttype"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0009_remove_collection_collection_type"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0010_rename_name_rootobject_deprecated_name"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0011_alter_rootobject_deprecated_name"),
]
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_metainfo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class CollectionSerializer(serializers.HyperlinkedModelSerializer):

url = serializers.HyperlinkedIdentityField(
view_name="apis:apis_api:text-detail", lookup_field="pk"
)
Expand Down
5 changes: 0 additions & 5 deletions apis_core/apis_metainfo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ def helper_render_date(value, var_date, var_start_date, var_end_date):
# Various if-else branches checking which of the date fields are not None and should be used

if var_start_date is not None and var_end_date is not None:

overlay_help_text = str(var_start_date) + " - " + str(var_end_date)

elif var_date is not None:

overlay_help_text = str(var_date)

else:

return "—"

return format_html("<abbr title='" + overlay_help_text + "'>" + value + "</b>")
Expand All @@ -82,7 +79,6 @@ def helper_render_date(value, var_date, var_start_date, var_end_date):
# Again this function serves a generic purpose and must be assigned as class method to django-tables2 tables.Table class
# The whole logic is very similare to the generic_order_* functions above, so see their comments for more details.
def generic_render_start_date_written(self, record, value):

return helper_render_date(
value=value,
var_date=record.start_date,
Expand All @@ -92,7 +88,6 @@ def generic_render_start_date_written(self, record, value):


def generic_render_end_date_written(self, record, value):

return helper_render_date(
value=value,
var_date=record.end_date,
Expand Down
6 changes: 0 additions & 6 deletions apis_core/apis_relations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Meta:
}

def __init__(self, entity_type_self_str, entity_type_other_str):

super().__init__()

self.helper = FormHelper()
Expand Down Expand Up @@ -100,19 +99,16 @@ def load_subj_obj_prop(
# triple and the property name_forward or name_reverse are loaded correctly here.

if property_direction == PropertyAutocomplete.SELF_SUBJ_OTHER_OBJ_STR:

triple_subj = entity_instance_self
triple_obj = entity_instance_other
property_direction_name = property_instance.name_forward

elif property_direction == PropertyAutocomplete.SELF_OBJ_OTHER_SUBJ_STR:

triple_subj = entity_instance_other
triple_obj = entity_instance_self
property_direction_name = property_instance.name_reverse

else:

raise Exception("No valid property direction given.")

self.fields["subj"].initial = triple_subj
Expand Down Expand Up @@ -163,15 +159,13 @@ def load_remaining_data_from_input(

def save(self):
if self.instance.pk is None:

self.instance = TempTriple.objects.create(
subj=self.fields["subj"].initial,
obj=self.fields["obj"].initial,
prop=self.fields["prop"].initial,
)

else:

self.instance.subj = self.fields["subj"].initial
self.instance.obj = self.fields["obj"].initial
self.instance.prop = self.fields["prop"].initial
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_relations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_relations", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_relations", "0002_property_property_class_uri"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("apis_metainfo", "0003_auto_20220218_1530"),
("apis_relations", "0003_auto_20230123_1715"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("contenttypes", "0002_remove_content_type_name"),
("apis_relations", "0004_auto_20230124_1201"),
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_relations/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def order_object(self, queryset, is_descending):


def get_generic_triple_table(other_entity_class_name, entity_pk_self, detail):

# TODO RDF : add code from before refactoring and comment it out
class TripleTableBase(tables.Table):
"""
Expand Down
Loading
Loading