mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Configures ruff as the one stop linter and resolves warnings it raised
This commit is contained in:
@@ -19,14 +19,14 @@ from django.utils import termcolors
|
||||
from django.utils import timezone
|
||||
from filelock import FileLock
|
||||
|
||||
from .. import matching
|
||||
from ..file_handling import create_source_path_directory
|
||||
from ..file_handling import delete_empty_directories
|
||||
from ..file_handling import generate_unique_filename
|
||||
from ..models import Document
|
||||
from ..models import MatchingModel
|
||||
from ..models import PaperlessTask
|
||||
from ..models import Tag
|
||||
from documents import matching
|
||||
from documents.file_handling import create_source_path_directory
|
||||
from documents.file_handling import delete_empty_directories
|
||||
from documents.file_handling import generate_unique_filename
|
||||
from documents.models import Document
|
||||
from documents.models import MatchingModel
|
||||
from documents.models import PaperlessTask
|
||||
from documents.models import Tag
|
||||
|
||||
logger = logging.getLogger("paperless.handlers")
|
||||
|
||||
@@ -54,10 +54,7 @@ def set_correspondent(
|
||||
potential_correspondents = matching.match_correspondents(document, classifier)
|
||||
|
||||
potential_count = len(potential_correspondents)
|
||||
if potential_correspondents:
|
||||
selected = potential_correspondents[0]
|
||||
else:
|
||||
selected = None
|
||||
selected = potential_correspondents[0] if potential_correspondents else None
|
||||
if potential_count > 1:
|
||||
if use_first:
|
||||
logger.debug(
|
||||
@@ -120,10 +117,7 @@ def set_document_type(
|
||||
potential_document_type = matching.match_document_types(document, classifier)
|
||||
|
||||
potential_count = len(potential_document_type)
|
||||
if potential_document_type:
|
||||
selected = potential_document_type[0]
|
||||
else:
|
||||
selected = None
|
||||
selected = potential_document_type[0] if potential_document_type else None
|
||||
|
||||
if potential_count > 1:
|
||||
if use_first:
|
||||
@@ -255,10 +249,7 @@ def set_storage_path(
|
||||
)
|
||||
|
||||
potential_count = len(potential_storage_path)
|
||||
if potential_storage_path:
|
||||
selected = potential_storage_path[0]
|
||||
else:
|
||||
selected = None
|
||||
selected = potential_storage_path[0] if potential_storage_path else None
|
||||
|
||||
if potential_count > 1:
|
||||
if use_first:
|
||||
@@ -370,7 +361,7 @@ def validate_move(instance, old_path, new_path):
|
||||
if not os.path.isfile(old_path):
|
||||
# Can't do anything if the old file does not exist anymore.
|
||||
logger.fatal(f"Document {str(instance)}: File {old_path} has gone.")
|
||||
raise CannotMoveFilesException()
|
||||
raise CannotMoveFilesException
|
||||
|
||||
if os.path.isfile(new_path):
|
||||
# Can't do anything if the new file already exists. Skip updating file.
|
||||
@@ -378,7 +369,7 @@ def validate_move(instance, old_path, new_path):
|
||||
f"Document {str(instance)}: Cannot rename file "
|
||||
f"since target path {new_path} already exists.",
|
||||
)
|
||||
raise CannotMoveFilesException()
|
||||
raise CannotMoveFilesException
|
||||
|
||||
|
||||
@receiver(models.signals.m2m_changed, sender=Document.tags.through)
|
||||
@@ -546,10 +537,10 @@ def before_task_publish_handler(sender=None, headers=None, body=None, **kwargs):
|
||||
date_started=None,
|
||||
date_done=None,
|
||||
)
|
||||
except Exception as e: # pragma: no cover
|
||||
except Exception: # pragma: no cover
|
||||
# Don't let an exception in the signal handlers prevent
|
||||
# a document from being consumed.
|
||||
logger.error(f"Creating PaperlessTask failed: {e}", exc_info=True)
|
||||
logger.exception("Creating PaperlessTask failed")
|
||||
|
||||
|
||||
@task_prerun.connect
|
||||
@@ -568,15 +559,20 @@ def task_prerun_handler(sender=None, task_id=None, task=None, **kwargs):
|
||||
task_instance.status = states.STARTED
|
||||
task_instance.date_started = timezone.now()
|
||||
task_instance.save()
|
||||
except Exception as e: # pragma: no cover
|
||||
except Exception: # pragma: no cover
|
||||
# Don't let an exception in the signal handlers prevent
|
||||
# a document from being consumed.
|
||||
logger.error(f"Setting PaperlessTask started failed: {e}", exc_info=True)
|
||||
logger.exception("Setting PaperlessTask started failed")
|
||||
|
||||
|
||||
@task_postrun.connect
|
||||
def task_postrun_handler(
|
||||
sender=None, task_id=None, task=None, retval=None, state=None, **kwargs
|
||||
sender=None,
|
||||
task_id=None,
|
||||
task=None,
|
||||
retval=None,
|
||||
state=None,
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Updates the result of the PaperlessTask.
|
||||
@@ -591,7 +587,7 @@ def task_postrun_handler(
|
||||
task_instance.result = retval
|
||||
task_instance.date_done = timezone.now()
|
||||
task_instance.save()
|
||||
except Exception as e: # pragma: no cover
|
||||
except Exception: # pragma: no cover
|
||||
# Don't let an exception in the signal handlers prevent
|
||||
# a document from being consumed.
|
||||
logger.error(f"Updating PaperlessTask failed: {e}", exc_info=True)
|
||||
logger.exception("Updating PaperlessTask failed")
|
||||
|
Reference in New Issue
Block a user