From ce73e5a1ee32666a75456c849ebe1c180ba5ae0b Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 07:11:48 +0000 Subject: [PATCH 01/17] :fire: replace physical fake moban-mako engine. #156 --- test.bat | 3 --- test.sh | 3 --- tests/moban-mako/moban_mako/__init__.py | 9 ------- tests/moban-mako/setup.py | 36 ------------------------- tests/test_engine.py | 12 ++++++--- 5 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 tests/moban-mako/moban_mako/__init__.py delete mode 100644 tests/moban-mako/setup.py diff --git a/test.bat b/test.bat index 9d124fa6..17ae36a6 100644 --- a/test.bat +++ b/test.bat @@ -1,7 +1,4 @@ pip freeze -cd tests\moban-mako -python setup.py install -cd ..\..\ nosetests --with-coverage --cover-package=moban --cover-package=tests flake8 . --exclude=docs,.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504 diff --git a/test.sh b/test.sh index 3fb012dc..6f15b0f5 100644 --- a/test.sh +++ b/test.sh @@ -1,6 +1,3 @@ pip freeze -cd tests/moban-mako -python setup.py install -cd ../../ nosetests --with-cov --with-doctest --doctest-extension=.rst --cover-package moban --cover-package tests && flake8 . --exclude=.moban.d,docs --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504 diff --git a/tests/moban-mako/moban_mako/__init__.py b/tests/moban-mako/moban_mako/__init__.py deleted file mode 100644 index 5e8d2458..00000000 --- a/tests/moban-mako/moban_mako/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -from lml.plugin import PluginInfo - -from moban.constants import TEMPLATE_ENGINE_EXTENSION - - -@PluginInfo(TEMPLATE_ENGINE_EXTENSION, tags=["mako"]) -class MakoEngine: - def __init__(self, template_dirs): - pass diff --git a/tests/moban-mako/setup.py b/tests/moban-mako/setup.py deleted file mode 100644 index fe8011a9..00000000 --- a/tests/moban-mako/setup.py +++ /dev/null @@ -1,36 +0,0 @@ -""" - moban-mako - ~~~~~~~~~~~~~~ - - It is a test plugin -""" - -try: - from setuptools import setup, find_packages -except ImportError: - from ez_setup import use_setuptools - - use_setuptools() - from setuptools import setup, find_packages - -setup( - name="moban_mako", - author="C. W.", - version="0.0.1", - author_email="wangc_2011 at hotmail.com", - packages=find_packages(exclude=["ez_setup", "examples", "tests"]), - include_package_data=True, - long_description=__doc__, - zip_safe=False, - classifiers=[ - "Development Status :: 3 - Alpha", - "Topic :: Office/Business", - "Topic :: Utilities", - "Topic :: Software Development :: Libraries", - "Programming Language :: Python", - "License :: OSI Approved :: GNU General Public License v3", - "Intended Audience :: Developers", - "Programming Language :: Python :: 2.6", - "Programming Language :: Python :: 2.7", - ], -) diff --git a/tests/test_engine.py b/tests/test_engine.py index 521be93d..447adc51 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -43,9 +43,15 @@ def test_default_template_type(): assert engine.engine_cls == Engine -def test_default_mako_type(): # fake mako - engine = ENGINES.get_engine("mako", [], "") - assert engine.engine_cls.__name__ == "MakoEngine" +class FakeEngine: + def __init__(self, template_dirs): + pass + + +@patch('moban.plugins.PluginManager.load_me_now', return_value=FakeEngine) +def test_default_mako_type(_): # fake mako + engine = ENGINES.get_engine("fake", [], "") + assert engine.engine_cls.__name__ == "FakeEngine" @raises(exceptions.NoThirdPartyEngine) From a962097db402819f10406c8d528a6c738f0b8e8c Mon Sep 17 00:00:00 2001 From: chfw Date: Sun, 6 Jan 2019 14:00:40 +0000 Subject: [PATCH 02/17] :sparkles: use template string as an input for '-t'. resolve #154 --- moban/jinja2/engine.py | 13 ++++++++++--- moban/plugins.py | 31 +++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/moban/jinja2/engine.py b/moban/jinja2/engine.py index eef41c02..10a59726 100644 --- a/moban/jinja2/engine.py +++ b/moban/jinja2/engine.py @@ -1,8 +1,9 @@ -from jinja2 import Environment, FileSystemLoader +from jinja2 import Template, Environment, FileSystemLoader from lml.loader import scan_plugins_regex from lml.plugin import PluginInfo, PluginManager +from jinja2.exceptions import TemplateNotFound -import moban.constants as constants +from moban import constants, exceptions JINJA2_LIBRARIES = "^moban_jinja2_.+$" JINJA2_EXENSIONS = [ @@ -91,9 +92,15 @@ def get_template(self, template_file): template file exists at: '/User/moban-pro/my-template/templates/myfile.jj2' """ - template = self.jj2_environment.get_template(template_file) + try: + template = self.jj2_environment.get_template(template_file) + except TemplateNotFound: + raise exceptions.FileNotFound("%s does not exist" % template_file) return template + def get_template_from_string(self, string): + return Template(string) + def apply_template(self, template, data, output): """ It is not expected this function to write content to file system. diff --git a/moban/plugins.py b/moban/plugins.py index a258fe2a..4b7b5927 100644 --- a/moban/plugins.py +++ b/moban/plugins.py @@ -48,10 +48,15 @@ def number_of_templated_files(self): def render_to_file(self, template_file, data_file, output_file): self.file_count = 1 data = self.context.get_data(data_file) - template = self.engine.get_template(template_file) - template_abs_path = utils.get_template_path( - self.template_dirs, template_file - ) + try: + template = self.engine.get_template(template_file) + template_abs_path = utils.get_template_path( + self.template_dirs, template_file + ) + except exceptions.TemplateFileMissing: + template = self.engine.get_template_from_string(template_file) + template_abs_path = "string template" + flag = self.apply_template( template_abs_path, template, data, output_file ) @@ -65,15 +70,21 @@ def apply_template(self, template_abs_path, template, data, output_file): ) rendered_content = utils.strip_off_trailing_new_lines(rendered_content) rendered_content = rendered_content.encode("utf-8") - flag = HASH_STORE.is_file_changed( - output_file, rendered_content, template_abs_path - ) - if flag: + try: + flag = HASH_STORE.is_file_changed( + output_file, rendered_content, template_abs_path + ) + if flag: + utils.write_file_out( + output_file, rendered_content, strip=False, encode=False + ) + utils.file_permissions_copy(template_abs_path, output_file) + return flag + except exceptions.FileNotFound: utils.write_file_out( output_file, rendered_content, strip=False, encode=False ) - utils.file_permissions_copy(template_abs_path, output_file) - return flag + return True def render_to_files(self, array_of_param_tuple): sta = Strategy(array_of_param_tuple) From f0d28a617accd1be4e729505b1c1dd0b67b76389 Mon Sep 17 00:00:00 2001 From: chfw Date: Sun, 6 Jan 2019 14:23:54 +0000 Subject: [PATCH 03/17] :sparkles: provide short form string template. #154 --- moban/constants.py | 1 + moban/main.py | 15 ++++++++++++++- moban/plugins.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/moban/constants.py b/moban/constants.py index ae11d2f9..fb21c2e0 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -21,6 +21,7 @@ LABEL_CONFIG_DIR = "configuration_dir" LABEL_PLUGIN_DIRS = "plugin_dir" LABEL_TEMPLATE = "template" +POSITIONAL_LABEL_TEMPLATE = "template2" LABEL_TMPL_DIRS = "template_dir" LABEL_OUTPUT = "output" LABEL_TEMPLATE_TYPE = "template_type" diff --git a/moban/main.py b/moban/main.py index 17e75722..c4aa696b 100644 --- a/moban/main.py +++ b/moban/main.py @@ -94,6 +94,13 @@ def create_parser(): parser.add_argument( "-m", "--%s" % constants.LABEL_MOBANFILE, help="custom moban file" ) + parser.add_argument( + constants.POSITIONAL_LABEL_TEMPLATE, + metavar="template", + type=str, + nargs="?", + help="string templates", + ) return parser @@ -153,8 +160,14 @@ def handle_command_line(options): act upon command options """ options = merge(options, constants.DEFAULT_OPTIONS) + print(options) if options[constants.LABEL_TEMPLATE] is None: - raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) + if options[constants.POSITIONAL_LABEL_TEMPLATE] is None: + raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) + else: + options[constants.LABEL_TEMPLATE] = options[ + constants.POSITIONAL_LABEL_TEMPLATE + ] engine = plugins.ENGINES.get_engine( options[constants.LABEL_TEMPLATE_TYPE], options[constants.LABEL_TMPL_DIRS], diff --git a/moban/plugins.py b/moban/plugins.py index 4b7b5927..fc332414 100644 --- a/moban/plugins.py +++ b/moban/plugins.py @@ -53,7 +53,7 @@ def render_to_file(self, template_file, data_file, output_file): template_abs_path = utils.get_template_path( self.template_dirs, template_file ) - except exceptions.TemplateFileMissing: + except exceptions.FileNotFound: template = self.engine.get_template_from_string(template_file) template_abs_path = "string template" From 9585cdc17df33d85584fd6ceb8df5ce961d550af Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 08:03:35 +0000 Subject: [PATCH 04/17] :hammer: code refactoring --- moban/constants.py | 2 +- moban/main.py | 28 +++++++++++++++------------- moban/plugins.py | 26 ++++++++++++++++++-------- tests/test_engine.py | 13 ++++++++++++- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/moban/constants.py b/moban/constants.py index fb21c2e0..d02aed8f 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -21,7 +21,7 @@ LABEL_CONFIG_DIR = "configuration_dir" LABEL_PLUGIN_DIRS = "plugin_dir" LABEL_TEMPLATE = "template" -POSITIONAL_LABEL_TEMPLATE = "template2" +POSITIONAL_LABEL_TEMPLATE = "template_in_string" LABEL_TMPL_DIRS = "template_dir" LABEL_OUTPUT = "output" LABEL_TEMPLATE_TYPE = "template_type" diff --git a/moban/main.py b/moban/main.py index c4aa696b..0ece570e 100644 --- a/moban/main.py +++ b/moban/main.py @@ -160,24 +160,26 @@ def handle_command_line(options): act upon command options """ options = merge(options, constants.DEFAULT_OPTIONS) - print(options) - if options[constants.LABEL_TEMPLATE] is None: - if options[constants.POSITIONAL_LABEL_TEMPLATE] is None: - raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE) - else: - options[constants.LABEL_TEMPLATE] = options[ - constants.POSITIONAL_LABEL_TEMPLATE - ] engine = plugins.ENGINES.get_engine( options[constants.LABEL_TEMPLATE_TYPE], options[constants.LABEL_TMPL_DIRS], options[constants.LABEL_CONFIG_DIR], ) - engine.render_to_file( - options[constants.LABEL_TEMPLATE], - options[constants.LABEL_CONFIG], - options[constants.LABEL_OUTPUT], - ) + if options[constants.LABEL_TEMPLATE] is None: + if options[constants.POSITIONAL_LABEL_TEMPLATE] 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], + ) + else: + engine.render_to_file( + options[constants.LABEL_TEMPLATE], + options[constants.LABEL_CONFIG], + options[constants.LABEL_OUTPUT], + ) engine.report() HASH_STORE.save_hashes() exit_code = reporter.convert_to_shell_exit_code( diff --git a/moban/plugins.py b/moban/plugins.py index fc332414..5ba36cee 100644 --- a/moban/plugins.py +++ b/moban/plugins.py @@ -48,14 +48,10 @@ def number_of_templated_files(self): def render_to_file(self, template_file, data_file, output_file): self.file_count = 1 data = self.context.get_data(data_file) - try: - template = self.engine.get_template(template_file) - template_abs_path = utils.get_template_path( - self.template_dirs, template_file - ) - except exceptions.FileNotFound: - template = self.engine.get_template_from_string(template_file) - template_abs_path = "string template" + template = self.engine.get_template(template_file) + template_abs_path = utils.get_template_path( + self.template_dirs, template_file + ) flag = self.apply_template( template_abs_path, template, data, output_file @@ -64,6 +60,20 @@ def render_to_file(self, template_file, data_file, output_file): reporter.report_templating(template_file, output_file) self.templated_count += 1 + def render_string_to_file( + self, template_in_string, data_file, output_file + ): + self.file_count = 1 + template = self.engine.get_template_from_string(template_in_string) + template_abs_path = template_in_string[:10] + "..." + data = self.context.get_data(data_file) + flag = self.apply_template( + template_abs_path, template, data, output_file + ) + if flag: + reporter.report_templating(template_abs_path, output_file) + self.templated_count += 1 + def apply_template(self, template_abs_path, template, data, output_file): rendered_content = self.engine.apply_template( template, data, output_file diff --git a/tests/test_engine.py b/tests/test_engine.py index 447adc51..9ce98862 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -48,7 +48,7 @@ def __init__(self, template_dirs): pass -@patch('moban.plugins.PluginManager.load_me_now', return_value=FakeEngine) +@patch("moban.plugins.PluginManager.load_me_now", return_value=FakeEngine) def test_default_mako_type(_): # fake mako engine = ENGINES.get_engine("fake", [], "") assert engine.engine_cls.__name__ == "FakeEngine" @@ -119,3 +119,14 @@ def test_environ_variables_as_data(): content = output_file.read() eq_(content, "foo") os.unlink(output) + + +def test_string_template(): + output = "test.txt" + path = os.path.join("tests", "fixtures") + engine = BaseEngine([path], path, Engine) + engine.render_string_to_file("{{simple}}", "simple.yaml", output) + with open(output, "r") as output_file: + content = output_file.read() + eq_(content, "yaml") + os.unlink(output) From e86fd1c752e045129447f5be6a5f564d5da6e9ff Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 08:09:27 +0000 Subject: [PATCH 05/17] :microscope: test command line options --- tests/integration_tests/test_command_line_options.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index a4c667c9..666fe3f8 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -82,6 +82,18 @@ def test_default_options(self, fake_template_doer): "a.jj2", "data.yml", "moban.output" ) + @patch("moban.plugins.BaseEngine.render_string_to_file") + def test_string_template(self, fake_template_doer): + string_template = "{{HELLO}}" + test_args = ["moban", string_template] + with patch.object(sys, "argv", test_args): + from moban.main import main + + main() + fake_template_doer.assert_called_with( + string_template, "data.yml", "moban.output" + ) + @raises(SystemExit) def test_no_argments(self): test_args = ["moban"] From 0e1af854bb74627035c613862557c613da64d74a Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 18:04:53 +0000 Subject: [PATCH 06/17] :microscope: test jinja2 engine get template from string --- tests/test_jinja2_engine.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test_jinja2_engine.py b/tests/test_jinja2_engine.py index d3d888f1..1a979971 100644 --- a/tests/test_jinja2_engine.py +++ b/tests/test_jinja2_engine.py @@ -5,7 +5,7 @@ from moban.jinja2.engine import Engine -def test_handlebars_template_not_found(): +def test_jinja2_template(): path = os.path.join("tests", "fixtures", "jinja_tests") engine = Engine([path]) template = engine.get_template("file_tests.template") @@ -13,3 +13,13 @@ def test_handlebars_template_not_found(): result = engine.apply_template(template, data, None) expected = "yes\nhere" eq_(expected, result) + + +def test_jinja2_template_string(): + path = os.path.join("tests", "fixtures", "jinja_tests") + engine = Engine([path]) + template = engine.get_template_from_string("{{test}}") + data = dict(test="here") + result = engine.apply_template(template, data, None) + expected = "here" + eq_(expected, result) From 5d6470e294b28899a982d1b46623fa09945579d2 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 18:10:01 +0000 Subject: [PATCH 07/17] :books: update readme --- README.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e699b4f4..075c2ac3 100644 --- a/README.rst +++ b/README.rst @@ -50,7 +50,17 @@ or clone it and install it: Quick start ================================================================================ -Here is a simple example: +.. code-block:: bash + + $ HELLO="world" moban "{{HELLO}}" + Warning: Both data.yml and /.../.moban.cd/data.yml does not exist + Warning: Attempting to use environment vars as data... + Templating {{HELLO}}... to moban.output + Templated 1 file. + $ cat moban.output + world + +A bit formal example: .. code-block:: bash From 5c2326a0d64a4e75b01196a1a96306d10879c4d2 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 18:11:45 +0000 Subject: [PATCH 08/17] :books: command options update --- README.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 075c2ac3..ceb401bb 100644 --- a/README.rst +++ b/README.rst @@ -87,15 +87,19 @@ moban.output will contain:: Usage ================================================================================ -:: +code-block:: bash usage: moban [-h] [-cd CONFIGURATION_DIR] [-c CONFIGURATION] [-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]] [-t TEMPLATE] [-o OUTPUT] [-f] [-m MOBANFILE] - + [template] + Yet another jinja2 cli command for static text generation + positional arguments: + template string templates + optional arguments: -h, --help show this help message and exit -cd CONFIGURATION_DIR, --configuration_dir CONFIGURATION_DIR From 6cfafdee8e389e42cd1440dc74cc9099eb6b9e45 Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 18:16:46 +0000 Subject: [PATCH 09/17] :books: explain environment variables. resolves #155 --- README.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ceb401bb..71dd2757 100644 --- a/README.rst +++ b/README.rst @@ -52,7 +52,8 @@ Quick start .. code-block:: bash - $ HELLO="world" moban "{{HELLO}}" + $ export HELLO="world" + $ moban "{{HELLO}}" Warning: Both data.yml and /.../.moban.cd/data.yml does not exist Warning: Attempting to use environment vars as data... Templating {{HELLO}}... to moban.output @@ -60,6 +61,12 @@ Quick start $ cat moban.output world +Or simply +.. code-block:: bash + + $ HELLO="world" moban "{{HELLO}}" + + A bit formal example: .. code-block:: bash @@ -79,6 +86,8 @@ moban.output will contain:: world +Please note that data.yml will take precedence over environment variables. + `the tutorial`_ has more use cases. .. _the tutorial: http://moban.readthedocs.org/en/latest/#tutorial From 7909bc97475369c8e166ae9e1e110101f6e5930d Mon Sep 17 00:00:00 2001 From: chfw Date: Thu, 10 Jan 2019 18:18:08 +0000 Subject: [PATCH 10/17] :lipstick: update version number --- .moban.cd/changelog.yml | 6 ++++++ .moban.cd/moban.yml | 6 +++--- CHANGELOG.rst | 9 +++++++++ docs/conf.py | 4 ++-- moban/_version.py | 2 +- setup.py | 8 ++++---- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index c6563382..452d5d2d 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: +- changes: + - action: Updated + details: + - "`#154`: introduce first ever positional argument for string base template." + date: 11-1-2019 + version: 0.3.8 - changes: - action: Updated details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 96a4c863..e354076a 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -3,9 +3,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.3.7 -current_version: 0.3.7 -release: 0.3.7 +version: 0.3.8 +current_version: 0.3.8 +release: 0.3.8 branch: master command_line_interface: "moban" entry_point: "moban.main:main" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e3d12085..fcf58fae 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.3.8 - 11-1-2019 +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#154 `_: introduce first ever + positional argument for string base template. + 0.3.7 - 6-1-2019 -------------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index b8bd3a7b..ce753fd0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,9 +28,9 @@ author = u'C. W.' # The short X.Y version -version = u'0.3.7' +version = u'0.3.8' # The full version, including alpha/beta/rc tags -release = u'0.3.7' +release = u'0.3.8' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index 2c02a9fe..846cb583 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.7" +__version__ = "0.3.8" __author__ = "C. W." diff --git a/setup.py b/setup.py index dbaca9af..decfd6ff 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ NAME = 'moban' AUTHOR = 'C. W.' -VERSION = '0.3.7' +VERSION = '0.3.8' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'MIT' ENTRY_POINTS = { @@ -25,7 +25,7 @@ 'Yet another jinja2 cli command for static text generation' ) URL = 'https://github.com/moremoban/moban' -DOWNLOAD_URL = '%s/archive/0.3.7.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.3.8.tar.gz' % URL FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'python', @@ -60,8 +60,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.3.7 ' + - "Find 0.3.7 in changelog for more details") +GS_COMMAND = ('gs moban v0.3.8 ' + + "Find 0.3.8 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = ( From ce9e9a5886a0a6cd74d28ec70451218e1467d9e7 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 11 Jan 2019 07:02:44 +0000 Subject: [PATCH 11/17] :books: minor update on README --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 71dd2757..d2ca5894 100644 --- a/README.rst +++ b/README.rst @@ -62,6 +62,7 @@ Quick start world Or simply + .. code-block:: bash $ HELLO="world" moban "{{HELLO}}" From a0cf4dfdb180bd6382a7c1a12c8594e31e1ae278 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 11 Jan 2019 07:03:31 +0000 Subject: [PATCH 12/17] :books: minor update on README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index d2ca5894..ad1fc166 100644 --- a/README.rst +++ b/README.rst @@ -97,7 +97,7 @@ Please note that data.yml will take precedence over environment variables. Usage ================================================================================ -code-block:: bash +.. code-block:: bash usage: moban [-h] [-cd CONFIGURATION_DIR] [-c CONFIGURATION] From 39b544d2089f35da0cb70fb5efb5e3169767fa5b Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 11 Jan 2019 08:01:20 +0000 Subject: [PATCH 13/17] :sparkles: update exit code. resolves #157. update #14. --- .moban.cd/changelog.yml | 1 + CHANGELOG.rst | 3 +++ README.rst | 9 ++++++++- moban/constants.py | 1 + moban/main.py | 26 ++++++++++++++++++++------ tests/test_main.py | 26 +++++++++++++++++++++++++- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 452d5d2d..481e9e5b 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,6 +5,7 @@ releases: - action: Updated details: - "`#154`: introduce first ever positional argument for string base template." + - "`#157`: the exit code behavior changed. for backward compactibility please use --exit-code. Otherwise, moban will not tell if there is any changes." date: 11-1-2019 version: 0.3.8 - changes: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fcf58fae..f83a2b62 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,9 @@ Updated #. `#154 `_: introduce first ever positional argument for string base template. +#. `#157 `_: the exit code + behavior changed. for backward compactibility please use --exit-code. + Otherwise, moban will not tell if there is any changes. 0.3.7 - 6-1-2019 -------------------------------------------------------------------------------- diff --git a/README.rst b/README.rst index ad1fc166..00cdd090 100644 --- a/README.rst +++ b/README.rst @@ -128,12 +128,19 @@ Usage the template type, default is jinja2 -f force moban to template all files despite of .moban.hashes + --exit-code tell moban to change exit code -m MOBANFILE, --mobanfile MOBANFILE custom moban file -exit codes +Exit codes -------------------------------------------------------------------------------- +By default: + +- 0 : no changes +- 1 : error occured + +With `--exit-code`: - 0 : no changes - 1 : has changes diff --git a/moban/constants.py b/moban/constants.py index d02aed8f..a667e874 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -31,6 +31,7 @@ LABEL_MOBANFILE = "mobanfile" LABEL_FORCE = "force" LABEL_REQUIRES = "requires" +LABEL_EXIT_CODE = "exit-code" DEFAULT_CONFIGURATION_DIRNAME = ".moban.cd" DEFAULT_TEMPLATE_DIRNAME = ".moban.td" diff --git a/moban/main.py b/moban/main.py index 0ece570e..f811efa0 100644 --- a/moban/main.py +++ b/moban/main.py @@ -34,23 +34,30 @@ def main(): if moban_file: try: count = handle_moban_file(moban_file, options) - if count: - sys.exit(count) + moban_exit(options[constants.LABEL_EXIT_CODE], count) except ( exceptions.DirectoryNotFound, exceptions.NoThirdPartyEngine, exceptions.MobanfileGrammarException, ) as e: reporter.report_error_message(str(e)) - sys.exit(constants.ERROR) + moban_exit(options[constants.LABEL_EXIT_CODE], constants.ERROR) else: try: count = handle_command_line(options) - if count: - sys.exit(count) + moban_exit(options[constants.LABEL_EXIT_CODE], count) except exceptions.NoTemplate as e: reporter.report_error_message(str(e)) - sys.exit(constants.ERROR) + moban_exit(options[constants.LABEL_EXIT_CODE], constants.ERROR) + + +def moban_exit(exit_code_toggle_flag, exit_code): + if exit_code_toggle_flag: + if exit_code: + sys.exit(exit_code) + else: + if exit_code == constants.ERROR: + sys.exit(1) def create_parser(): @@ -91,6 +98,13 @@ def create_parser(): default=False, help="force moban to template all files despite of .moban.hashes", ) + parser.add_argument( + "--%s" % constants.LABEL_EXIT_CODE, + action="store_true", + dest=constants.LABEL_EXIT_CODE, + default=False, + help="tell moban to change exit code", + ) parser.add_argument( "-m", "--%s" % constants.LABEL_MOBANFILE, help="custom moban file" ) diff --git a/tests/test_main.py b/tests/test_main.py index 308e8b64..0d73f7b2 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -137,6 +137,31 @@ def tearDown(self): os.unlink(".moban.hashes") @raises(SystemExit) + @patch("moban.main.handle_moban_file") + @patch("moban.mobanfile.find_default_moban_file") + def test_has_many_files_with_exit_code( + self, fake_find_file, fake_moban_file + ): + fake_find_file.return_value = "abc" + fake_moban_file.return_value = 1 + from moban.main import main + + with patch.object(sys, "argv", ["moban", "--exit-code"]): + main() + + @raises(SystemExit) + @patch("moban.main.handle_command_line") + @patch("moban.mobanfile.find_default_moban_file") + def test_handle_single_change_with_exit_code( + self, fake_find_file, fake_command_line + ): + fake_find_file.return_value = None + fake_command_line.return_value = 1 + from moban.main import main + + with patch.object(sys, "argv", ["moban", "--exit-code"]): + main() + @patch("moban.main.handle_moban_file") @patch("moban.mobanfile.find_default_moban_file") def test_has_many_files(self, fake_find_file, fake_moban_file): @@ -147,7 +172,6 @@ def test_has_many_files(self, fake_find_file, fake_moban_file): with patch.object(sys, "argv", ["moban"]): main() - @raises(SystemExit) @patch("moban.main.handle_command_line") @patch("moban.mobanfile.find_default_moban_file") def test_handle_single_change(self, fake_find_file, fake_command_line): From c821119b99e1b971125ec2b8d25f860354a3f0dd Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 11 Jan 2019 08:11:14 +0000 Subject: [PATCH 14/17] :sparkles: disable file permission related feature: permission copying and file changes. resolve #141 --- .moban.cd/changelog.yml | 1 + CHANGELOG.rst | 2 ++ moban/utils.py | 2 ++ tests/test_utils.py | 8 ++++++++ 4 files changed, 13 insertions(+) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 452d5d2d..ddd8bcb3 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,6 +5,7 @@ releases: - action: Updated details: - "`#154`: introduce first ever positional argument for string base template." + - "`#141`: disable file permissions copy feature and not to check file permission changes on windows." date: 11-1-2019 version: 0.3.8 - changes: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fcf58fae..0260e6d7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Updated #. `#154 `_: introduce first ever positional argument for string base template. +#. `#141 `_: disable file + permissions copy feature and not to check file permission changes on windows. 0.3.7 - 6-1-2019 -------------------------------------------------------------------------------- diff --git a/moban/utils.py b/moban/utils.py index 7d542909..36de191b 100644 --- a/moban/utils.py +++ b/moban/utils.py @@ -126,6 +126,8 @@ def file_permissions_copy(source, dest): def file_permissions(afile): + if sys.platform == "win32": + return "no-permission-support" if not os.path.exists(afile): raise exceptions.FileNotFound(afile) return stat.S_IMODE(os.stat(afile).st_mode) diff --git a/tests/test_utils.py b/tests/test_utils.py index cd3a4bf8..56ed331d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -44,6 +44,14 @@ def test_file_permission_copy(): os.unlink(test_dest) +def file_permissions_disabled_on_windows(): + if sys.platform == 'win32': + permissions = file_permissions('abc') + eq_('no-permission-support', permissions) + else: + raise SkipTest("No test required") + + @raises(FileNotFound) def test_file_permissions_file_not_found(): file_permissions("I does not exist") From 697f31693a85c6f69f21817b529eff3777d3ce81 Mon Sep 17 00:00:00 2001 From: chfw Date: Fri, 11 Jan 2019 18:18:21 +0000 Subject: [PATCH 15/17] :books: update change log --- .moban.cd/changelog.yml | 4 ++-- CHANGELOG.rst | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index f71993d6..a8b54c02 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -4,10 +4,10 @@ releases: - changes: - action: Updated details: - - "`#154`: introduce first ever positional argument for string base template." - "`#141`: disable file permissions copy feature and not to check file permission changes on windows." + - "`#154`: introduce first ever positional argument for string base template." - "`#157`: the exit code behavior changed. for backward compactibility please use --exit-code. Otherwise, moban will not tell if there is any changes." - date: 11-1-2019 + date: 12-1-2019 version: 0.3.8 - changes: - action: Updated diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e6926e9..0b9b467e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,16 +1,16 @@ Change log ================================================================================ -0.3.8 - 11-1-2019 +0.3.8 - 12-1-2019 -------------------------------------------------------------------------------- Updated ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -#. `#154 `_: introduce first ever - positional argument for string base template. #. `#141 `_: disable file permissions copy feature and not to check file permission changes on windows. +#. `#154 `_: introduce first ever + positional argument for string base template. #. `#157 `_: the exit code behavior changed. for backward compactibility please use --exit-code. Otherwise, moban will not tell if there is any changes. From fdc40d107e9a0537752d9a5a88170da214546171 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 12 Jan 2019 15:27:18 +0000 Subject: [PATCH 16/17] :microscope: enable hash store test on windows --- tests/test_hash_store.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_hash_store.py b/tests/test_hash_store.py index 659b3b5b..51e43dac 100644 --- a/tests/test_hash_store.py +++ b/tests/test_hash_store.py @@ -1,7 +1,4 @@ import os -import sys - -from nose import SkipTest from moban.hashstore import HashStore @@ -80,8 +77,6 @@ def test_dest_file_file_permision_changed(self): Save as above, but this time, the generated file had file permision change """ - if sys.platform == "win32": - raise SkipTest("No actual chmod on windows") hs = HashStore() flag = hs.is_file_changed(*self.fixture) if flag: From bb8c747a608c8d84def726ad5924a66672c2b89e Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 12 Jan 2019 19:28:56 +0000 Subject: [PATCH 17/17] :fire: remove python 3.4 so that each travis-ci test will finish sooner under 5 parallel job quota --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8295c536..16330f5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ python: - 3.7-dev - 3.6 - 3.5 - - 3.4 - 2.7 before_install: - if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi