Skip to content

Commit

Permalink
Merge pull request #479 from afuetterer/ruff
Browse files Browse the repository at this point in the history
build: modernize ruff config
  • Loading branch information
huberrob authored Jan 26, 2024
2 parents 708fe43 + 63b81a9 commit 72b2234
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 69 deletions.
42 changes: 21 additions & 21 deletions fuji_server/data/metadata_standards_uris.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion fuji_server/evaluators/fair_evaluator_formal_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions fuji_server/evaluators/fair_evaluator_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ 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
license_output.osi_approved = spdx_osi
self.output.append(license_output)
self.license_info.append(
{
"license": l,
"license": license,
"id": spdx_id,
"is_url": isurl,
"spdx_uri": spdx_uri,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion fuji_server/harvester/data_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")):
Expand Down
22 changes: 11 additions & 11 deletions fuji_server/harvester/metadata_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fuji_server/helper/linked_vocab_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions fuji_server/helper/metadata_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions fuji_server/helper/metadata_collector_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion fuji_server/helper/metric_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import re

import yaml

from fuji_server.helper.preprocessor import Preprocessor


Expand Down
2 changes: 1 addition & 1 deletion fuji_server/helper/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions fuji_server/helper/request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion tests/helper/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 72b2234

Please sign in to comment.