From 79c37401c472b059f313078c2447fb5da2eca2e4 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sat, 17 Jul 2021 14:19:48 -0600 Subject: [PATCH] `jrnl.__version__` magic works! (#1296) * `jrnl.__version__` magic works! Adjust version imports Update version on GitHub release flow Fix version imports & black issue * escape strings in workflow Co-authored-by: Jonathan Wren --- .github/workflows/release.yaml | 12 +++++++++++- features/steps/core.py | 2 +- jrnl/DayOneJournal.py | 2 +- jrnl/__version__.py | 8 ++++++++ jrnl/cli.py | 2 +- jrnl/commands.py | 4 ++-- jrnl/config.py | 2 +- jrnl/plugins/exporter/dates.py | 3 +-- jrnl/plugins/exporter/fancy.py | 3 +-- jrnl/plugins/exporter/json.py | 3 +-- jrnl/plugins/exporter/markdown.py | 3 +-- jrnl/plugins/exporter/pretty.py | 3 +-- jrnl/plugins/exporter/short.py | 3 +-- jrnl/plugins/exporter/tag.py | 3 +-- jrnl/plugins/exporter/text.py | 3 +-- jrnl/plugins/exporter/xml.py | 3 +-- jrnl/plugins/exporter/yaml.py | 3 +-- jrnl/plugins/importer/jrnl.py | 3 +-- jrnl/upgrade.py | 2 +- 19 files changed, 37 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5e0169c15..39683e0b4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -80,7 +80,17 @@ jobs: if: ${{ github.event.inputs.include_repo_version == 'true' }} run: | poetry version "$JRNL_VERSION" - echo __version__ = \"$JRNL_VERSION\" > jrnl/__version__.py + { + echo "# This file is managed automatically by the GitHub release flow" + echo + echo "import sys" + echo + echo "__version__ = \"$JRNL_VERSION\"" + echo + echo '# this makes the version available at `jrnl.__version__` without requiring a' + echo '# `__init__.py` file in the *jrnl* root directory!' + echo 'sys.modules["jrnl.__version__"] = __version__' + } > jrnl/__version__.py - name: Commit updated files if: ${{ github.event.inputs.include_repo_version == 'true' && github.repository == env.HOME_REPO }} diff --git a/features/steps/core.py b/features/steps/core.py index f2cf27af7..481401643 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -18,7 +18,7 @@ from yaml.loader import SafeLoader from jrnl import Journal -from jrnl.__version__ import __version__ +from jrnl import __version__ from jrnl import plugins from jrnl.args import parse_args from jrnl.behave_testing import _mock_getpass diff --git a/jrnl/DayOneJournal.py b/jrnl/DayOneJournal.py index bb34ac3f5..09b6891d0 100644 --- a/jrnl/DayOneJournal.py +++ b/jrnl/DayOneJournal.py @@ -15,7 +15,7 @@ from . import Entry from . import Journal -from jrnl.__version__ import __version__ +from . import __version__ class DayOne(Journal.Journal): diff --git a/jrnl/__version__.py b/jrnl/__version__.py index 51977ba3e..929739e96 100644 --- a/jrnl/__version__.py +++ b/jrnl/__version__.py @@ -1 +1,9 @@ +# This file is managed automatically by the GitHub release flow + +import sys + __version__ = "v2.8.1" + +# this makes the version available at `jrnl.__version__` without requiring a +# `__init__.py` file in the *jrnl* root directory +sys.modules["jrnl.__version__"] = __version__ diff --git a/jrnl/cli.py b/jrnl/cli.py index 6a1c6a0f0..d8b06ddd8 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -4,9 +4,9 @@ import logging import sys -from .jrnl import run from .args import parse_args from .exception import JrnlError +from .jrnl import run def configure_logger(debug=False): diff --git a/jrnl/commands.py b/jrnl/commands.py index 90c01b5af..85478d8e4 100644 --- a/jrnl/commands.py +++ b/jrnl/commands.py @@ -16,7 +16,7 @@ def preconfig_diagnostic(_): - from jrnl.__version__ import __version__ + from jrnl import __version__ print( f"jrnl: {__version__}\n" @@ -26,7 +26,7 @@ def preconfig_diagnostic(_): def preconfig_version(_): - from jrnl.__version__ import __version__ + from jrnl import __version__ from jrnl.plugins.collector import ( IMPORT_FORMATS, EXPORT_FORMATS, diff --git a/jrnl/config.py b/jrnl/config.py index d8d0bab0f..326952041 100644 --- a/jrnl/config.py +++ b/jrnl/config.py @@ -6,7 +6,7 @@ import yaml import xdg.BaseDirectory -from jrnl.__version__ import __version__ +from . import __version__ from .exception import JrnlError from .color import ERROR_COLOR from .color import RESET_COLOR diff --git a/jrnl/plugins/exporter/dates.py b/jrnl/plugins/exporter/dates.py index 9dbaa395b..66f0193c0 100644 --- a/jrnl/plugins/exporter/dates.py +++ b/jrnl/plugins/exporter/dates.py @@ -4,10 +4,9 @@ from collections import Counter +from jrnl import __version__ from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter lists dates and their respective counts, for heatingmapping etc.""" diff --git a/jrnl/plugins/exporter/fancy.py b/jrnl/plugins/exporter/fancy.py index 60005fd8e..47ff24d6a 100644 --- a/jrnl/plugins/exporter/fancy.py +++ b/jrnl/plugins/exporter/fancy.py @@ -5,11 +5,10 @@ from textwrap import TextWrapper +from jrnl import __version__ from jrnl.plugins.base import BaseExporter from jrnl.plugins.util import check_provided_linewrap_viability -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into text with unicode box drawing characters.""" diff --git a/jrnl/plugins/exporter/json.py b/jrnl/plugins/exporter/json.py index cb9a617fd..b724a8048 100644 --- a/jrnl/plugins/exporter/json.py +++ b/jrnl/plugins/exporter/json.py @@ -4,11 +4,10 @@ import json +from jrnl import __version__ from jrnl.plugins.base import BaseExporter from jrnl.plugins.util import get_tags_count -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into json.""" diff --git a/jrnl/plugins/exporter/markdown.py b/jrnl/plugins/exporter/markdown.py index 3026b0b23..98e226c8b 100644 --- a/jrnl/plugins/exporter/markdown.py +++ b/jrnl/plugins/exporter/markdown.py @@ -6,12 +6,11 @@ import re import sys +from jrnl import __version__ from jrnl.color import RESET_COLOR from jrnl.color import WARNING_COLOR from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into Markdown.""" diff --git a/jrnl/plugins/exporter/pretty.py b/jrnl/plugins/exporter/pretty.py index 9a83341c2..e4c843f64 100644 --- a/jrnl/plugins/exporter/pretty.py +++ b/jrnl/plugins/exporter/pretty.py @@ -3,10 +3,9 @@ # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +from jrnl import __version__ from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """Pretty print journal""" diff --git a/jrnl/plugins/exporter/short.py b/jrnl/plugins/exporter/short.py index 9ebf057a3..078d7079e 100644 --- a/jrnl/plugins/exporter/short.py +++ b/jrnl/plugins/exporter/short.py @@ -3,10 +3,9 @@ # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +from jrnl import __version__ from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """Short export -- i.e. single line date and title""" diff --git a/jrnl/plugins/exporter/tag.py b/jrnl/plugins/exporter/tag.py index f2a9d50bb..de3ccacc9 100644 --- a/jrnl/plugins/exporter/tag.py +++ b/jrnl/plugins/exporter/tag.py @@ -3,11 +3,10 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html +from jrnl import __version__ from jrnl.plugins.base import BaseExporter from jrnl.plugins.util import get_tags_count -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can lists the tags for entries and journals, exported as a plain text file.""" diff --git a/jrnl/plugins/exporter/text.py b/jrnl/plugins/exporter/text.py index 7f3e6fcdc..09fc90ec3 100644 --- a/jrnl/plugins/exporter/text.py +++ b/jrnl/plugins/exporter/text.py @@ -3,10 +3,9 @@ # Copyright (C) 2012-2021 jrnl contributors # License: https://www.gnu.org/licenses/gpl-3.0.html +from jrnl import __version__ from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into text files.""" diff --git a/jrnl/plugins/exporter/xml.py b/jrnl/plugins/exporter/xml.py index 904593e0b..38c8c1979 100644 --- a/jrnl/plugins/exporter/xml.py +++ b/jrnl/plugins/exporter/xml.py @@ -4,11 +4,10 @@ from xml.dom import minidom +from jrnl import __version__ from jrnl.plugins.base import BaseExporter from jrnl.plugins.util import get_tags_count -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into XML.""" diff --git a/jrnl/plugins/exporter/yaml.py b/jrnl/plugins/exporter/yaml.py index 2054f344b..7511b0ada 100644 --- a/jrnl/plugins/exporter/yaml.py +++ b/jrnl/plugins/exporter/yaml.py @@ -6,13 +6,12 @@ import re import sys +from jrnl import __version__ from jrnl.color import ERROR_COLOR from jrnl.color import RESET_COLOR from jrnl.color import WARNING_COLOR from jrnl.plugins.base import BaseExporter -from jrnl.__version__ import __version__ - class Exporter(BaseExporter): """This Exporter can convert entries and journals into Markdown formatted text with YAML front matter.""" diff --git a/jrnl/plugins/importer/jrnl.py b/jrnl/plugins/importer/jrnl.py index 07031cc36..f5b1c2377 100644 --- a/jrnl/plugins/importer/jrnl.py +++ b/jrnl/plugins/importer/jrnl.py @@ -4,10 +4,9 @@ import sys +from jrnl import __version__ from jrnl.plugins.base import BaseImporter -from jrnl.__version__ import __version__ - class Importer(BaseImporter): """This plugin imports entries from other jrnl files.""" diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index e9eb83f1a..158f8de3f 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -5,7 +5,7 @@ import sys from . import Journal -from jrnl.__version__ import __version__ +from . import __version__ from .EncryptedJournal import EncryptedJournal from .config import is_config_json from .config import load_config