From 71e1b38affd26acc794666fe715462985edc6f7a Mon Sep 17 00:00:00 2001 From: Micah Jerome Ellison Date: Mon, 3 Jul 2023 11:09:01 -0700 Subject: [PATCH] Resolve all remaining ruff line length errors --- jrnl/args.py | 2 +- jrnl/commands.py | 2 +- jrnl/config.py | 5 ++-- jrnl/controller.py | 8 +++--- jrnl/editor.py | 3 ++- jrnl/install.py | 12 ++++----- jrnl/journals/Entry.py | 4 +-- jrnl/journals/FolderJournal.py | 3 ++- jrnl/journals/Journal.py | 12 +++++---- jrnl/messages/MsgText.py | 4 +-- jrnl/override.py | 3 ++- jrnl/plugins/fancy_exporter.py | 2 +- jrnl/plugins/tag_exporter.py | 2 +- jrnl/plugins/util.py | 3 ++- jrnl/plugins/yaml_exporter.py | 14 ++++++++--- jrnl/time.py | 10 ++++---- tests/lib/then_steps.py | 46 ++++++++++++++++++++-------------- tests/unit/test_parse_args.py | 4 ++- 18 files changed, 83 insertions(+), 56 deletions(-) diff --git a/jrnl/args.py b/jrnl/args.py index 559c3c71..53a77462 100644 --- a/jrnl/args.py +++ b/jrnl/args.py @@ -439,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 + """, # 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) diff --git a/tests/lib/then_steps.py b/tests/lib/then_steps.py index 5ec75ad5..7216a23f 100644 --- a/tests/lib/then_steps.py +++ b/tests/lib/then_steps.py @@ -38,38 +38,41 @@ def output_should_match(regex, cli_run): assert matches, f"\nRegex didn't match:\n{regex}\n{str(out)}\n{str(matches)}" -@then(parse("the output {it_should:Should} contain\n{expected_output}", SHOULD_DICT)) -@then(parse('the output {it_should:Should} contain "{expected_output}"', SHOULD_DICT)) +@then(parse("the output {it_should:Should} contain\n{expected}", SHOULD_DICT)) +@then(parse('the output {it_should:Should} contain "{expected}"', SHOULD_DICT)) @then( parse( - "the {which_output_stream} output {it_should:Should} contain\n{expected_output}", + "the {which_output_stream} output {it_should:Should} contain\n{expected}", SHOULD_DICT, ) ) @then( parse( - 'the {which_output_stream} output {it_should:Should} contain "{expected_output}"', + 'the {which_output_stream} output {it_should:Should} contain "{expected}"', SHOULD_DICT, ) ) -def output_should_contain(expected_output, which_output_stream, cli_run, it_should): - output_str = f"\nEXPECTED:\n{expected_output}\n\nACTUAL STDOUT:\n{cli_run['stdout']}\n\nACTUAL STDERR:\n{cli_run['stderr']}" - assert expected_output +def output_should_contain(expected, which_output_stream, cli_run, it_should): + output_str = ( + f"\nEXPECTED:\n{expected}\n\n" + f"ACTUAL STDOUT:\n{cli_run['stdout']}\n\n" + f"ACTUAL STDERR:\n{cli_run['stderr']}" + ) + + assert expected if which_output_stream is None: - assert ((expected_output in cli_run["stdout"]) == it_should) or ( - (expected_output in cli_run["stderr"]) == it_should + assert ((expected in cli_run["stdout"]) == it_should) or ( + (expected in cli_run["stderr"]) == it_should ), output_str elif which_output_stream == "standard": - assert (expected_output in cli_run["stdout"]) == it_should, output_str + assert (expected in cli_run["stdout"]) == it_should, output_str elif which_output_stream == "error": - assert (expected_output in cli_run["stderr"]) == it_should, output_str + assert (expected in cli_run["stderr"]) == it_should, output_str else: - assert ( - expected_output in cli_run[which_output_stream] - ) == it_should, output_str + assert (expected in cli_run[which_output_stream]) == it_should, output_str @then(parse("the output should not contain\n{expected_output}")) @@ -119,7 +122,8 @@ def output_should_be_columns_wide(cli_run, width): @then( parse( - 'the default journal "{journal_file}" should be in the "{journal_dir}" directory' + 'the default journal "{journal_file}" ' + 'should be in the "{journal_dir}" directory' ) ) def default_journal_location(journal_file, journal_dir, config_on_disk, temp_dir): @@ -135,13 +139,15 @@ def default_journal_location(journal_file, journal_dir, config_on_disk, temp_dir @then( parse( - 'the config for journal "{journal_name}" {it_should:Should} contain "{some_yaml}"', + 'the config for journal "{journal_name}" ' + '{it_should:Should} contain "{some_yaml}"', SHOULD_DICT, ) ) @then( parse( - 'the config for journal "{journal_name}" {it_should:Should} contain\n{some_yaml}', + 'the config for journal "{journal_name}" ' + "{it_should:Should} contain\n{some_yaml}", SHOULD_DICT, ) ) @@ -164,13 +170,15 @@ def config_var_on_disk(config_on_disk, journal_name, it_should, some_yaml): @then( parse( - 'the config in memory for journal "{journal_name}" {it_should:Should} contain "{some_yaml}"', + 'the config in memory for journal "{journal_name}" ' + '{it_should:Should} contain "{some_yaml}"', SHOULD_DICT, ) ) @then( parse( - 'the config in memory for journal "{journal_name}" {it_should:Should} contain\n{some_yaml}', + 'the config in memory for journal "{journal_name}" ' + "{it_should:Should} contain\n{some_yaml}", SHOULD_DICT, ) ) diff --git a/tests/unit/test_parse_args.py b/tests/unit/test_parse_args.py index fd1d0844..e3036020 100644 --- a/tests/unit/test_parse_args.py +++ b/tests/unit/test_parse_args.py @@ -242,7 +242,9 @@ def test_color_override(): def test_multiple_overrides(): parsed_args = cli_as_dict( - '--config-override colors.title green --config-override editor "nano" --config-override journal.scratchpad "/tmp/scratchpad"' + "--config-override colors.title green " + '--config-override editor "nano" ' + '--config-override journal.scratchpad "/tmp/scratchpad"' ) assert parsed_args == expected_args( config_override=[