From ec7a1cc83a25501c197c241dc5c291aae5b55960 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 19 Sep 2019 23:15:36 +0100 Subject: [PATCH 01/17] :sparkles: support template string from shell pipe. resolves #260 --- moban/main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/moban/main.py b/moban/main.py index d8d66563..55429104 100644 --- a/moban/main.py +++ b/moban/main.py @@ -230,7 +230,17 @@ def handle_command_line(options): ) if options[constants.LABEL_TEMPLATE] is None: if options[constants.POSITIONAL_LABEL_TEMPLATE] is None: - raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) + content = None + if not sys.stdin.isatty(): + content = sys.stdin.read().strip() + if content: + engine.render_string_to_file( + content, + options[constants.LABEL_CONFIG], + options[constants.LABEL_OUTPUT], + ) + else: + raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) else: engine.render_string_to_file( options[constants.POSITIONAL_LABEL_TEMPLATE], From 3c4a4ec8c8432497504e5ac141507f9ef7c841de Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 19 Sep 2019 23:33:08 +0100 Subject: [PATCH 02/17] :microscope: test shell pipe feature. test #260 --- .../integration_tests/test_command_line_options.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index bd333cf0..6378cd66 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -1,5 +1,6 @@ import os import sys +from io import StringIO from shutil import copyfile from mock import patch @@ -524,3 +525,16 @@ def test_add_extension(): "{}.{}".format(sys.version_info[0], sys.version_info[1]), ) os.unlink("moban.output") + + +def test_stdin_input(): + test_args = ["moban", "-d", "hello=world"] + with patch.object(sys, "stdin", StringIO("{{hello}}")): + with patch.object(sys, "argv", test_args): + from moban.main import main + + main() + with open("moban.output") as f: + content = f.read() + eq_(content, "world") + os.unlink("moban.output") From a891e7a868ce389560c93e8da1e45f5873df898c Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 19 Sep 2019 23:42:59 +0100 Subject: [PATCH 03/17] :books: update documentation --- .moban.cd/changelog.yml | 6 ++++++ CHANGELOG.rst | 9 +++++++++ README.rst | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index d6e6d4ab..a5fa5a96 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: + - changes: + - action: Added + details: + - "`#260`: jinja-cli parity: support command line pipe stream." + date: tbd + version: 0.6.3 - changes: - action: Added details: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e271273f..fc148bb6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.6.3 - tbd +-------------------------------------------------------------------------------- + +Added +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#260 `_: jinja-cli parity: + support command line pipe stream. + 0.6.2 - 15.09.2019 -------------------------------------------------------------------------------- diff --git a/README.rst b/README.rst index 308723c9..bf60eba3 100644 --- a/README.rst +++ b/README.rst @@ -71,6 +71,13 @@ Quick start $ cat moban.output world +Or + +.. code-block:: bash + + $ export HELLO="world" + $ echo "{{HELLO}}" | moban + Or simply .. code-block:: bash From 24c9e0d8e97a2b9b754448cd3fd32317e7892f33 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 19 Sep 2019 23:45:19 +0100 Subject: [PATCH 04/17] :hammer: code refactoring --- moban/main.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/moban/main.py b/moban/main.py index 55429104..c3831bb0 100644 --- a/moban/main.py +++ b/moban/main.py @@ -229,24 +229,18 @@ def handle_command_line(options): options[constants.LABEL_CONFIG_DIR], ) if options[constants.LABEL_TEMPLATE] is None: - if options[constants.POSITIONAL_LABEL_TEMPLATE] is None: - content = None + content = options[constants.POSITIONAL_LABEL_TEMPLATE] + if content is None: if not sys.stdin.isatty(): content = sys.stdin.read().strip() - if content: - engine.render_string_to_file( - content, - options[constants.LABEL_CONFIG], - options[constants.LABEL_OUTPUT], - ) - else: - raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) - else: - engine.render_string_to_file( - options[constants.POSITIONAL_LABEL_TEMPLATE], - options[constants.LABEL_CONFIG], - options[constants.LABEL_OUTPUT], - ) + if content is None: + raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) + + engine.render_string_to_file( + content, + options[constants.LABEL_CONFIG], + options[constants.LABEL_OUTPUT], + ) else: engine.render_to_file( options[constants.LABEL_TEMPLATE], From df5b2d11c0c7905817d1a29557b01b8cd7048a50 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 19 Sep 2019 23:47:46 +0100 Subject: [PATCH 05/17] :green_heart: fix python 2 compactibility --- tests/integration_tests/test_command_line_options.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 6378cd66..b045cfdd 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -1,6 +1,5 @@ import os import sys -from io import StringIO from shutil import copyfile from mock import patch @@ -8,6 +7,11 @@ from nose.tools import eq_, raises, assert_raises from moban.definitions import TemplateTarget +try: + from io import StringIO +except ImportError: + from StringIO import StringIO + class TestCustomOptions: def setUp(self): From b6f84536eb2d8240c1b778ecb28e50c7053606e2 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 21 Sep 2019 08:56:57 +0100 Subject: [PATCH 06/17] :green_heart: update unit tests --- tests/integration_tests/test_command_line_options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index b045cfdd..bd4e0eec 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -8,9 +8,9 @@ from moban.definitions import TemplateTarget try: - from io import StringIO -except ImportError: from StringIO import StringIO +except ImportError: + from io import StringIO class TestCustomOptions: From 83357492bf8cca94bc0bf3b10e23afd384ebc460 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 21 Sep 2019 09:02:35 +0100 Subject: [PATCH 07/17] :fire: skip windows tests --- tests/integration_tests/test_command_line_options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index bd4e0eec..4b25371c 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -532,6 +532,8 @@ def test_add_extension(): def test_stdin_input(): + if sys.version_info[0] == 2: + raise SkipTest("windows test fails with this pipe test") test_args = ["moban", "-d", "hello=world"] with patch.object(sys, "stdin", StringIO("{{hello}}")): with patch.object(sys, "argv", test_args): From 6cf08fcae942ebb2dbec35c427cdec8c40e931a9 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 21 Sep 2019 09:04:24 +0100 Subject: [PATCH 08/17] :sparkles: enable tests on python 2 version for additional versions --- tests/integration_tests/test_command_line_options.py | 2 -- tests/requirements.txt | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 4b25371c..56ede60a 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -499,8 +499,6 @@ def test_pypi_pkg_example(_): def test_add_extension(): - if sys.version_info[0] == 2: - raise SkipTest("jinja2-python-version does not support python 2") test_commands = [ [ "moban", diff --git a/tests/requirements.txt b/tests/requirements.txt index 176572ca..4979027e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -14,4 +14,4 @@ arrow;python_version!="3.4" jinja2_time pypifs gitfs2 -jinja2-python-version +jinja2-python-version>=1.1.2 From f75d9ed39f0a5e22a098987038331a1947a08717 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 21 Sep 2019 13:54:28 +0100 Subject: [PATCH 09/17] :fire: test if the new test function broke azure build --- .../test_command_line_options.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 56ede60a..af339dbd 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -527,18 +527,3 @@ def test_add_extension(): "{}.{}".format(sys.version_info[0], sys.version_info[1]), ) os.unlink("moban.output") - - -def test_stdin_input(): - if sys.version_info[0] == 2: - raise SkipTest("windows test fails with this pipe test") - test_args = ["moban", "-d", "hello=world"] - with patch.object(sys, "stdin", StringIO("{{hello}}")): - with patch.object(sys, "argv", test_args): - from moban.main import main - - main() - with open("moban.output") as f: - content = f.read() - eq_(content, "world") - os.unlink("moban.output") From 08ce41866fe0dd55f164f07c28e835a67f06fc0b Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 23 Sep 2019 19:33:10 +0100 Subject: [PATCH 10/17] :fire: remove win32 support as it has no pipe --- moban/main.py | 2 +- .../test_command_line_options.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/moban/main.py b/moban/main.py index c3831bb0..2e911cad 100644 --- a/moban/main.py +++ b/moban/main.py @@ -231,7 +231,7 @@ def handle_command_line(options): if options[constants.LABEL_TEMPLATE] is None: content = options[constants.POSITIONAL_LABEL_TEMPLATE] if content is None: - if not sys.stdin.isatty(): + if not sys.stdin.isatty() and sys.platform != 'win32': content = sys.stdin.read().strip() if content is None: raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index af339dbd..76967c7d 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -499,6 +499,8 @@ def test_pypi_pkg_example(_): def test_add_extension(): + if sys.version_info[0] == 2: + raise SkipTest("jinja2-python-version does not support python 2") test_commands = [ [ "moban", @@ -527,3 +529,18 @@ def test_add_extension(): "{}.{}".format(sys.version_info[0], sys.version_info[1]), ) os.unlink("moban.output") + + +def test_stdin_input(): + if sys.version_info[0] == 2: + raise SkipTest("windows test fails with this pipe test 2") + test_args = ["moban", "-d", "hello=world"] + with patch.object(sys, "stdin", StringIO("{{hello}}")): + with patch.object(sys, "argv", test_args): + from moban.main import main + + main() + with open("moban.output") as f: + content = f.read() + eq_(content, "world") + os.unlink("moban.output") From 1b008353f1e3d68016eac9e8b0d47c68a6ab8cd6 Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 23 Sep 2019 19:33:52 +0100 Subject: [PATCH 11/17] :shirt: coding style update --- moban/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moban/main.py b/moban/main.py index 2e911cad..96f3e569 100644 --- a/moban/main.py +++ b/moban/main.py @@ -231,7 +231,7 @@ def handle_command_line(options): if options[constants.LABEL_TEMPLATE] is None: content = options[constants.POSITIONAL_LABEL_TEMPLATE] if content is None: - if not sys.stdin.isatty() and sys.platform != 'win32': + if not sys.stdin.isatty() and sys.platform != "win32": content = sys.stdin.read().strip() if content is None: raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) From a0fac4b283a885595fc8fc407159520cdc0a7524 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 21:56:53 +0100 Subject: [PATCH 12/17] :fire: skip the stdin test on windows --- test.sh | 2 +- tests/integration_tests/test_command_line_options.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index b294f53a..775f6173 100644 --- a/test.sh +++ b/test.sh @@ -1,3 +1,3 @@ pip freeze -nosetests --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests +nosetests --verbosity=3 --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 76967c7d..6f936dd7 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -532,7 +532,7 @@ def test_add_extension(): def test_stdin_input(): - if sys.version_info[0] == 2: + if sys.platform == "win32": raise SkipTest("windows test fails with this pipe test 2") test_args = ["moban", "-d", "hello=world"] with patch.object(sys, "stdin", StringIO("{{hello}}")): From ecf924dd57244ce0efb2da49487f4725d84f53f0 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 22:05:47 +0100 Subject: [PATCH 13/17] :green_heart: better mocking to fix azure macos test, which seems eating console output --- tests/integration_tests/test_command_line_options.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 6f936dd7..aa39818c 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -2,7 +2,7 @@ import sys from shutil import copyfile -from mock import patch +from mock import MagicMock, patch from nose import SkipTest from nose.tools import eq_, raises, assert_raises from moban.definitions import TemplateTarget @@ -59,10 +59,12 @@ def test_minimal_options(self, fake_template_doer): @raises(SystemExit) def test_missing_template(self): test_args = ["moban", "-c", self.config_file] - with patch.object(sys, "argv", test_args): - from moban.main import main + fake_stdin = MagicMock(isatty=MagicMock(return_value=True)) + with patch.object(sys, "stdin", fake_stdin): + with patch.object(sys, "argv", test_args): + from moban.main import main - main() + main() def tearDown(self): self.patcher1.stop() From 15019971954588a2c9ce1898dcec4efd0482bb92 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 22:09:19 +0100 Subject: [PATCH 14/17] :green_heart: update one more test case, which seems eating console output --- tests/integration_tests/test_command_line_options.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index aa39818c..0a2bc8e7 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -107,10 +107,12 @@ def test_string_template(self, fake_template_doer): @raises(SystemExit) def test_no_argments(self): test_args = ["moban"] - with patch.object(sys, "argv", test_args): - from moban.main import main + fake_stdin = MagicMock(isatty=MagicMock(return_value=True)) + with patch.object(sys, "stdin", fake_stdin): + with patch.object(sys, "argv", test_args): + from moban.main import main - main() + main() def tearDown(self): self.patcher1.stop() From 15a0e60de074eeb0a66fbcb2904a8b7bae8d07f9 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 22:19:50 +0100 Subject: [PATCH 15/17] :green_heart: update one more test case, which seems eating console output --- tests/test_main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 96adba08..2b054538 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -3,7 +3,7 @@ from shutil import copyfile import moban.exceptions as exceptions -from mock import patch +from mock import MagicMock, patch from nose.tools import eq_, raises, assert_raises @@ -86,10 +86,12 @@ def test_directory_not_found( ): fake_file.return_value = True fake_moban_file.side_effect = exceptions.DirectoryNotFound - from moban.main import main + fake_stdin = MagicMock(isatty=MagicMock(return_value=True)) + with patch.object(sys, "stdin", fake_stdin): + with patch.object(sys, "argv", ["moban"]): + from moban.main import main - with patch.object(sys, "argv", ["moban"]): - main() + main() @raises(SystemExit) @patch("os.path.exists") From b7a12769a6c644fc9783ba7f3a0dc30c9cbde0d3 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 22:23:02 +0100 Subject: [PATCH 16/17] :green_heart: update one more test case, which seems eating console output --- tests/test_main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 2b054538..0de35825 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -102,10 +102,12 @@ def test_no_third_party_engine( ): fake_file.return_value = True fake_moban_file.side_effect = exceptions.NoThirdPartyEngine - from moban.main import main + fake_stdin = MagicMock(isatty=MagicMock(return_value=True)) + with patch.object(sys, "stdin", fake_stdin): + from moban.main import main - with patch.object(sys, "argv", ["moban"]): - main() + with patch.object(sys, "argv", ["moban"]): + main() @raises(SystemExit) @patch("os.path.exists") @@ -116,10 +118,12 @@ def test_double_underscore_main( ): fake_file.return_value = True fake_moban_file.side_effect = exceptions.DirectoryNotFound - from moban.__main__ import main + fake_stdin = MagicMock(isatty=MagicMock(return_value=True)) + with patch.object(sys, "stdin", fake_stdin): + from moban.__main__ import main - with patch.object(sys, "argv", ["moban"]): - main() + with patch.object(sys, "argv", ["moban"]): + main() class TestExitCodes: From b710bd732fb58e7b893ebe22931545b393367987 Mon Sep 17 00:00:00 2001 From: chfw Date: Tue, 24 Sep 2019 22:27:40 +0100 Subject: [PATCH 17/17] :shirt: update change log and version number --- .moban.cd/changelog.yml | 2 +- .moban.cd/moban.yml | 6 +++--- CHANGELOG.rst | 2 +- docs/conf.py | 4 ++-- moban/_version.py | 2 +- setup.py | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index a5fa5a96..b3584f87 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,7 +5,7 @@ releases: - action: Added details: - "`#260`: jinja-cli parity: support command line pipe stream." - date: tbd + date: 25.09.2019 version: 0.6.3 - changes: - action: Added diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 0f245d75..5853522c 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -4,9 +4,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.6.2 -current_version: 0.6.2 -release: 0.6.2 +version: 0.6.3 +current_version: 0.6.3 +release: 0.6.3 branch: master master: index command_line_interface: "moban" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fc148bb6..bf1a2951 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ Change log ================================================================================ -0.6.3 - tbd +0.6.3 - 25.09.2019 -------------------------------------------------------------------------------- Added diff --git a/docs/conf.py b/docs/conf.py index c7d0042f..7378f931 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,9 +25,9 @@ copyright = '2017-2019 Onni Software Ltd.' author = 'C. W.' # The short X.Y version -version = '0.6.2' +version = '0.6.3' # The full version, including alpha/beta/rc tags -release = '0.6.2' +release = '0.6.3' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index bbb51f5d..ed642873 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.6.2" +__version__ = "0.6.3" __author__ = "C. W." diff --git a/setup.py b/setup.py index 1030de0f..08b37c05 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ NAME = "moban" AUTHOR = "C. W." -VERSION = "0.6.2" +VERSION = "0.6.3" EMAIL = "wangc_2011@hotmail.com" LICENSE = "MIT" ENTRY_POINTS = { @@ -50,7 +50,7 @@ "Yet another jinja2 cli command for static text generation" ) URL = "https://github.com/moremoban/moban" -DOWNLOAD_URL = "%s/archive/0.6.2.tar.gz" % URL +DOWNLOAD_URL = "%s/archive/0.6.3.tar.gz" % URL FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"] KEYWORDS = [ "python", @@ -97,8 +97,8 @@ } # You do not need to read beyond this line PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable) -GS_COMMAND = ("gs moban v0.6.2 " + - "Find 0.6.2 in changelog for more details") +GS_COMMAND = ("gs moban v0.6.3 " + + "Find 0.6.3 in changelog for more details") NO_GS_MESSAGE = ("Automatic github release is disabled. " + "Please install gease to enable it.") UPLOAD_FAILED_MSG = (