diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index d6e6d4ab..b3584f87 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: 25.09.2019 + version: 0.6.3 - changes: - action: Added details: 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 e271273f..bf1a2951 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.6.3 - 25.09.2019 +-------------------------------------------------------------------------------- + +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 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/moban/main.py b/moban/main.py index d8d66563..96f3e569 100644 --- a/moban/main.py +++ b/moban/main.py @@ -229,14 +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 = options[constants.POSITIONAL_LABEL_TEMPLATE] + if content is None: + 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) - else: - engine.render_string_to_file( - options[constants.POSITIONAL_LABEL_TEMPLATE], - options[constants.LABEL_CONFIG], - options[constants.LABEL_OUTPUT], - ) + + engine.render_string_to_file( + content, + options[constants.LABEL_CONFIG], + options[constants.LABEL_OUTPUT], + ) else: engine.render_to_file( options[constants.LABEL_TEMPLATE], 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 = ( 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 bd333cf0..0a2bc8e7 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -2,11 +2,16 @@ 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 +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + class TestCustomOptions: def setUp(self): @@ -54,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() @@ -100,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() @@ -524,3 +533,18 @@ def test_add_extension(): "{}.{}".format(sys.version_info[0], sys.version_info[1]), ) os.unlink("moban.output") + + +def test_stdin_input(): + 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}}")): + 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") 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 diff --git a/tests/test_main.py b/tests/test_main.py index 96adba08..0de35825 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") @@ -100,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") @@ -114,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: