Skip to content

Commit

Permalink
style: fix issues identified by Ruff
Browse files Browse the repository at this point in the history
Fix formatting and linting issues pointed
out by Ruff.

Closes: #103
  • Loading branch information
koeaw committed May 15, 2024
1 parent e085a6c commit 12e966c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 35 deletions.
1 change: 1 addition & 0 deletions apis_ontology/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
I.e. project-specific endpoints (not APIS built-in API).
"""

from rest_framework import serializers

from apis_ontology.models import Expression, Work, WorkType
Expand Down
4 changes: 1 addition & 3 deletions apis_ontology/management/commands/delete_source_objects.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import itertools
from django.core.management.base import BaseCommand
from apis_ontology.models import DataSource
from apis_core.utils.caching import (
Expand Down Expand Up @@ -70,7 +69,6 @@ def handle(self, *args, **options):
entities = []
entities_failed = []

all_sources = DataSource.objects.all()
all_entities = get_all_entity_class_names()
entity_names = [m for m in all_entities]

Expand Down Expand Up @@ -137,7 +135,7 @@ def handle(self, *args, **options):
# else:
try:
ent_obj = ent_class.objects.filter(data_source__in=source_obj)
except:
except Exception:
print(f"No objects left for source {source_obj.name}.")
exit(0)

Expand Down
35 changes: 21 additions & 14 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ class TemporalFrequency(models.TextChoices):

class FigureSpeech(models.TextChoices):
DIRECT_QUOTE = "direct_quotation", _("direkt zitierend")
DIRECT_FIGURE_SPEECH = "direct_figure_speech", _(
"autonome, direkte Figurenrede"
DIRECT_FIGURE_SPEECH = (
"direct_figure_speech",
_("autonome, direkte Figurenrede"),
)
DIRECT_SPEECH = "direct_speech", _("direkte Rede")
INDIRECT_SPEECH = "indirect_speech", _("indirekte Rede")
Expand All @@ -324,11 +325,13 @@ class RepresentationOfThought(models.TextChoices):

class Focalization(models.TextChoices):
ZERO_FOCALIZATION = "zero", _("Nullfokalisierung")
INTERNAL_FOCALIZATION_VARIABLE = "internal_variable", _(
"interne Fokalisierung – variabel"
INTERNAL_FOCALIZATION_VARIABLE = (
"internal_variable",
_("interne Fokalisierung – variabel"),
)
INTERNAL_FOCALIZATION_FIXED = "internal_fixed", _(
"interne Fokalisierung – fixiert"
INTERNAL_FOCALIZATION_FIXED = (
"internal_fixed",
_("interne Fokalisierung – fixiert"),
)
EXTERNAL_FOCALIZATION = "external", _("externe Fokalisierung")

Expand All @@ -351,17 +354,21 @@ class NarrativeLevel(models.TextChoices):

class NarrativeVoice(models.TextChoices):
HETERODIEGETIC = "heterodiegetic", _("heterodiegetisches Erzählen")
HOMODIEGETIC_UNINVOLVED_EYEWITNESS = "homodiegetic_uninvolved", _(
"homodiegetisches Erzählen – unbeteiligter Beobachter:in"
HOMODIEGETIC_UNINVOLVED_EYEWITNESS = (
"homodiegetic_uninvolved",
_("homodiegetisches Erzählen – unbeteiligter Beobachter:in"),
) # a.k.a. alterodiegetic
HOMODIEGETIC_WITNESS_PARTICIPANT = "homodiegetic_participant", _(
"homodiegetisches Erzählen – beteiligter Beobachter:in"
HOMODIEGETIC_WITNESS_PARTICIPANT = (
"homodiegetic_participant",
_("homodiegetisches Erzählen – beteiligter Beobachter:in"),
) # a.k.a. alterodiegetic
HOMODIEGETIC_MINOR_CHARACTER = "homodiegetic_character", _(
"homodiegetisches Erzählen – Nebenfigur"
HOMODIEGETIC_MINOR_CHARACTER = (
"homodiegetic_character",
_("homodiegetisches Erzählen – Nebenfigur"),
) # a.k.a. alterodiegetic
HOMODIEGETIC_PROTAGONIST = "homodiegetic_protagonist", _(
"homodiegetisches Erzählen – Hauptfigur"
HOMODIEGETIC_PROTAGONIST = (
"homodiegetic_protagonist",
_("homodiegetisches Erzählen – Hauptfigur"),
) # a.k.a. autodiegetic

siglum = models.CharField(
Expand Down
7 changes: 3 additions & 4 deletions apis_ontology/scripts/access_sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import sharepy
import pandas as pd
import getpass
from pathlib import Path
from urllib.parse import quote
Expand Down Expand Up @@ -59,7 +58,7 @@ def sharepoint_connect():
try:
s = sharepy.connect(sp_site, username=sp_user, password=sp_pass)
s.save()
except Exception as e:
except Exception:
print("Cannot connect to SharePoint!")
exit(1)

Expand Down Expand Up @@ -205,9 +204,9 @@ def fetch_file_data(s, sp_fname, sp_file_url):
:return: the requested file
"""
sp_group = os.environ.get("SP_GROUP")
sp_dir = os.environ.get("SP_DIRECTORY")
# sp_dir = os.environ.get("SP_DIRECTORY")

source_file_by_name = f"https://{s.site}/sites/{sp_group}/_api/web/GetFolderByServerRelativeUrl('{sp_dir}')/Files('{sp_fname}')/$value"
# source_file_by_name = f"https://{s.site}/sites/{sp_group}/_api/web/GetFolderByServerRelativeUrl('{sp_dir}')/Files('{sp_fname}')/$value"
source_file_by_url = f"https://{s.site}/sites/{sp_group}/_api/web/GetFileByServerRelativeUrl('{sp_file_url}')/$value"

return source_file_by_url
Expand Down
7 changes: 3 additions & 4 deletions apis_ontology/scripts/import_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
WorkType,
Topic,
)
from .utils import create_import_date_string, convert_year_only_date


def create_triple(entity_subj, entity_obj, prop):
Expand Down Expand Up @@ -122,7 +121,7 @@ def get_work(siglum: str):
work = Work.objects.get(
siglum=siglum,
)
except Exception as e:
except Exception:
pass

return work
Expand All @@ -138,7 +137,7 @@ def get_type(title: str):
work_type = WorkType.objects.get(
name=title,
)
except Exception as e:
except Exception:
pass

return work_type
Expand Down Expand Up @@ -217,7 +216,7 @@ def create_person(person_data: dict, source: DataSource):
full_name = first_name
else:
# TODO log as error instead of exiting program
f"Missing name to look up or create Person, exiting."
"Missing name to look up or create Person, exiting."
exit(1)
else:
# rudimentary way of determining first name and last name from
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import numpy as np
import pandas as pd
import logging
from apis_ontology.scripts.access_sharepoint import import_and_parse_data
Expand Down
4 changes: 2 additions & 2 deletions apis_ontology/scripts/import_vorlass_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
WorkType,
StatusMixin,
)
from .additional_infos import WORK_TYPES, WORKTYPE_MAPPINGS
from .additional_infos import WORK_TYPES
from .import_helpers import create_triple, create_source
from apis_ontology.scripts.access_sharepoint import import_and_parse_data

Expand Down Expand Up @@ -63,7 +63,7 @@ def parse_vorlass_xml(title_siglum_dict, vorlass_excel_source):
]

with open(
f"./vorlass_data_frischmuth/04_derived_custom/Frischmuth_Vorlass_FNI-FRISCHMUTH_import-data.xml",
"./vorlass_data_frischmuth/04_derived_custom/Frischmuth_Vorlass_FNI-FRISCHMUTH_import-data.xml",
"r",
encoding="utf-8",
) as file_obj:
Expand Down
6 changes: 3 additions & 3 deletions apis_ontology/scripts/import_zotero_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ def zotero_login():

try:
zot.key_info()
except zotero_errors.UserNotAuthorised as e:
except zotero_errors.UserNotAuthorised:
print(
f"Zotero login not possible: "
f"{zot.request.text} ({zot.request.status_code})"
)
exit(1)
except zotero_errors.HTTPError as e:
except zotero_errors.HTTPError:
print(
f"Zotero login not possible: "
f"{zot.request.text} ({zot.request.status_code})"
Expand Down Expand Up @@ -585,7 +585,7 @@ def fetch(sub_collections=sub_collections):
try:
key_match = zot.collection(k)
active.append(key_match)
except Exception as e:
except Exception:
print(f"Collection with key {k} not found.")

if not active:
Expand Down
1 change: 1 addition & 0 deletions apis_ontology/scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Helper functions useful for various data import scripts.
"""

import datetime
from ..settings import APIS_BASE_URI

Expand Down
13 changes: 9 additions & 4 deletions apis_ontology/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
import os

from pathlib import Path
from apis_acdhch_default_settings.settings import *
from apis_acdhch_default_settings.settings import (
INSTALLED_APPS,
MIDDLEWARE,
REST_FRAMEWORK,
SPECTACULAR_SETTINGS,
)

# General Django settings

Expand Down Expand Up @@ -144,9 +149,9 @@

SPECTACULAR_SETTINGS["COMPONENT_SPLIT_REQUEST"] = True
SPECTACULAR_SETTINGS["COMPONENT_NO_READ_ONLY_REQUIRED"] = True
SPECTACULAR_SETTINGS[
"DEFAULT_GENERATOR_CLASS"
] = "apis_core.generic.generators.CustomSchemaGenerator"
SPECTACULAR_SETTINGS["DEFAULT_GENERATOR_CLASS"] = (
"apis_core.generic.generators.CustomSchemaGenerator"
)


# Database
Expand Down
1 change: 1 addition & 0 deletions apis_ontology/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from apis_acdhch_default_settings.urls import urlpatterns
from django.urls import include, path
from rest_framework import routers
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down

0 comments on commit 12e966c

Please sign in to comment.