From 9ccbcdcc7e1c08bd570c774179b1b0bb00d8287e Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 15 Aug 2020 18:49:23 -0700 Subject: [PATCH] clean up import statements --- features/environment.py | 1 - features/steps/core.py | 8 +++++--- features/steps/export_steps.py | 3 ++- jrnl/DayOneJournal.py | 9 ++++++--- jrnl/EncryptedJournal.py | 18 ++++++++++++------ jrnl/cli.py | 9 ++++----- jrnl/color.py | 4 +++- jrnl/commands.py | 2 +- jrnl/config.py | 3 ++- jrnl/editor.py | 4 ++-- jrnl/install.py | 2 ++ jrnl/jrnl.py | 3 +-- jrnl/output.py | 4 +++- jrnl/parse_args.py | 13 ++++--------- jrnl/plugins/markdown_exporter.py | 4 +++- jrnl/plugins/text_exporter.py | 3 ++- jrnl/plugins/yaml_exporter.py | 5 ++++- jrnl/prompt.py | 2 +- jrnl/time.py | 1 - jrnl/upgrade.py | 4 ++-- pyproject.toml | 8 +++----- tests/test_parse_args.py | 5 +++-- tests/test_time.py | 1 + 23 files changed, 66 insertions(+), 50 deletions(-) diff --git a/features/environment.py b/features/environment.py index 533dcea5..63fec4a6 100644 --- a/features/environment.py +++ b/features/environment.py @@ -3,7 +3,6 @@ import shutil from jrnl.os_compat import on_windows - CWD = os.getcwd() diff --git a/features/steps/core.py b/features/steps/core.py index 449c2874..76bc8d32 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -7,17 +7,18 @@ import shlex import time from unittest.mock import patch +from behave import given +from behave import then +from behave import when import keyring import toml import yaml -from behave import given, then, when from jrnl import Journal from jrnl import __version__ from jrnl import cli from jrnl import install from jrnl import plugins - from jrnl.config import load_config from jrnl.os_compat import on_windows @@ -398,9 +399,10 @@ def list_journal_directory(context, journal="default"): @then("the Python version warning should appear if our version is below {version}") def check_python_warning_if_version_low_enough(context, version): - import packaging.version import platform + import packaging.version + if packaging.version.parse(platform.python_version()) < packaging.version.parse( version ): diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index 2e59d729..d75aea64 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -3,7 +3,8 @@ import os import shutil from xml.etree import ElementTree -from behave import given, then +from behave import given +from behave import then @then("the output should be parsable as json") diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index cb568bc3..6e1b8345 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -4,18 +4,21 @@ from datetime import datetime import fnmatch import os from pathlib import Path +import platform import plistlib import re +import socket import time import uuid from xml.parsers.expat import ExpatError -import socket -import platform import pytz import tzlocal -from . import __title__, __version__, Entry, Journal +from . import Entry +from . import Journal +from . import __title__ +from . import __version__ class DayOne(Journal.Journal): diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index 16cdb337..e1d248aa 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -1,19 +1,25 @@ import base64 +import getpass import hashlib import logging import os import sys -from typing import Callable, Optional -import getpass +from typing import Callable +from typing import Optional -from cryptography.fernet import Fernet, InvalidToken +from cryptography.fernet import Fernet +from cryptography.fernet import InvalidToken from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import hashes, padding -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives import padding +from cryptography.hazmat.primitives.ciphers import Cipher +from cryptography.hazmat.primitives.ciphers import algorithms +from cryptography.hazmat.primitives.ciphers import modes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC +from .Journal import Journal +from .Journal import LegacyJournal from .prompt import create_password -from .Journal import Journal, LegacyJournal def make_key(password): diff --git a/jrnl/cli.py b/jrnl/cli.py index 87c0bcab..3d30e84d 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -19,14 +19,13 @@ import logging import sys -from . import jrnl from . import install - -from .parse_args import parse_args -from .config import scope_config -from .exception import UserAbort +from . import jrnl from .Journal import open_journal from .config import get_journal_name +from .config import scope_config +from .exception import UserAbort +from .parse_args import parse_args def configure_logger(debug=False): diff --git a/jrnl/color.py b/jrnl/color.py index fbdd2b8b..dca28117 100644 --- a/jrnl/color.py +++ b/jrnl/color.py @@ -1,8 +1,10 @@ #!/usr/bin/env python -import colorama import re from string import punctuation from string import whitespace + +import colorama + from .os_compat import on_windows if on_windows: diff --git a/jrnl/commands.py b/jrnl/commands.py index 96dc68c0..d8d36571 100644 --- a/jrnl/commands.py +++ b/jrnl/commands.py @@ -40,8 +40,8 @@ def postconfig_list(config, **kwargs): def postconfig_import(args, config, **kwargs): - from .plugins import get_importer from .Journal import open_journal + from .plugins import get_importer # Requires opening the journal journal = open_journal(args.journal_name, config) diff --git a/jrnl/config.py b/jrnl/config.py index 2f9388ce..1e0cee54 100644 --- a/jrnl/config.py +++ b/jrnl/config.py @@ -1,6 +1,7 @@ import logging -import colorama import sys + +import colorama import yaml from .color import ERROR_COLOR diff --git a/jrnl/editor.py b/jrnl/editor.py index fb7c39c1..06f32b9f 100644 --- a/jrnl/editor.py +++ b/jrnl/editor.py @@ -1,8 +1,8 @@ -import tempfile import os -import sys import shlex import subprocess +import sys +import tempfile import textwrap from .color import ERROR_COLOR diff --git a/jrnl/install.py b/jrnl/install.py index af71a40d..7359f990 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -4,8 +4,10 @@ import glob import logging import os import sys + import xdg.BaseDirectory import yaml + from . import __version__ from .config import load_config from .config import verify_config diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 0c72e559..4051d876 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -3,10 +3,9 @@ import sys from . import install from . import plugins -from .editor import get_text_from_editor - from .color import ERROR_COLOR from .color import RESET_COLOR +from .editor import get_text_from_editor from .os_compat import on_windows diff --git a/jrnl/output.py b/jrnl/output.py index 271a6c00..b645d6d1 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -4,7 +4,9 @@ import logging def deprecated_cmd(old_cmd, new_cmd, callback=None, **kwargs): import sys import textwrap - from .color import RESET_COLOR, WARNING_COLOR + + from .color import RESET_COLOR + from .color import WARNING_COLOR warning_msg = f""" The command {old_cmd} is deprecated and will be removed from jrnl soon. diff --git a/jrnl/parse_args.py b/jrnl/parse_args.py index 3127b8f0..b1baa2a1 100644 --- a/jrnl/parse_args.py +++ b/jrnl/parse_args.py @@ -2,16 +2,11 @@ import argparse import re import textwrap -from .plugins import util -from .plugins import IMPORT_FORMATS +from .commands import deprecated_cmd +from .commands import output from .plugins import EXPORT_FORMATS -from .commands import preconfig_version -from .commands import preconfig_diagnostic -from .commands import postconfig_list -from .commands import postconfig_import -from .commands import postconfig_encrypt -from .commands import postconfig_decrypt -from .output import deprecated_cmd +from .plugins import IMPORT_FORMATS +from .plugins import util class WrappingFormatter(argparse.RawTextHelpFormatter): diff --git a/jrnl/plugins/markdown_exporter.py b/jrnl/plugins/markdown_exporter.py index 5c0fd486..7ee20472 100644 --- a/jrnl/plugins/markdown_exporter.py +++ b/jrnl/plugins/markdown_exporter.py @@ -5,7 +5,9 @@ import os import re import sys -from jrnl.color import RESET_COLOR, WARNING_COLOR +from jrnl.color import RESET_COLOR +from jrnl.color import WARNING_COLOR + from .text_exporter import TextExporter diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index eccd6b5b..68061e4e 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -5,7 +5,8 @@ import os import re import unicodedata -from jrnl.color import ERROR_COLOR, RESET_COLOR +from jrnl.color import ERROR_COLOR +from jrnl.color import RESET_COLOR class TextExporter: diff --git a/jrnl/plugins/yaml_exporter.py b/jrnl/plugins/yaml_exporter.py index 637990d0..0d431967 100644 --- a/jrnl/plugins/yaml_exporter.py +++ b/jrnl/plugins/yaml_exporter.py @@ -5,7 +5,10 @@ import os import re import sys -from jrnl.color import ERROR_COLOR, RESET_COLOR, WARNING_COLOR +from jrnl.color import ERROR_COLOR +from jrnl.color import RESET_COLOR +from jrnl.color import WARNING_COLOR + from .text_exporter import TextExporter diff --git a/jrnl/prompt.py b/jrnl/prompt.py index 2d68d5e4..13828620 100644 --- a/jrnl/prompt.py +++ b/jrnl/prompt.py @@ -1,5 +1,5 @@ -import sys import getpass +import sys def create_password( diff --git a/jrnl/time.py b/jrnl/time.py index 25fba0d7..45fc15cc 100644 --- a/jrnl/time.py +++ b/jrnl/time.py @@ -1,6 +1,5 @@ from datetime import datetime - FAKE_YEAR = 9999 DEFAULT_FUTURE = datetime(FAKE_YEAR, 12, 31, 23, 59, 59) DEFAULT_PAST = datetime(FAKE_YEAR, 1, 1, 0, 0) diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index 1b47eb9c..fb526e97 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -1,15 +1,15 @@ import os import sys -from . import __version__ from . import Journal +from . import __version__ +from .EncryptedJournal import EncryptedJournal from .config import is_config_json from .config import load_config from .config import scope_config from .exception import UpgradeValidationException from .exception import UserAbort from .prompt import yesno -from .EncryptedJournal import EncryptedJournal def backup(filename, binary=False): diff --git a/pyproject.toml b/pyproject.toml index 4d43d73a..a0723e8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,12 +43,10 @@ pytest = "^5.4.3" jrnl = 'jrnl.cli:run' [tool.isort] -multi_line_output = 3 -include_trailing_comma = true -force_grid_wrap = 0 -use_parentheses = true +multi_line_output = 7 +force_single_line = true line_length = 88 -known_first_party = ["jrnl", "behave"] +known_first_party = ["jrnl"] force_sort_within_sections = true [build-system] diff --git a/tests/test_parse_args.py b/tests/test_parse_args.py index 70cae1b8..431892e6 100644 --- a/tests/test_parse_args.py +++ b/tests/test_parse_args.py @@ -1,7 +1,8 @@ -from jrnl.parse_args import parse_args +import shlex import pytest -import shlex + +from jrnl.parse_args import parse_args def cli_as_dict(str): diff --git a/tests/test_time.py b/tests/test_time.py index 697a409f..e04e1733 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -1,4 +1,5 @@ import datetime + from jrnl import time