mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 09:28:31 +02:00
Fix linters
This commit is contained in:
parent
9e8ec6d31e
commit
c87af82366
6 changed files with 46 additions and 14 deletions
|
@ -5,16 +5,25 @@ import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import ansiwrap
|
import ansiwrap
|
||||||
|
|
||||||
from .Journal import Journal
|
|
||||||
from .color import colorize
|
from .color import colorize
|
||||||
from .color import highlight_tags_with_background_color
|
from .color import highlight_tags_with_background_color
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .Journal import Journal
|
||||||
|
|
||||||
|
|
||||||
class Entry:
|
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.journal = journal # Reference to journal mainly to access its config
|
||||||
self.date = date or datetime.datetime.now()
|
self.date = date or datetime.datetime.now()
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
|
@ -4,12 +4,15 @@
|
||||||
import re
|
import re
|
||||||
from string import punctuation
|
from string import punctuation
|
||||||
from string import whitespace
|
from string import whitespace
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
|
|
||||||
from jrnl.Entry import Entry
|
|
||||||
from jrnl.os_compat import on_windows
|
from jrnl.os_compat import on_windows
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from jrnl.Entry import Entry
|
||||||
|
|
||||||
if on_windows():
|
if on_windows():
|
||||||
colorama.init()
|
colorama.init()
|
||||||
|
|
||||||
|
@ -28,7 +31,7 @@ def colorize(string: str, color: str, bold: bool = False) -> str:
|
||||||
|
|
||||||
|
|
||||||
def highlight_tags_with_background_color(
|
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:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Takes a string and colorizes the tags in it based upon the config value for
|
Takes a string and colorizes the tags in it based upon the config value for
|
||||||
|
|
|
@ -194,7 +194,9 @@ def is_config_json(config_path: str) -> bool:
|
||||||
return config_file.strip().startswith("{")
|
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
|
"""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 config['journals'][scope] is just a string pointing to a journal file,
|
||||||
or within the scope"""
|
or within the scope"""
|
||||||
|
|
24
jrnl/jrnl.py
24
jrnl/jrnl.py
|
@ -1,8 +1,8 @@
|
||||||
# Copyright © 2012-2022 jrnl contributors
|
# Copyright © 2012-2022 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
from argparse import Namespace
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from argparse import Namespace
|
||||||
|
|
||||||
from jrnl import install
|
from jrnl import install
|
||||||
from jrnl import plugins
|
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.editor import get_text_from_stdin
|
||||||
from jrnl.Entry import Entry
|
from jrnl.Entry import Entry
|
||||||
from jrnl.exception import JrnlException
|
from jrnl.exception import JrnlException
|
||||||
from jrnl.Journal import open_journal
|
|
||||||
from jrnl.Journal import Journal
|
from jrnl.Journal import Journal
|
||||||
|
from jrnl.Journal import open_journal
|
||||||
from jrnl.messages import Message
|
from jrnl.messages import Message
|
||||||
from jrnl.messages import MsgStyle
|
from jrnl.messages import MsgStyle
|
||||||
from jrnl.messages import MsgText
|
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]
|
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
|
1. Send the given journal entries to the user-configured editor
|
||||||
2. Print out stats on any modifications to journal
|
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()
|
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 = {
|
stats = {
|
||||||
"added": len(journal) - old_stats["count"],
|
"added": len(journal) - old_stats["count"],
|
||||||
"deleted": old_stats["count"] - len(journal),
|
"deleted": old_stats["count"] - len(journal),
|
||||||
|
@ -399,7 +403,9 @@ def _get_predit_stats(journal: Journal) -> dict[str, int]:
|
||||||
return {"count": len(journal)}
|
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)
|
entries_to_delete = journal.prompt_action_entries(MsgText.DeleteEntryQuestion)
|
||||||
|
|
||||||
if entries_to_delete:
|
if entries_to_delete:
|
||||||
|
@ -409,7 +415,13 @@ def _delete_search_results(journal: Journal, old_entries: list[Entry], **kwargs)
|
||||||
journal.write()
|
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
|
# separate entries we are not editing
|
||||||
other_entries = _other_entries(journal, old_entries)
|
other_entries = _other_entries(journal, old_entries)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,9 @@ from jrnl.messages import MsgStyle
|
||||||
from jrnl.messages import MsgText
|
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(
|
print_msg(
|
||||||
Message(
|
Message(
|
||||||
MsgText.DeprecatedCommand,
|
MsgText.DeprecatedCommand,
|
||||||
|
|
|
@ -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)
|
DEFAULT_PAST = datetime.datetime(FAKE_YEAR, 1, 1, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def __get_pdt_calendar() -> "pdt.Calendar":
|
def __get_pdt_calendar():
|
||||||
try:
|
try:
|
||||||
import parsedatetime.parsedatetime_consts as pdt
|
import parsedatetime.parsedatetime_consts as pdt
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -22,7 +22,11 @@ def __get_pdt_calendar() -> "pdt.Calendar":
|
||||||
|
|
||||||
|
|
||||||
def parse(
|
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:
|
) -> datetime.datetime | None:
|
||||||
"""Parses a string containing a fuzzy date and returns a datetime.datetime object"""
|
"""Parses a string containing a fuzzy date and returns a datetime.datetime object"""
|
||||||
if not date_str:
|
if not date_str:
|
||||||
|
|
Loading…
Add table
Reference in a new issue