diff --git a/fuji_server/data/metadata_standards_uris.json b/fuji_server/data/metadata_standards_uris.json index 752abdb6..25a48cb0 100644 --- a/fuji_server/data/metadata_standards_uris.json +++ b/fuji_server/data/metadata_standards_uris.json @@ -7668,27 +7668,6 @@ ], "title": "EAD (Encoded Archival Description)" }, - "https://ogp.me": { - "acronym": "OpenGraph", - "field_of_science": [], - "id": "opengraph", - "identifier": [ - { - "type": "local", - "value": "fuji:m46" - }, - { - "type": "homepage", - "value": "https://ogp.me" - }, - { - "type": "namespace", - "value": "https://ogp.me/ns#" - } - ], - "subject_areas": null, - "title": "The Open Graph protocol metadata format" - }, "http://a9.com/-/spec/opensearch/1.1/": { "acronym": null, "field_of_science": [], @@ -38198,6 +38177,27 @@ ], "title": "ETD-MS an Interoperability Metadata Standard for Electronic Theses and Dissertations" }, + "https://ogp.me": { + "acronym": "OpenGraph", + "field_of_science": [], + "id": "opengraph", + "identifier": [ + { + "type": "local", + "value": "fuji:m46" + }, + { + "type": "homepage", + "value": "https://ogp.me" + }, + { + "type": "namespace", + "value": "https://ogp.me/ns#" + } + ], + "subject_areas": null, + "title": "The Open Graph protocol metadata format" + }, "https://ogp.me/ns#": { "acronym": "OpenGraph", "field_of_science": [], diff --git a/fuji_server/evaluators/fair_evaluator_formal_metadata.py b/fuji_server/evaluators/fair_evaluator_formal_metadata.py index 192aff60..273ece50 100644 --- a/fuji_server/evaluators/fair_evaluator_formal_metadata.py +++ b/fuji_server/evaluators/fair_evaluator_formal_metadata.py @@ -138,7 +138,7 @@ def testExternalStructuredMetadataAvailable(self): sparql_provider = SPARQLMetadataProvider( endpoint=self.fuji.sparql_endpoint, logger=self.logger, metric_id=self.metric_identifier ) - if self.fuji.pid_url == None: + if self.fuji.pid_url is None: url_to_sparql = self.fuji.landing_url else: url_to_sparql = self.fuji.pid_url diff --git a/fuji_server/evaluators/fair_evaluator_license.py b/fuji_server/evaluators/fair_evaluator_license.py index dfafa62d..8d54c901 100644 --- a/fuji_server/evaluators/fair_evaluator_license.py +++ b/fuji_server/evaluators/fair_evaluator_license.py @@ -40,20 +40,20 @@ def setLicenseDataAndOutput(self): if isinstance(specified_licenses, str): # licenses maybe string or list depending on metadata schemas specified_licenses = [specified_licenses] if specified_licenses is not None and specified_licenses != []: - for l in specified_licenses: + for license in specified_licenses: isurl = False licence_valid = False license_output = LicenseOutputInner() - if isinstance(l, str): - isurl = idutils.is_url(l) + if isinstance(license, str): + isurl = idutils.is_url(license) if isurl: - iscc, generic_cc = self.isCreativeCommonsLicense(l, self.metric_identifier) + iscc, generic_cc = self.isCreativeCommonsLicense(license, self.metric_identifier) if iscc: - l = generic_cc - spdx_uri, spdx_osi, spdx_id = self.lookup_license_by_url(l, self.metric_identifier) + license = generic_cc + spdx_uri, spdx_osi, spdx_id = self.lookup_license_by_url(license, self.metric_identifier) else: # maybe licence name - spdx_uri, spdx_osi, spdx_id = self.lookup_license_by_name(l, self.metric_identifier) - license_output.license = l + spdx_uri, spdx_osi, spdx_id = self.lookup_license_by_name(license, self.metric_identifier) + license_output.license = license if spdx_uri: licence_valid = True license_output.details_url = spdx_uri @@ -61,7 +61,7 @@ def setLicenseDataAndOutput(self): self.output.append(license_output) self.license_info.append( { - "license": l, + "license": license, "id": spdx_id, "is_url": isurl, "spdx_uri": spdx_uri, @@ -204,14 +204,14 @@ def testLicenseIsValidAndSPDXRegistered(self): ) ) if self.license_info: - for l in self.license_info: + for license in self.license_info: if test_required: for rq_license_id in test_required: - if l.get("id"): - if fnmatch.fnmatch(l.get("id"), rq_license_id): + if license.get("id"): + if fnmatch.fnmatch(license.get("id"), rq_license_id): test_status = True else: - if l.get("valid"): + if license.get("valid"): test_status = True else: self.logger.warning( diff --git a/fuji_server/harvester/data_harvester.py b/fuji_server/harvester/data_harvester.py index c2bd46cf..d383aa97 100644 --- a/fuji_server/harvester/data_harvester.py +++ b/fuji_server/harvester/data_harvester.py @@ -95,7 +95,7 @@ def retrieve_all_data(self, scan_content=True): fl["size"] = None else: fl["size"] = None - if fl.get("type") == None: + if fl.get("type") is None: if fl["trust"] > 1: fl["trust"] -= 1 elif "/" in str(fl.get("type")): diff --git a/fuji_server/harvester/metadata_harvester.py b/fuji_server/harvester/metadata_harvester.py index 48f3f88e..1e48d62f 100644 --- a/fuji_server/harvester/metadata_harvester.py +++ b/fuji_server/harvester/metadata_harvester.py @@ -150,7 +150,7 @@ def merge_metadata(self, metadict, url, method, format, mimetype, schema="", nam "FsF-F2-01M : Harvesting of this metadata is explicitely disabled in the metric configuration-:" + str(metadata_standard) ) - if isinstance(metadict, dict) and allow_merge == True: + if isinstance(metadict, dict) and allow_merge is True: # self.metadata_sources.append((method_source, 'negotiated')) for r in metadict.keys(): if r in self.reference_elements: @@ -246,14 +246,14 @@ def merge_metadata(self, metadict, url, method, format, mimetype, schema="", nam print("Metadata Merge Error: " + str(e), format, mimetype, schema) def exclude_null(self, dt): - if type(dt) is dict: + if isinstance(dt, dict): return dict((k, self.exclude_null(v)) for k, v in dt.items() if v and self.exclude_null(v)) - elif type(dt) is list: + elif isinstance(dt, list): try: return list(set([self.exclude_null(v) for v in dt if v and self.exclude_null(v)])) except Exception: return [self.exclude_null(v) for v in dt if v and self.exclude_null(v)] - elif type(dt) is str: + elif isinstance(dt, str): return dt.strip() else: return dt @@ -321,7 +321,7 @@ def check_pidtest_repeat(self): validated = False if idhelper.is_persistent and validated: found_pids[found_id_scheme] = idhelper.get_identifier_url() - if len(found_pids) >= 1 and self.repeat_pid_check == False: + if len(found_pids) >= 1 and self.repeat_pid_check is False: self.logger.info( "FsF-F2-01M : Found object identifier in metadata, repeating PID check for FsF-F1-02D" ) @@ -345,12 +345,12 @@ def set_html_typed_links(self): try: dom = lxml.html.fromstring(self.landing_html.encode("utf8")) links = dom.xpath("/*/head/link") - for l in links: + for link in links: source = MetadataOfferingMethods.TYPED_LINKS - href = l.attrib.get("href") - rel = l.attrib.get("rel") - type = l.attrib.get("type") - profile = l.attrib.get("format") + href = link.attrib.get("href") + rel = link.attrib.get("rel") + type = link.attrib.get("type") + profile = link.attrib.get("format") type = str(type).strip() # handle relative paths linkparts = urlparse(href) @@ -673,7 +673,7 @@ def retrieve_metadata_embedded(self): # requestHelper.setAcceptType(AcceptTypes.html_xml) # request requestHelper.setAcceptType(AcceptTypes.default) # request neg_source, landingpage_html = requestHelper.content_negotiate("FsF-F1-02D", ignore_html=False) - if not "html" in str(requestHelper.content_type): + if "html" not in str(requestHelper.content_type): self.logger.info( "FsF-F2-01M :Content type is " + str(requestHelper.content_type) diff --git a/fuji_server/helper/linked_vocab_helper.py b/fuji_server/helper/linked_vocab_helper.py index a8cec7cf..58d38081 100644 --- a/fuji_server/helper/linked_vocab_helper.py +++ b/fuji_server/helper/linked_vocab_helper.py @@ -110,7 +110,7 @@ def set_linked_vocab_index(self): def get_overlap(self, s1, s2): result = "" for char in s1: - if char in s2 and not char in result: + if char in s2 and char not in result: result += char return len(result) diff --git a/fuji_server/helper/metadata_collector.py b/fuji_server/helper/metadata_collector.py index 0827d0e7..36fe08d7 100644 --- a/fuji_server/helper/metadata_collector.py +++ b/fuji_server/helper/metadata_collector.py @@ -257,8 +257,8 @@ def getMetadataMapping(self): def getLogger(self): return self.logger - def setLogger(self, l): - self.logger = l + def setLogger(self, logger): + self.logger = logger def getSourceMetadata(self): return self.source_metadata diff --git a/fuji_server/helper/metadata_collector_rdf.py b/fuji_server/helper/metadata_collector_rdf.py index bf6158af..fa886ec9 100644 --- a/fuji_server/helper/metadata_collector_rdf.py +++ b/fuji_server/helper/metadata_collector_rdf.py @@ -438,9 +438,9 @@ def get_sparqled_metadata(self, g): self.logger.info("FsF-F2-01M : Trying to query generic SPARQL on RDF, found triples: -:" + str(len(g))) r = g.query(Mapper.GENERIC_SPARQL.value) for row in r: - for l, v in row.asdict().items(): - if l is not None: - if l in [ + for relation_type, related_resource in row.asdict().items(): + if relation_type is not None: + if relation_type in [ "references", "source", "isVersionOf", @@ -456,10 +456,12 @@ def get_sparqled_metadata(self, g): ]: if not meta.get("related_resources"): meta["related_resources"] = [] - meta["related_resources"].append({"related_resource": str(v), "relation_type": l}) + meta["related_resources"].append( + {"related_resource": str(related_resource), "relation_type": relation_type} + ) else: - if v: - meta[l] = str(v) + if related_resource: + meta[relation_type] = str(related_resource) if meta: break # break @@ -474,7 +476,7 @@ def get_sparqled_metadata(self, g): has_xhtml = False for t in list(g): # exclude xhtml properties/predicates: - if not "/xhtml/vocab" in t[1] and not "/ogp.me" in t[1]: + if "/xhtml/vocab" not in t[1] and "/ogp.me" not in t[1]: goodtriples.append(t) else: has_xhtml = True diff --git a/fuji_server/helper/metric_helper.py b/fuji_server/helper/metric_helper.py index f194283b..f6206349 100644 --- a/fuji_server/helper/metric_helper.py +++ b/fuji_server/helper/metric_helper.py @@ -7,7 +7,6 @@ import re import yaml - from fuji_server.helper.preprocessor import Preprocessor diff --git a/fuji_server/helper/preprocessor.py b/fuji_server/helper/preprocessor.py index fc606b8c..bc80739b 100644 --- a/fuji_server/helper/preprocessor.py +++ b/fuji_server/helper/preprocessor.py @@ -10,8 +10,8 @@ from urllib.parse import urlparse import requests -import yaml +import yaml from fuji_server.helper.linked_vocab_helper import linked_vocab_helper diff --git a/fuji_server/helper/request_helper.py b/fuji_server/helper/request_helper.py index 4a569448..eeff2dbc 100644 --- a/fuji_server/helper/request_helper.py +++ b/fuji_server/helper/request_helper.py @@ -328,7 +328,7 @@ def content_negotiate(self, metric_id="", ignore_html=True): self.response_content = str(self.response_content).encode("utf-8") # Now content should be utf-8 encoded - if content_truncated == True: + if content_truncated is True: try: self.response_content = self.response_content.rsplit(b"\n", 1)[0] except Exception as e: @@ -410,7 +410,7 @@ def content_negotiate(self, metric_id="", ignore_html=True): if self.content_type in at.value: if at.name == "html": # since we already parse HTML in the landing page we ignore this and do not parse again - if ignore_html == False: + if ignore_html is False: self.logger.info("%s : Found HTML page!" % metric_id) else: self.logger.info("%s : Ignoring HTML response" % metric_id) diff --git a/pyproject.toml b/pyproject.toml index 811421c1..d1372296 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,17 +148,21 @@ markers = [ testpaths = "tests" [tool.ruff] -ignore = [ - "RUF012" # mutable-class-default -] line-length = 120 -select = [ - "F", # pyflakes +# Ref: https://docs.astral.sh/ruff/configuration/ +src = ["fuji_server"] +target-version = "py311" + +[tool.ruff.lint] +extend-select = [ "I", # isort "UP", # pyupgrade "RUF" # ruff ] -target-version = "py311" +ignore = [ + "E722", # bare-except + "RUF012" # mutable-class-default +] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["fuji_server", "tests"] diff --git a/tests/helper/test_preprocessor.py b/tests/helper/test_preprocessor.py index d7cc8c0c..b30b5f76 100644 --- a/tests/helper/test_preprocessor.py +++ b/tests/helper/test_preprocessor.py @@ -23,8 +23,8 @@ from typing import Any import pytest -import yaml +import yaml from fuji_server.helper.preprocessor import Preprocessor from tests.conftest import DATA_DIR