summaryrefslogtreecommitdiffstats
path: root/jrnl
diff options
context:
space:
mode:
authorMicah Jerome Ellison <micah.jerome.ellison@gmail.com>2023-07-15 12:35:10 -0700
committerGitHub <noreply@github.com>2023-07-15 12:35:10 -0700
commit34c7903300e84b53c86c2792196d069b15cb5888 (patch)
tree112341efb023a881f618cd090e40e017527ae4cf /jrnl
parentdd09ece4e776d3757c315e87bb649438603890fa (diff)
Replace flake8 and isort with ruff linter and add `black --check` to linting step (#1763)
* Add ruff * Add ruff config * Add ruff rules that look useful and are already passing * Add more ruff rules after talking with Jonathan * Add line length exception for acceptably long indented line * Resolve ruff line length 88 rule in args. Changing small lines but adding a noqa ignore directive to longer lines that look best as they are. Their dedented length is still less than 88 * poe format * Resolve all remaining ruff line length errors * Replace flake* and isort with ruff calls * Add black --check as final lint step. ruff catches most but not all black formatting issues * Remove unneeded flakeheaven setting * Remove flake* and isort now that ruff is handling all their business * Update pyproject, lockfile with latest version of ruff * Document each ruff rule with comment * Add black --version call before black --check * Remove extraneous period
Diffstat (limited to 'jrnl')
-rw-r--r--jrnl/args.py29
-rw-r--r--jrnl/commands.py2
-rw-r--r--jrnl/config.py5
-rw-r--r--jrnl/controller.py8
-rw-r--r--jrnl/editor.py3
-rw-r--r--jrnl/install.py12
-rw-r--r--jrnl/journals/Entry.py4
-rw-r--r--jrnl/journals/FolderJournal.py3
-rw-r--r--jrnl/journals/Journal.py12
-rw-r--r--jrnl/messages/MsgText.py4
-rw-r--r--jrnl/override.py3
-rw-r--r--jrnl/plugins/fancy_exporter.py2
-rw-r--r--jrnl/plugins/tag_exporter.py2
-rw-r--r--jrnl/plugins/util.py3
-rw-r--r--jrnl/plugins/yaml_exporter.py14
-rw-r--r--jrnl/time.py10
16 files changed, 71 insertions, 45 deletions
diff --git a/jrnl/args.py b/jrnl/args.py
index 9b7dafe7..53a77462 100644
--- a/jrnl/args.py
+++ b/jrnl/args.py
@@ -78,7 +78,7 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
"""
We gratefully thank all contributors!
Come see the whole list of code and financial contributors at https://github.com/jrnl-org/jrnl
- And special thanks to Bad Lip Reading for the Yoda joke in the Writing section above :)"""
+ And special thanks to Bad Lip Reading for the Yoda joke in the Writing section above :)""" # noqa: E501
),
)
@@ -214,7 +214,8 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
composing.add_argument(
"--template",
dest="template",
- help="Path to template file. Can be a local path, absolute path, or a path relative to $XDG_DATA_HOME/jrnl/templates/",
+ help="Path to template file. Can be a local path, absolute path, or a path "
+ "relative to $XDG_DATA_HOME/jrnl/templates/",
)
read_msg = (
@@ -265,13 +266,15 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
"-contains",
dest="contains",
metavar="TEXT",
- help="Show entries containing specific text (put quotes around text with spaces)",
+ help="Show entries containing specific text (put quotes around text with "
+ "spaces)",
)
reading.add_argument(
"-and",
dest="strict",
action="store_true",
- help='Show only entries that match all conditions, like saying "x AND y" (default: OR)',
+ help='Show only entries that match all conditions, like saying "x AND y" '
+ "(default: OR)",
)
reading.add_argument(
"-starred",
@@ -290,7 +293,8 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
dest="limit",
default=None,
metavar="NUMBER",
- help="Show a maximum of NUMBER entries (note: '-n 3' and '-3' have the same effect)",
+ help="Show a maximum of NUMBER entries (note: '-n 3' and '-3' have the same "
+ "effect)",
nargs="?",
type=int,
)
@@ -308,8 +312,12 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
),
)
- search_options_msg = """ These help you do various tasks with the selected entries from your search.
- If used on their own (with no search), they will act on your entire journal"""
+ search_options_msg = (
+ " " # Preserves indentation
+ """
+ These help you do various tasks with the selected entries from your search.
+ If used on their own (with no search), they will act on your entire journal"""
+ )
exporting = parser.add_argument_group(
"Searching Options", textwrap.dedent(search_options_msg)
)
@@ -360,7 +368,8 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
"--tags",
dest="tags",
action="store_true",
- help="Alias for '--format tags'. Returns a list of all tags and number of occurrences",
+ help="Alias for '--format tags'. Returns a list of all tags and number of "
+ "occurrences",
)
exporting.add_argument(
"--short",
@@ -400,7 +409,7 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
\t jrnl --config-override editor "nano" \n
\t - Override color selections\n
\t jrnl --config-override colors.body blue --config-override colors.title green
- """,
+ """, # noqa: E501
)
config_overrides.add_argument(
"--co",
@@ -430,7 +439,7 @@ def parse_args(args: list[str] = []) -> argparse.Namespace:
\t jrnl --config-file /home/user1/work_config.yaml
\t - Use a personal config file stored on a thumb drive: \n
\t jrnl --config-file /media/user1/my-thumb-drive/personal_config.yaml
- """,
+ """, # noqa: E501
)
alternate_config.add_argument(
diff --git a/jrnl/commands.py b/jrnl/commands.py
index 83618ce2..5ba449e4 100644
--- a/jrnl/commands.py
+++ b/jrnl/commands.py
@@ -142,7 +142,7 @@ def postconfig_encrypt(
def postconfig_decrypt(
args: argparse.Namespace, config: dict, original_config: dict
) -> int:
- """Decrypts into new file. If filename is not set, we encrypt the journal file itself."""
+ """Decrypts to file. If filename is not set, we encrypt the journal file itself."""
from jrnl.config import update_config
from jrnl.install import save_config
from jrnl.journals import open_journal
diff --git a/jrnl/config.py b/jrnl/config.py
index a2f0885c..1fdded19 100644
--- a/jrnl/config.py
+++ b/jrnl/config.py
@@ -37,9 +37,10 @@ def make_yaml_valid_dict(input: list) -> dict:
The dict is created through the yaml loader, with the assumption that
"input[0]: input[1]" is valid yaml.
- :param input: list of configuration keys in dot-notation and their respective values.
+ :param input: list of configuration keys in dot-notation and their respective values
:type input: list
- :return: A single level dict of the configuration keys in dot-notation and their respective desired values
+ :return: A single level dict of the configuration keys in dot-notation and their
+ respective desired values
:rtype: dict
"""
diff --git a/jrnl/controller.py b/jrnl/controller.py
index e0e222b5..2e36551b 100644
--- a/jrnl/controller.py
+++ b/jrnl/controller.py
@@ -34,9 +34,9 @@ if TYPE_CHECKING:
def run(args: "Namespace"):
"""
Flow:
- 1. Run standalone command if it doesn't require config (help, version, etc), then exit
+ 1. Run standalone command if it doesn't need config (help, version, etc), then exit
2. Load config
- 3. Run standalone command if it does require config (encrypt, decrypt, etc), then exit
+ 3. Run standalone command if it does need config (encrypt, decrypt, etc), then exit
4. Load specified journal
5. Start append mode, or search mode
6. Perform actions with results from search mode (if needed)
@@ -181,7 +181,9 @@ def append_mode(args: "Namespace", config: dict, journal: "Journal", **kwargs) -
def _get_template(args, config) -> str:
# Read template file and pass as raw text into the composer
logging.debug(
- f"Get template:\n--template: {args.template}\nfrom config: {config.get('template')}"
+ "Get template:\n"
+ f"--template: {args.template}\n"
+ f"from config: {config.get('template')}"
)
template_path = args.template or config.get("template")
diff --git a/jrnl/editor.py b/jrnl/editor.py
index cbcf6207..61afed3c 100644
--- a/jrnl/editor.py
+++ b/jrnl/editor.py
@@ -81,7 +81,8 @@ def get_template_path(template_path: str, jrnl_template_dir: str) -> str:
actual_template_path = os.path.join(jrnl_template_dir, template_path)
if not os.path.exists(actual_template_path):
logging.debug(
- f"Couldn't open {actual_template_path}. Treating template path like a local / abs path."
+ f"Couldn't open {actual_template_path}. "
+ "Treating template path like a local / abs path."
)
actual_template_path = absolute_path(template_path)
diff --git a/jrnl/install.py b/jrnl/install.py
index f9d9ac1a..4033c33c 100644
--- a/jrnl/install.py
+++ b/jrnl/install.py
@@ -31,11 +31,11 @@ from jrnl.upgrade import is_old_version
def upgrade_config(config_data: dict, alt_config_path: str | None = None) -> None:
- """Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
- This essentially automatically ports jrnl installations if new config parameters are introduced in later
- versions.
- Also checks for existence of and difference in version number between config dict and current jrnl version,
- and if so, update the config file accordingly.
+ """Checks if there are keys missing in a given config dict, and if so, updates the
+ config file accordingly. This essentially automatically ports jrnl installations
+ if new config parameters are introduced in later versions. Also checks for
+ existence of and difference in version number between config dict
+ and current jrnl version, and if so, update the config file accordingly.
Supply alt_config_path if using an alternate config through --config-file."""
default_config = get_default_config()
missing_keys = set(default_config).difference(config_data)
@@ -167,7 +167,7 @@ def install() -> dict:
def _initialize_autocomplete() -> None:
- # readline is not included in Windows Active Python and perhaps some other distributions
+ # readline is not included in Windows Active Python and perhaps some other distss
if sys.modules.get("readline"):
import readline
diff --git a/jrnl/journals/Entry.py b/jrnl/journals/Entry.py
index 93b825f8..5b35d734 100644
--- a/jrnl/journals/Entry.py
+++ b/jrnl/journals/Entry.py
@@ -89,7 +89,7 @@ class Entry:
}
def __str__(self):
- """Returns a string representation of the entry to be written into a journal file."""
+ """Returns string representation of the entry to be written to journal file."""
date_str = self.date.strftime(self.journal.config["timeformat"])
title = "[{}] {}".format(date_str, self.title.rstrip("\n "))
if self.starred:
@@ -233,7 +233,7 @@ SENTENCE_SPLITTER = re.compile(
\s+ # AND a sequence of required spaces.
)
|[\uFF01\uFF0E\uFF1F\uFF61\u3002] # CJK full/half width terminals usually do not have following spaces.
- """,
+ """, # noqa: E501
re.VERBOSE,
)
diff --git a/jrnl/journals/FolderJournal.py b/jrnl/journals/FolderJournal.py
index 0d497fb8..c6faf1e0 100644
--- a/jrnl/journals/FolderJournal.py
+++ b/jrnl/journals/FolderJournal.py
@@ -122,7 +122,8 @@ class Folder(Journal):
@staticmethod
def _get_files(journal_path: str) -> list[str]:
- """Searches through sub directories starting with journal_path and find all text files that look like entries"""
+ """Searches through sub directories starting with journal_path and find all text
+ files that look like entries"""
for year_folder in Folder._get_year_folders(pathlib.Path(journal_path)):
for month_folder in Folder._get_month_folders(year_folder):
yield from Folder._get_day_files(month_folder)
diff --git a/jrnl/journals/Journal.py b/jrnl/journals/Journal.py
index bd72788b..d1054814 100644
--- a/jrnl/journals/Journal.py
+++ b/jrnl/journals/Journal.py
@@ -102,7 +102,7 @@ class Journal:
return self.encryption_method.encrypt(text)
def open(self, filename: str | None = None) -> "Journal":
- """Opens the journal file defined in the config and parses it into a list of Entries.
+ """Opens the journal file and parses it into a list of Entries
Entries have the form (date, title, body)."""
filename = filename or self.config["journal"]
dirname = os.path.dirname(filename)
@@ -144,7 +144,7 @@ class Journal:
self._store(filename, text)
def validate_parsing(self) -> bool:
- """Confirms that the jrnl is still parsed correctly after being dumped to text."""
+ """Confirms that the jrnl is still parsed correctly after conversion to text."""
new_entries = self._parse(self._to_text())
return all(entry == new_entries[i] for i, entry in enumerate(self.entries))
@@ -225,8 +225,9 @@ class Journal:
@property
def tags(self) -> list[Tag]:
"""Returns a set of tuples (count, tag) for all tags present in the journal."""
- # Astute reader: should the following line leave you as puzzled as me the first time
- # I came across this construction, worry not and embrace the ensuing moment of enlightment.
+ # Astute reader: should the following line leave you as puzzled as me the first
+ # time I came across this construction, worry not and embrace the ensuing moment
+ # of enlightment.
tags = [tag for entry in self.entries for tag in set(entry.tags)]
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]
tag_counts = {(tags.count(tag), tag) for tag in tags}
@@ -343,7 +344,8 @@ class Journal:
def new_entry(self, raw: str, date=None, sort: bool = True) -> Entry:
"""Constructs a new entry from some raw text input.
- If a date is given, it will parse and use this, otherwise scan for a date in the input first.
+ If a date is given, it will parse and use this, otherwise scan for a date in
+ the input first.
"""
raw = raw.replace("\\n ", "\n").replace("\\n", "\n")
diff --git a/jrnl/messages/MsgText.py b/jrnl/messages/MsgText.py
index c8ac5b04..9361781d 100644
--- a/jrnl/messages/MsgText.py
+++ b/jrnl/messages/MsgText.py
@@ -43,8 +43,8 @@ class MsgText(Enum):
Do you want to encrypt your journal? (You can always change this later)
"""
UseColorsQuestion = """
- Do you want jrnl to use colors when displaying entries? (You can always change this later)
- """
+ Do you want jrnl to use colors to display entries? (You can always change this later)
+ """ # noqa: E501 - the line is still under 88 when dedented
YesOrNoPromptDefaultYes = "[Y/n]"
YesOrNoPromptDefaultNo = "[y/N]"
ContinueUpgrade = "Continue upgrading jrnl?"
diff --git a/jrnl/override.py b/jrnl/override.py
index bc85f47e..368d1a37 100644
--- a/jrnl/override.py
+++ b/jrnl/override.py
@@ -56,7 +56,8 @@ def _recursively_apply(tree: dict, nodes: list, override_value) -> dict:
Args:
config (dict): Configuration to modify
- nodes (list): Vector of override keys; the length of the vector indicates tree depth
+ nodes (list): Vector of override keys; the length of the vector indicates tree
+ depth
override_value (str): Runtime override passed from the command-line
"""
key = nodes[0]
diff --git a/jrnl/plugins/fancy_exporter.py b/jrnl/plugins/fancy_exporter.py
index 447f1347..a6cbe361 100644
--- a/jrnl/plugins/fancy_exporter.py
+++ b/jrnl/plugins/fancy_exporter.py
@@ -18,7 +18,7 @@ if TYPE_CHECKING:
class FancyExporter(TextExporter):
- """This Exporter can convert entries and journals into text with unicode box drawing characters."""
+ """This Exporter converts entries and journals into text with unicode boxes."""
names = ["fancy", "boxed"]
extension = "txt"
diff --git a/jrnl/plugins/tag_exporter.py b/jrnl/plugins/tag_exporter.py
index b8b5eb79..c1160626 100644
--- a/jrnl/plugins/tag_exporter.py
+++ b/jrnl/plugins/tag_exporter.py
@@ -12,7 +12,7 @@ if TYPE_CHECKING:
class TagExporter(TextExporter):
- """This Exporter can lists the tags for entries and journals, exported as a plain text file."""
+ """This Exporter lists the tags for entries and journals."""
names = ["tags"]
extension = "tags"
diff --git a/jrnl/plugins/util.py b/jrnl/plugins/util.py
index ceaa0b04..180d86ea 100644
--- a/jrnl/plugins/util.py
+++ b/jrnl/plugins/util.py
@@ -10,7 +10,8 @@ if TYPE_CHECKING:
def get_tags_count(journal: "Journal") -> set[tuple[int, str]]:
"""Returns a set of tuples (count, tag) for all tags present in the journal."""
# Astute reader: should the following line leave you as puzzled as me the first time
- # I came across this construction, worry not and embrace the ensuing moment of enlightment.
+ # I came across this construction, worry not and embrace the ensuing moment of
+ # enlightment.
tags = [tag for entry in journal.entries for tag in set(entry.tags)]
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]
tag_counts = {(tags.count(tag), tag) for tag in tags}
diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py
index d960ef8a..90c14086 100644
--- a/jrnl/plugins/yaml_exporter.py
+++ b/jrnl/plugins/yaml_exporter.py
@@ -18,14 +18,15 @@ if TYPE_CHECKING:
class YAMLExporter(TextExporter):
- """This Exporter can convert entries and journals into Markdown formatted text with YAML front matter."""
+ """This Exporter converts entries and journals into Markdown formatted text with
+ YAML front matter."""
names = ["yaml"]
extension = "md"
@classmethod
def export_entry(cls, entry: "Entry", to_multifile: bool = True) -> str:
- """Returns a markdown representation of a single entry, with YAML front matter."""
+ """Returns a markdown representation of an entry, with YAML front matter."""
if to_multifile is False:
raise JrnlException(Message(MsgText.YamlMustBeDirectory, MsgStyle.ERROR))
@@ -117,7 +118,14 @@ class YAMLExporter(TextExporter):
# source directory is entry.journal.config['journal']
# output directory is...?
- return "{start}\ntitle: {title}\ndate: {date}\nstarred: {starred}\ntags: {tags}\n{dayone}body: |{body}{end}".format(
+ return (
+ "{start}\n"
+ "title: {title}\n"
+ "date: {date}\n"
+ "starred: {starred}\n"
+ "tags: {tags}\n"
+ "{dayone}body: |{body}{end}"
+ ).format(
start="---",
date=date_str,
title=entry.title,
diff --git a/jrnl/time.py b/jrnl/time.py
index dd6fcb0f..da13f1d0 100644
--- a/jrnl/time.py
+++ b/jrnl/time.py
@@ -34,8 +34,8 @@ def parse(
elif isinstance(date_str, datetime.datetime):
return date_str
- # Don't try to parse anything with 6 or fewer characters and was parsed from the existing journal.
- # It's probably a markdown footnote
+ # Don't try to parse anything with 6 or fewer characters and was parsed from the
+ # existing journal. It's probably a markdown footnote
if len(date_str) <= 6 and bracketed:
return None
@@ -82,9 +82,9 @@ def parse(
else:
date = datetime.datetime(*date[:6])
- # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year wrong.
- # Rather than this, we would like to see parsedatetime patched so we can tell it to prefer
- # past dates
+ # Ugly heuristic: if the date is more than 4 weeks in the future, we got the year
+ # wrong. Rather than this, we would like to see parsedatetime patched so we can
+ # tell it to prefer past dates
dt = datetime.datetime.now() - date
if dt.days < -28 and not year_present:
date = date.replace(date.year - 1)