Fix linters

This commit is contained in:
outa 2022-10-11 18:11:35 +02:00
parent 9e8ec6d31e
commit c87af82366
6 changed files with 46 additions and 14 deletions

View file

@ -5,16 +5,25 @@ import datetime
import logging
import os
import re
from typing import TYPE_CHECKING
import ansiwrap
from .Journal import Journal
from .color import colorize
from .color import highlight_tags_with_background_color
if TYPE_CHECKING:
from .Journal import Journal
class Entry:
def __init__(self, journal: Journal, date: datetime.datetime | None = None, text: str = "", starred: bool = False):
def __init__(
self,
journal: "Journal",
date: datetime.datetime | None = None,
text: str = "",
starred: bool = False,
):
self.journal = journal # Reference to journal mainly to access its config
self.date = date or datetime.datetime.now()
self.text = text

View file

@ -4,12 +4,15 @@
import re
from string import punctuation
from string import whitespace
from typing import TYPE_CHECKING
import colorama
from jrnl.Entry import Entry
from jrnl.os_compat import on_windows
if TYPE_CHECKING:
from jrnl.Entry import Entry
if on_windows():
colorama.init()
@ -28,7 +31,7 @@ def colorize(string: str, color: str, bold: bool = False) -> str:
def highlight_tags_with_background_color(
entry: Entry, text: str, color: str, is_title: bool = False
entry: "Entry", text: str, color: str, is_title: bool = False
) -> str:
"""
Takes a string and colorizes the tags in it based upon the config value for

View file

@ -194,7 +194,9 @@ def is_config_json(config_path: str) -> bool:
return config_file.strip().startswith("{")
def update_config(config: dict, new_config: dict, scope: str | None, force_local: bool = False) -> None:
def update_config(
config: dict, new_config: dict, scope: str | None, force_local: bool = False
) -> None:
"""Updates a config dict with new values - either global if scope is None
or config['journals'][scope] is just a string pointing to a journal file,
or within the scope"""

View file

@ -1,8 +1,8 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
from argparse import Namespace
import logging
import sys
from argparse import Namespace
from jrnl import install
from jrnl import plugins
@ -15,8 +15,8 @@ from jrnl.editor import get_text_from_editor
from jrnl.editor import get_text_from_stdin
from jrnl.Entry import Entry
from jrnl.exception import JrnlException
from jrnl.Journal import open_journal
from jrnl.Journal import Journal
from jrnl.Journal import open_journal
from jrnl.messages import Message
from jrnl.messages import MsgStyle
from jrnl.messages import MsgText
@ -322,7 +322,9 @@ def _other_entries(journal: Journal, entries: list[Entry]) -> list[Entry]:
return [e for e in entries if e not in journal.entries]
def _edit_search_results(config: dict, journal: Journal, old_entries: list[Entry], **kwargs) -> None:
def _edit_search_results(
config: dict, journal: Journal, old_entries: list[Entry], **kwargs
) -> None:
"""
1. Send the given journal entries to the user-configured editor
2. Print out stats on any modifications to journal
@ -356,7 +358,9 @@ def _edit_search_results(config: dict, journal: Journal, old_entries: list[Entry
journal.write()
def _print_edited_summary(journal: Journal, old_stats: dict[str, int], **kwargs) -> None:
def _print_edited_summary(
journal: Journal, old_stats: dict[str, int], **kwargs
) -> None:
stats = {
"added": len(journal) - old_stats["count"],
"deleted": old_stats["count"] - len(journal),
@ -399,7 +403,9 @@ def _get_predit_stats(journal: Journal) -> dict[str, int]:
return {"count": len(journal)}
def _delete_search_results(journal: Journal, old_entries: list[Entry], **kwargs) -> None:
def _delete_search_results(
journal: Journal, old_entries: list[Entry], **kwargs
) -> None:
entries_to_delete = journal.prompt_action_entries(MsgText.DeleteEntryQuestion)
if entries_to_delete:
@ -409,7 +415,13 @@ def _delete_search_results(journal: Journal, old_entries: list[Entry], **kwargs)
journal.write()
def _change_time_search_results(args: Namespace, journal: Journal, old_entries: list[Entry], no_prompt: bool = False, **kwargs) -> None:
def _change_time_search_results(
args: Namespace,
journal: Journal,
old_entries: list[Entry],
no_prompt: bool = False,
**kwargs
) -> None:
# separate entries we are not editing
other_entries = _other_entries(journal, old_entries)

View file

@ -12,7 +12,9 @@ from jrnl.messages import MsgStyle
from jrnl.messages import MsgText
def deprecated_cmd(old_cmd: str, new_cmd: str, callback: Callable | None = None, **kwargs) -> None:
def deprecated_cmd(
old_cmd: str, new_cmd: str, callback: Callable | None = None, **kwargs
) -> None:
print_msg(
Message(
MsgText.DeprecatedCommand,

View file

@ -8,7 +8,7 @@ DEFAULT_FUTURE = datetime.datetime(FAKE_YEAR, 12, 31, 23, 59, 59)
DEFAULT_PAST = datetime.datetime(FAKE_YEAR, 1, 1, 0, 0)
def __get_pdt_calendar() -> "pdt.Calendar":
def __get_pdt_calendar():
try:
import parsedatetime.parsedatetime_consts as pdt
except ImportError:
@ -22,7 +22,11 @@ def __get_pdt_calendar() -> "pdt.Calendar":
def parse(
date_str: str | datetime.datetime, inclusive: bool = False, default_hour: int | None = None, default_minute: int | None = None, bracketed: bool = False
date_str: str | datetime.datetime,
inclusive: bool = False,
default_hour: int | None = None,
default_minute: int | None = None,
bracketed: bool = False,
) -> datetime.datetime | None:
"""Parses a string containing a fuzzy date and returns a datetime.datetime object"""
if not date_str: