mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Enable ruff FBT001 check and fix resulting complaints
This commit is contained in:
parent
4726be0d51
commit
4ebed423a8
@ -33,6 +33,7 @@ extend-select = [
|
|||||||
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
|
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
|
||||||
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
|
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
|
||||||
"FBT002", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
"FBT002", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
||||||
|
"FBT001", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
|
||||||
]
|
]
|
||||||
ignore = ["DJ001", "SIM105", "RUF012"]
|
ignore = ["DJ001", "SIM105", "RUF012"]
|
||||||
|
|
||||||
|
@ -248,15 +248,15 @@ class Command(BaseCommand):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if settings.CONSUMER_POLLING == 0 and INotify:
|
if settings.CONSUMER_POLLING == 0 and INotify:
|
||||||
self.handle_inotify(directory, recursive, options["testing"])
|
self.handle_inotify(directory, recursive, is_testing=options["testing"])
|
||||||
else:
|
else:
|
||||||
if INotify is None and settings.CONSUMER_POLLING == 0: # pragma: no cover
|
if INotify is None and settings.CONSUMER_POLLING == 0: # pragma: no cover
|
||||||
logger.warning("Using polling as INotify import failed")
|
logger.warning("Using polling as INotify import failed")
|
||||||
self.handle_polling(directory, recursive, options["testing"])
|
self.handle_polling(directory, recursive, is_testing=options["testing"])
|
||||||
|
|
||||||
logger.debug("Consumer exiting.")
|
logger.debug("Consumer exiting.")
|
||||||
|
|
||||||
def handle_polling(self, directory, recursive, is_testing: bool):
|
def handle_polling(self, directory, recursive, *, is_testing: bool):
|
||||||
logger.info(f"Polling directory for changes: {directory}")
|
logger.info(f"Polling directory for changes: {directory}")
|
||||||
|
|
||||||
timeout = None
|
timeout = None
|
||||||
@ -283,7 +283,7 @@ class Command(BaseCommand):
|
|||||||
observer.stop()
|
observer.stop()
|
||||||
observer.join()
|
observer.join()
|
||||||
|
|
||||||
def handle_inotify(self, directory, recursive, is_testing: bool):
|
def handle_inotify(self, directory, recursive, *, is_testing: bool):
|
||||||
logger.info(f"Using inotify to watch directory for changes: {directory}")
|
logger.info(f"Using inotify to watch directory for changes: {directory}")
|
||||||
|
|
||||||
timeout_ms = None
|
timeout_ms = None
|
||||||
|
@ -1872,7 +1872,7 @@ class SharedLinkView(View):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def serve_file(doc: Document, use_archive: bool, disposition: str):
|
def serve_file(*, doc: Document, use_archive: bool, disposition: str):
|
||||||
if use_archive:
|
if use_archive:
|
||||||
file_handle = doc.archive_file
|
file_handle = doc.archive_file
|
||||||
filename = doc.get_public_filename(archive=True)
|
filename = doc.get_public_filename(archive=True)
|
||||||
|
@ -150,7 +150,7 @@ class TagMailAction(BaseMailAction):
|
|||||||
A mail action that tags mails after processing.
|
A mail action that tags mails after processing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, parameter: str, supports_gmail_labels: bool):
|
def __init__(self, parameter: str, *, supports_gmail_labels: bool):
|
||||||
# The custom tag should look like "apple:<color>"
|
# The custom tag should look like "apple:<color>"
|
||||||
if "apple:" in parameter.lower():
|
if "apple:" in parameter.lower():
|
||||||
_, self.color = parameter.split(":")
|
_, self.color = parameter.split(":")
|
||||||
@ -268,7 +268,7 @@ def apply_mail_action(
|
|||||||
mailbox_login(M, account)
|
mailbox_login(M, account)
|
||||||
M.folder.set(rule.folder)
|
M.folder.set(rule.folder)
|
||||||
|
|
||||||
action = get_rule_action(rule, supports_gmail_labels)
|
action = get_rule_action(rule, supports_gmail_labels=supports_gmail_labels)
|
||||||
try:
|
try:
|
||||||
action.post_consume(M, message_uid, rule.action_parameter)
|
action.post_consume(M, message_uid, rule.action_parameter)
|
||||||
except errors.ImapToolsError:
|
except errors.ImapToolsError:
|
||||||
@ -356,7 +356,7 @@ def queue_consumption_tasks(
|
|||||||
).delay()
|
).delay()
|
||||||
|
|
||||||
|
|
||||||
def get_rule_action(rule: MailRule, supports_gmail_labels: bool) -> BaseMailAction:
|
def get_rule_action(rule: MailRule, *, supports_gmail_labels: bool) -> BaseMailAction:
|
||||||
"""
|
"""
|
||||||
Returns a BaseMailAction instance for the given rule.
|
Returns a BaseMailAction instance for the given rule.
|
||||||
"""
|
"""
|
||||||
@ -370,12 +370,15 @@ def get_rule_action(rule: MailRule, supports_gmail_labels: bool) -> BaseMailActi
|
|||||||
elif rule.action == MailRule.MailAction.MARK_READ:
|
elif rule.action == MailRule.MailAction.MARK_READ:
|
||||||
return MarkReadMailAction()
|
return MarkReadMailAction()
|
||||||
elif rule.action == MailRule.MailAction.TAG:
|
elif rule.action == MailRule.MailAction.TAG:
|
||||||
return TagMailAction(rule.action_parameter, supports_gmail_labels)
|
return TagMailAction(
|
||||||
|
rule.action_parameter,
|
||||||
|
supports_gmail_labels=supports_gmail_labels,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Unknown action.") # pragma: no cover
|
raise NotImplementedError("Unknown action.") # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
def make_criterias(rule: MailRule, supports_gmail_labels: bool):
|
def make_criterias(rule: MailRule, *, supports_gmail_labels: bool):
|
||||||
"""
|
"""
|
||||||
Returns criteria to be applied to MailBox.fetch for the given rule.
|
Returns criteria to be applied to MailBox.fetch for the given rule.
|
||||||
"""
|
"""
|
||||||
@ -393,7 +396,10 @@ def make_criterias(rule: MailRule, supports_gmail_labels: bool):
|
|||||||
if rule.filter_body:
|
if rule.filter_body:
|
||||||
criterias["body"] = rule.filter_body
|
criterias["body"] = rule.filter_body
|
||||||
|
|
||||||
rule_query = get_rule_action(rule, supports_gmail_labels).get_criteria()
|
rule_query = get_rule_action(
|
||||||
|
rule,
|
||||||
|
supports_gmail_labels=supports_gmail_labels,
|
||||||
|
).get_criteria()
|
||||||
if isinstance(rule_query, dict):
|
if isinstance(rule_query, dict):
|
||||||
if len(rule_query) or len(criterias):
|
if len(rule_query) or len(criterias):
|
||||||
return AND(**rule_query, **criterias)
|
return AND(**rule_query, **criterias)
|
||||||
@ -563,7 +569,7 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
total_processed_files += self._handle_mail_rule(
|
total_processed_files += self._handle_mail_rule(
|
||||||
M,
|
M,
|
||||||
rule,
|
rule,
|
||||||
supports_gmail_labels,
|
supports_gmail_labels=supports_gmail_labels,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.exception(
|
self.log.exception(
|
||||||
@ -588,6 +594,7 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
self,
|
self,
|
||||||
M: MailBox,
|
M: MailBox,
|
||||||
rule: MailRule,
|
rule: MailRule,
|
||||||
|
*,
|
||||||
supports_gmail_labels: bool,
|
supports_gmail_labels: bool,
|
||||||
):
|
):
|
||||||
folders = [rule.folder]
|
folders = [rule.folder]
|
||||||
@ -616,7 +623,7 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
f"does not exist in account {rule.account}",
|
f"does not exist in account {rule.account}",
|
||||||
) from err
|
) from err
|
||||||
|
|
||||||
criterias = make_criterias(rule, supports_gmail_labels)
|
criterias = make_criterias(rule, supports_gmail_labels=supports_gmail_labels)
|
||||||
|
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
f"Rule {rule}: Searching folder with criteria {criterias}",
|
f"Rule {rule}: Searching folder with criteria {criterias}",
|
||||||
|
@ -981,7 +981,7 @@ class TestMail(
|
|||||||
MailError,
|
MailError,
|
||||||
TagMailAction,
|
TagMailAction,
|
||||||
"apple:black",
|
"apple:black",
|
||||||
False,
|
supports_gmail_labels=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_handle_mail_account_tag_applemail(self):
|
def test_handle_mail_account_tag_applemail(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user