Skip to content
Snippets Groups Projects
Commit 8b4cde36 authored by Manon Blanco's avatar Manon Blanco Committed by Yoann Schneider
Browse files

Bump ruff linter and add formatter

parent 0d0fdcca
No related branches found
No related tags found
1 merge request!448Bump ruff linter and add formatter
Pipeline #144482 passed
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.278
rev: v0.1.6
hooks:
# Run the linter.
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: "^worker-{{cookiecutter.slug}}/"
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
# Run the formatter.
- id: ruff-format
exclude: "^worker-{{cookiecutter.slug}}/"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
......
......@@ -204,8 +204,8 @@ class ClassificationMixin(object):
for index, classification in enumerate(classifications):
ml_class_id = classification.get("ml_class_id")
assert ml_class_id and isinstance(
ml_class_id, str
assert (
ml_class_id and isinstance(ml_class_id, str)
), f"Classification at index {index} in classifications: ml_class_id shouldn't be null and should be of type str"
# Make sure it's a valid UUID
......
......@@ -195,18 +195,18 @@ class ElementMixin(object):
), f"Element at index {index} in elements: Should be of type dict"
name = element.get("name")
assert name and isinstance(
name, str
assert (
name and isinstance(name, str)
), f"Element at index {index} in elements: name shouldn't be null and should be of type str"
type = element.get("type")
assert type and isinstance(
type, str
assert (
type and isinstance(type, str)
), f"Element at index {index} in elements: type shouldn't be null and should be of type str"
polygon = element.get("polygon")
assert polygon and isinstance(
polygon, list
assert (
polygon and isinstance(polygon, list)
), f"Element at index {index} in elements: polygon shouldn't be null and should be of type list"
assert (
len(polygon) >= 3
......@@ -219,8 +219,9 @@ class ElementMixin(object):
), f"Element at index {index} in elements: polygon points should be lists of two numbers"
confidence = element.get("confidence")
assert confidence is None or (
isinstance(confidence, float) and 0 <= confidence <= 1
assert (
confidence is None
or (isinstance(confidence, float) and 0 <= confidence <= 1)
), f"Element at index {index} in elements: confidence should be None or a float in [0..1] range"
if self.is_read_only:
......@@ -485,11 +486,14 @@ class ElementMixin(object):
if self.use_cache:
# Checking that we only received query_params handled by the cache
assert set(query_params.keys()) <= {
"type",
"worker_version",
"worker_run",
}, "When using the local cache, you can only filter by 'type' and/or 'worker_version' and/or 'worker_run'"
assert (
set(query_params.keys())
<= {
"type",
"worker_version",
"worker_run",
}
), "When using the local cache, you can only filter by 'type' and/or 'worker_version' and/or 'worker_run'"
query = CachedElement.select().where(CachedElement.parent_id == element.id)
if type:
......@@ -644,11 +648,14 @@ class ElementMixin(object):
if self.use_cache:
# Checking that we only received query_params handled by the cache
assert set(query_params.keys()) <= {
"type",
"worker_version",
"worker_run",
}, "When using the local cache, you can only filter by 'type' and/or 'worker_version' and/or 'worker_run'"
assert (
set(query_params.keys())
<= {
"type",
"worker_version",
"worker_run",
}
), "When using the local cache, you can only filter by 'type' and/or 'worker_version' and/or 'worker_run'"
parent_ids = CachedElement.select(CachedElement.parent_id).where(
CachedElement.id == element.id
......
......@@ -250,13 +250,13 @@ class EntityMixin(object):
), f"Entity at index {index} in entities: Should be of type dict"
name = entity.get("name")
assert name and isinstance(
name, str
assert (
name and isinstance(name, str)
), f"Entity at index {index} in entities: name shouldn't be null and should be of type str"
type_id = entity.get("type_id")
assert type_id and isinstance(
type_id, str
assert (
type_id and isinstance(type_id, str)
), f"Entity at index {index} in entities: type_id shouldn't be null and should be of type str"
offset = entity.get("offset")
......@@ -270,8 +270,9 @@ class EntityMixin(object):
), f"Entity at index {index} in entities: length shouldn't be null and should be a strictly positive integer"
confidence = entity.get("confidence")
assert confidence is None or (
isinstance(confidence, float) and 0 <= confidence <= 1
assert (
confidence is None
or (isinstance(confidence, float) and 0 <= confidence <= 1)
), f"Entity at index {index} in entities: confidence should be None or a float in [0..1] range"
assert len(entities) == len(
......
......@@ -235,9 +235,7 @@ class TrainingMixin(object):
), "The model is already marked as available."
s3_put_url = self.model_version.get("s3_put_url")
assert (
s3_put_url
), "S3 PUT URL is not set, please ensure you have the right to validate a model version."
assert s3_put_url, "S3 PUT URL is not set, please ensure you have the right to validate a model version."
logger.info("Uploading to s3...")
# Upload the archive on s3
......@@ -263,9 +261,7 @@ class TrainingMixin(object):
:param size: The size of the uploaded archive
:param archive_hash: MD5 hash of the uploaded archive
"""
assert (
self.model_version
), "You must create the model version and upload its archive before validating it."
assert self.model_version, "You must create the model version and upload its archive before validating it."
try:
self.model_version = self.request(
"ValidateModelVersion",
......
......@@ -140,13 +140,13 @@ class TranscriptionMixin(object):
for index, transcription in enumerate(transcriptions_payload):
element_id = transcription.get("element_id")
assert element_id and isinstance(
element_id, str
assert (
element_id and isinstance(element_id, str)
), f"Transcription at index {index} in transcriptions: element_id shouldn't be null and should be of type str"
text = transcription.get("text")
assert text and isinstance(
text, str
assert (
text and isinstance(text, str)
), f"Transcription at index {index} in transcriptions: text shouldn't be null and should be of type str"
confidence = transcription.get("confidence")
......@@ -159,8 +159,8 @@ class TranscriptionMixin(object):
orientation = transcription.get(
"orientation", TextOrientation.HorizontalLeftToRight
)
assert orientation and isinstance(
orientation, TextOrientation
assert (
orientation and isinstance(orientation, TextOrientation)
), f"Transcription at index {index} in transcriptions: orientation shouldn't be null and should be of type TextOrientation"
if orientation:
transcription["orientation"] = orientation.value
......@@ -242,8 +242,8 @@ class TranscriptionMixin(object):
for index, transcription in enumerate(transcriptions_payload):
text = transcription.get("text")
assert text and isinstance(
text, str
assert (
text and isinstance(text, str)
), f"Transcription at index {index} in transcriptions: text shouldn't be null and should be of type str"
confidence = transcription.get("confidence")
......@@ -256,15 +256,15 @@ class TranscriptionMixin(object):
orientation = transcription.get(
"orientation", TextOrientation.HorizontalLeftToRight
)
assert orientation and isinstance(
orientation, TextOrientation
assert (
orientation and isinstance(orientation, TextOrientation)
), f"Transcription at index {index} in transcriptions: orientation shouldn't be null and should be of type TextOrientation"
if orientation:
transcription["orientation"] = orientation.value
polygon = transcription.get("polygon")
assert polygon and isinstance(
polygon, list
assert (
polygon and isinstance(polygon, list)
), f"Transcription at index {index} in transcriptions: polygon shouldn't be null and should be of type list"
assert (
len(polygon) >= 3
......@@ -277,8 +277,12 @@ class TranscriptionMixin(object):
), f"Transcription at index {index} in transcriptions: polygon points should be lists of two numbers"
element_confidence = transcription.get("element_confidence")
assert element_confidence is None or (
isinstance(element_confidence, float) and 0 <= element_confidence <= 1
assert (
element_confidence is None
or (
isinstance(element_confidence, float)
and 0 <= element_confidence <= 1
)
), f"Transcription at index {index} in transcriptions: element_confidence should be either null or a float in [0..1] range"
if self.is_read_only:
......
[tool.ruff]
exclude = [".git", "__pycache__"]
ignore = ["E501"]
select = ["E", "F", "T1", "W", "I"]
select = [
# pycodestyle
"E",
"W",
# Pyflakes
"F",
# Flake8 Debugger
"T1",
# Isort
"I",
]
[tool.ruff.isort]
known-first-party = ["arkindex", "arkindex_common", "arkindex_worker"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment