mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Add simplify
plugin to linting checks (#1630)
* add simplify plugin for flakeheaven * update lock file * fix linting issues in current codebase
This commit is contained in:
parent
1e69495728
commit
b508ed6c9a
10 changed files with 55 additions and 45 deletions
|
@ -1,6 +1,7 @@
|
||||||
# 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
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import datetime
|
import datetime
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import os
|
import os
|
||||||
|
@ -75,40 +76,23 @@ class DayOne(Journal.Journal):
|
||||||
]
|
]
|
||||||
|
|
||||||
"""Extended DayOne attributes"""
|
"""Extended DayOne attributes"""
|
||||||
try:
|
# just ignore it if the keys don't exist
|
||||||
|
with contextlib.suppress(KeyError):
|
||||||
entry.creator_device_agent = dict_entry["Creator"][
|
entry.creator_device_agent = dict_entry["Creator"][
|
||||||
"Device Agent"
|
"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"]
|
entry.creator_host_name = dict_entry["Creator"]["Host Name"]
|
||||||
except: # noqa: E722
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
|
entry.creator_os_agent = dict_entry["Creator"]["OS Agent"]
|
||||||
except: # noqa: E722
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
entry.creator_software_agent = dict_entry["Creator"][
|
entry.creator_software_agent = dict_entry["Creator"][
|
||||||
"Software Agent"
|
"Software Agent"
|
||||||
]
|
]
|
||||||
except: # noqa: E722
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
entry.location = dict_entry["Location"]
|
entry.location = dict_entry["Location"]
|
||||||
except: # noqa: E722
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
entry.weather = dict_entry["Weather"]
|
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.entries.append(entry)
|
||||||
self.sort()
|
self.sort()
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import contextlib
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -202,10 +203,9 @@ def set_keychain(journal_name, password):
|
||||||
import keyring
|
import keyring
|
||||||
|
|
||||||
if password is None:
|
if password is None:
|
||||||
try:
|
cm = contextlib.suppress(keyring.errors.KeyringError)
|
||||||
|
with cm:
|
||||||
keyring.delete_password("jrnl", journal_name)
|
keyring.delete_password("jrnl", journal_name)
|
||||||
except keyring.errors.KeyringError:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
keyring.set_password("jrnl", journal_name, password)
|
keyring.set_password("jrnl", journal_name, password)
|
||||||
|
|
|
@ -120,10 +120,7 @@ class Journal:
|
||||||
def validate_parsing(self):
|
def validate_parsing(self):
|
||||||
"""Confirms that the jrnl is still parsed correctly after being dumped to text."""
|
"""Confirms that the jrnl is still parsed correctly after being dumped to text."""
|
||||||
new_entries = self._parse(self._to_text())
|
new_entries = self._parse(self._to_text())
|
||||||
for i, entry in enumerate(self.entries):
|
return all(entry == new_entries[i] for i, entry in enumerate(self.entries))
|
||||||
if entry != new_entries[i]:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_file(filename):
|
def create_file(filename):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# 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
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -128,10 +129,8 @@ def install() -> dict:
|
||||||
|
|
||||||
# If the folder doesn't exist, create it
|
# If the folder doesn't exist, create it
|
||||||
path = os.path.split(journal_path)[0]
|
path = os.path.split(journal_path)[0]
|
||||||
try:
|
with contextlib.suppress(OSError):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Encrypt it?
|
# Encrypt it?
|
||||||
encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False)
|
encrypt = yesno(Message(MsgText.EncryptJournalQuestion), default=False)
|
||||||
|
|
|
@ -240,7 +240,8 @@ def _get_editor_template(config: dict, **kwargs) -> str:
|
||||||
template_path = expand_path(config["template"])
|
template_path = expand_path(config["template"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
template = open(template_path).read()
|
with open(template_path) as f:
|
||||||
|
template = f.read()
|
||||||
logging.debug("Write mode: template loaded: %s", template)
|
logging.debug("Write mode: template loaded: %s", template)
|
||||||
except OSError:
|
except OSError:
|
||||||
logging.error("Write mode: template not loaded")
|
logging.error("Write mode: template not loaded")
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# 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 jrnl.messages.Message import Message
|
from jrnl.messages import Message
|
||||||
from jrnl.messages.MsgStyle import MsgStyle
|
from jrnl.messages import MsgStyle
|
||||||
from jrnl.messages.MsgText import MsgText
|
from jrnl.messages import MsgText
|
||||||
|
|
||||||
Message = Message
|
Message = Message.Message
|
||||||
MsgStyle = MsgStyle
|
MsgStyle = MsgStyle.MsgStyle
|
||||||
MsgText = MsgText
|
MsgText = MsgText.MsgText
|
||||||
|
|
|
@ -83,11 +83,11 @@ class MarkdownExporter(TextExporter):
|
||||||
out = []
|
out = []
|
||||||
year, month = -1, -1
|
year, month = -1, -1
|
||||||
for e in journal.entries:
|
for e in journal.entries:
|
||||||
if not e.date.year == year:
|
if e.date.year != year:
|
||||||
year = e.date.year
|
year = e.date.year
|
||||||
out.append("# " + str(year))
|
out.append("# " + str(year))
|
||||||
out.append("")
|
out.append("")
|
||||||
if not e.date.month == month:
|
if e.date.month != month:
|
||||||
month = e.date.month
|
month = e.date.month
|
||||||
out.append("## " + e.date.strftime("%B"))
|
out.append("## " + e.date.strftime("%B"))
|
||||||
out.append("")
|
out.append("")
|
||||||
|
|
30
poetry.lock
generated
30
poetry.lock
generated
|
@ -17,6 +17,14 @@ category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "*"
|
python-versions = "*"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "astor"
|
||||||
|
version = "0.8.1"
|
||||||
|
description = "Read/rewrite/write Python ASTs"
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asttokens"
|
name = "asttokens"
|
||||||
version = "2.0.5"
|
version = "2.0.5"
|
||||||
|
@ -265,6 +273,18 @@ isort = ">=4.3.5,<6"
|
||||||
[package.extras]
|
[package.extras]
|
||||||
test = ["pytest"]
|
test = ["pytest"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flake8-simplify"
|
||||||
|
version = "0.19.3"
|
||||||
|
description = "flake8 plugin which checks for code that can be simplified"
|
||||||
|
category = "dev"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6.1"
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
astor = ">=0.1"
|
||||||
|
flake8 = ">=3.7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flake8-type-checking"
|
name = "flake8-type-checking"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
|
@ -1178,7 +1198,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>=
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = ">=3.10.0, <3.13"
|
python-versions = ">=3.10.0, <3.13"
|
||||||
content-hash = "63f39baa62c8641eb6329472de340a9f06d9ffea3096a4095e90f98ce2986f91"
|
content-hash = "d386601320306164cb6332391f68aca47c114da7cad2dfa273d1fcb70824db16"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
ansiwrap = [
|
ansiwrap = [
|
||||||
|
@ -1189,6 +1209,10 @@ appnope = [
|
||||||
{file = "appnope-0.1.3-py2.py3-none-any.whl", hash = "sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e"},
|
{file = "appnope-0.1.3-py2.py3-none-any.whl", hash = "sha256:265a455292d0bd8a72453494fa24df5a11eb18373a60c7c0430889f22548605e"},
|
||||||
{file = "appnope-0.1.3.tar.gz", hash = "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24"},
|
{file = "appnope-0.1.3.tar.gz", hash = "sha256:02bd91c4de869fbb1e1c50aafc4098827a7a54ab2f39d9dcba6c9547ed920e24"},
|
||||||
]
|
]
|
||||||
|
astor = [
|
||||||
|
{file = "astor-0.8.1-py2.py3-none-any.whl", hash = "sha256:070a54e890cefb5b3739d19f30f5a5ec840ffc9c50ffa7d23cc9fc1a38ebbfc5"},
|
||||||
|
{file = "astor-0.8.1.tar.gz", hash = "sha256:6a6effda93f4e1ce9f618779b2dd1d9d84f1e32812c23a29b3fff6fd7f63fa5e"},
|
||||||
|
]
|
||||||
asttokens = [
|
asttokens = [
|
||||||
{file = "asttokens-2.0.5-py2.py3-none-any.whl", hash = "sha256:0844691e88552595a6f4a4281a9f7f79b8dd45ca4ccea82e5e05b4bbdb76705c"},
|
{file = "asttokens-2.0.5-py2.py3-none-any.whl", hash = "sha256:0844691e88552595a6f4a4281a9f7f79b8dd45ca4ccea82e5e05b4bbdb76705c"},
|
||||||
{file = "asttokens-2.0.5.tar.gz", hash = "sha256:9a54c114f02c7a9480d56550932546a3f1fe71d8a02f1bc7ccd0ee3ee35cf4d5"},
|
{file = "asttokens-2.0.5.tar.gz", hash = "sha256:9a54c114f02c7a9480d56550932546a3f1fe71d8a02f1bc7ccd0ee3ee35cf4d5"},
|
||||||
|
@ -1379,6 +1403,10 @@ flake8-isort = [
|
||||||
{file = "flake8-isort-5.0.0.tar.gz", hash = "sha256:e336f928c7edc509684930ab124414194b7f4e237c712af8fcbdf49d8747b10c"},
|
{file = "flake8-isort-5.0.0.tar.gz", hash = "sha256:e336f928c7edc509684930ab124414194b7f4e237c712af8fcbdf49d8747b10c"},
|
||||||
{file = "flake8_isort-5.0.0-py3-none-any.whl", hash = "sha256:c73f9cbd1bf209887f602a27b827164ccfeba1676801b2aa23cb49051a1be79c"},
|
{file = "flake8_isort-5.0.0-py3-none-any.whl", hash = "sha256:c73f9cbd1bf209887f602a27b827164ccfeba1676801b2aa23cb49051a1be79c"},
|
||||||
]
|
]
|
||||||
|
flake8-simplify = [
|
||||||
|
{file = "flake8_simplify-0.19.3-py3-none-any.whl", hash = "sha256:1057320e9312d75849541fee822900d27bcad05b2405edc84713affee635629e"},
|
||||||
|
{file = "flake8_simplify-0.19.3.tar.gz", hash = "sha256:2fb083bf5142a98d9c9554755cf2f56f8926eb4a33eae30c0809041b1546879e"},
|
||||||
|
]
|
||||||
flake8-type-checking = [
|
flake8-type-checking = [
|
||||||
{file = "flake8_type_checking-2.2.0-py3-none-any.whl", hash = "sha256:c7d9d7adc6cd635a5a1a7859e5e0140f4f8f1705982a22db45872dd9acd49753"},
|
{file = "flake8_type_checking-2.2.0-py3-none-any.whl", hash = "sha256:c7d9d7adc6cd635a5a1a7859e5e0140f4f8f1705982a22db45872dd9acd49753"},
|
||||||
{file = "flake8_type_checking-2.2.0.tar.gz", hash = "sha256:f7972fc9102f3f632ace1f4b1c5c20b900b8b7b529f04bb6c1fe0a11801e9658"},
|
{file = "flake8_type_checking-2.2.0.tar.gz", hash = "sha256:f7972fc9102f3f632ace1f4b1c5c20b900b8b7b529f04bb6c1fe0a11801e9658"},
|
||||||
|
|
|
@ -48,6 +48,7 @@ flakeheaven = ">=3.0"
|
||||||
flake8-black = ">=0.3.3"
|
flake8-black = ">=0.3.3"
|
||||||
flake8-isort = ">=5.0.0"
|
flake8-isort = ">=5.0.0"
|
||||||
flake8-type-checking = ">=2.2.0"
|
flake8-type-checking = ">=2.2.0"
|
||||||
|
flake8-simplify = ">=0.19"
|
||||||
ipdb = "*"
|
ipdb = "*"
|
||||||
isort = ">=5.10"
|
isort = ">=5.10"
|
||||||
mkdocs = ">=1.0,<1.3"
|
mkdocs = ">=1.0,<1.3"
|
||||||
|
|
|
@ -293,7 +293,7 @@ class TestDeserialization:
|
||||||
|
|
||||||
runtime_config = make_yaml_valid_dict(input_str)
|
runtime_config = make_yaml_valid_dict(input_str)
|
||||||
assert runtime_config.__class__ == dict
|
assert runtime_config.__class__ == dict
|
||||||
assert input_str[0] in runtime_config.keys()
|
assert input_str[0] in runtime_config
|
||||||
assert runtime_config[input_str[0]] == input_str[1]
|
assert runtime_config[input_str[0]] == input_str[1]
|
||||||
|
|
||||||
def test_deserialize_multiple_datatypes(self):
|
def test_deserialize_multiple_datatypes(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue