summaryrefslogtreecommitdiffstats
path: root/jrnl
diff options
context:
space:
mode:
authorJonathan Wren <jonathan@nowandwren.com>2022-11-05 15:56:46 -0700
committerGitHub <noreply@github.com>2022-11-05 15:56:46 -0700
commitb508ed6c9a307a50800894663f0725589a11b229 (patch)
tree5575e0da46fcc0b836f9a8b7d1332daa93d330aa /jrnl
parent1e694957284034818822ba6b330af716b45ac2e8 (diff)
Add `simplify` plugin to linting checks (#1630)
* add simplify plugin for flakeheaven * update lock file * fix linting issues in current codebase
Diffstat (limited to 'jrnl')
-rw-r--r--jrnl/DayOneJournal.py32
-rw-r--r--jrnl/EncryptedJournal.py6
-rw-r--r--jrnl/Journal.py5
-rw-r--r--jrnl/install.py5
-rw-r--r--jrnl/jrnl.py3
-rw-r--r--jrnl/messages/__init__.py12
-rw-r--r--jrnl/plugins/markdown_exporter.py4
7 files changed, 24 insertions, 43 deletions
diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py
index 4806bdbf..e65ca8d9 100644
--- a/jrnl/DayOneJournal.py
+++ b/jrnl/DayOneJournal.py
@@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
+import contextlib
import datetime
import fnmatch
import os
@@ -75,40 +76,23 @@ class DayOne(Journal.Journal):
]
"""Extended DayOne attributes"""
- try:
+ # just ignore it if the keys don't exist
+ with contextlib.suppress(KeyError):
entry.creator_device_agent = dict_entry["Creator"][
"Device Agent"
]
- except: # noqa: E722
- pass
- try:
- entry.creator_generation_date = dict_entry["Creator"][
- "Generation Date"
- ]
- except: # noqa: E722
- entry.creator_generation_date = date
- try:
entry.creator_host_name = dict_entry["Creator"]["Host Name"]
- except: # noqa: E722
- pass
- try:
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
- except: # noqa: E722
- pass
- try:
entry.creator_software_agent = dict_entry["Creator"][
"Software Agent"
]
- except: # noqa: E722
- pass
- try:
entry.location = dict_entry["Location"]
- except: # noqa: E722
- pass
- try:
entry.weather = dict_entry["Weather"]
- except: # noqa: E722
- pass
+
+ entry.creator_generation_date = dict_entry.get("Creator", {}).get(
+ "Generation Date", date
+ )
+
self.entries.append(entry)
self.sort()
return self
diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py
index 8b742d29..74fdbdf8 100644
--- a/jrnl/EncryptedJournal.py
+++ b/jrnl/EncryptedJournal.py
@@ -2,6 +2,7 @@
# License: https://www.gnu.org/licenses/gpl-3.0.html
import base64
+import contextlib
import hashlib
import logging
import os
@@ -202,10 +203,9 @@ def set_keychain(journal_name, password):
import keyring
if password is None:
- try:
+ cm = contextlib.suppress(keyring.errors.KeyringError)
+ with cm:
keyring.delete_password("jrnl", journal_name)
- except keyring.errors.KeyringError:
- pass
else:
try:
keyring.set_password("jrnl", journal_name, password)
diff --git a/jrnl/Journal.py b/jrnl/Journal.py
index 2fa1d465..3521fbaf 100644
--- a/jrnl/Journal.py
+++ b/jrnl/Journal.py
@@ -120,10 +120,7 @@ class Journal:
def validate_parsing(self):
"""Confirms that the jrnl is still parsed correctly after being dumped to text."""
new_entries = self._parse(self._to_text())
- for i, entry in enumerate(self.entries):
- if entry != new_entries[i]:
- return False
- return True
+ return all(entry == new_entries[i] for i, entry in enumerate(self.entries))
@staticmethod
def create_file(filename):
diff --git a/jrnl/install.py b/jrnl/install.py
index a37e51f9..b5ec636e 100644
--- a/jrnl/install.py
+++ b/jrnl/install.py
@@ -1,6 +1,7 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
+import contextlib
import glob
import logging
import os
@@ -128,10 +129,8 @@ def install() -> dict:
# If the folder doesn't exist, create it
path = os.path.split(journal_path)[0]
- try:
+ with contextlib.suppress(OSError):
os.makedirs(path)
- except OSError:
- pass
# Encrypt it?
encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False)
diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py
index 39c25b3f..c79d46e0 100644
--- a/jrnl/jrnl.py
+++ b/jrnl/jrnl.py
@@ -240,7 +240,8 @@ def _get_editor_template(config: dict, **kwargs) -> str:
template_path = expand_path(config["template"])
try:
- template = open(template_path).read()
+ with open(template_path) as f:
+ template = f.read()
logging.debug("Write mode: template loaded: %s", template)
except OSError:
logging.error("Write mode: template not loaded")
diff --git a/jrnl/messages/__init__.py b/jrnl/messages/__init__.py
index 381ee332..6bdd9a11 100644
--- a/jrnl/messages/__init__.py
+++ b/jrnl/messages/__init__.py
@@ -1,10 +1,10 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
-from jrnl.messages.Message import Message
-from jrnl.messages.MsgStyle import MsgStyle
-from jrnl.messages.MsgText import MsgText
+from jrnl.messages import Message
+from jrnl.messages import MsgStyle
+from jrnl.messages import MsgText
-Message = Message
-MsgStyle = MsgStyle
-MsgText = MsgText
+Message = Message.Message
+MsgStyle = MsgStyle.MsgStyle
+MsgText = MsgText.MsgText
diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py
index 8f0d07b4..8c079c63 100644
--- a/jrnl/plugins/markdown_exporter.py
+++ b/jrnl/plugins/markdown_exporter.py
@@ -83,11 +83,11 @@ class MarkdownExporter(TextExporter):
out = []
year, month = -1, -1
for e in journal.entries:
- if not e.date.year == year:
+ if e.date.year != year:
year = e.date.year
out.append("# " + str(year))
out.append("")
- if not e.date.month == month:
+ if e.date.month != month:
month = e.date.month
out.append("## " + e.date.strftime("%B"))
out.append("")