Skip to content

Commit

Permalink
Fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
outa committed Nov 1, 2022
1 parent ec9b740 commit 7b9b619
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
13 changes: 11 additions & 2 deletions jrnl/Entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
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
Expand Down
7 changes: 5 additions & 2 deletions jrnl/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion jrnl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
24 changes: 18 additions & 6 deletions jrnl/jrnl.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion jrnl/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
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,
Expand Down
8 changes: 6 additions & 2 deletions jrnl/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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:
Expand All @@ -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:
Expand Down

0 comments on commit 7b9b619

Please sign in to comment.