From db90855069ac8de5bfaa755cc72e3d3644d90a97 Mon Sep 17 00:00:00 2001 From: chfw Date: Mon, 9 Sep 2019 08:01:02 +0100 Subject: [PATCH 1/4] prototype --- moban/mobanfile/targets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/moban/mobanfile/targets.py b/moban/mobanfile/targets.py index 161de814..e4158196 100644 --- a/moban/mobanfile/targets.py +++ b/moban/mobanfile/targets.py @@ -132,6 +132,10 @@ def _handle_implicit_target(options, template_file, output): template_file, output, options[constants.LABEL_TMPL_DIRS] ): if t_type: + # now if t_type is the same as dest file's extension + # it should be 'copy' + if dest.endswith('.' + t_type): + t_type = constants.TEMPLATE_COPY yield TemplateTarget(src, common_data_file, dest, t_type) else: yield TemplateTarget( From 1a3f0feb4f3819f95ee72c2a281e99d405385c4a Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 11 Sep 2019 22:18:40 +0100 Subject: [PATCH 2/4] :sparkles: nice add-on for implicit target syntax. resolves #322 --- docs/level-15-copy-templates-as-target/.moban.yml | 1 + docs/level-15-copy-templates-as-target/README.rst | 3 ++- .../template-sources/when_source_have.same_file_extension | 1 + moban/definitions.py | 5 +++++ moban/mobanfile/targets.py | 4 ---- moban/mobanfile/templates.py | 5 ++++- tests/test_docs.py | 4 ++++ 7 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 docs/level-15-copy-templates-as-target/template-sources/when_source_have.same_file_extension diff --git a/docs/level-15-copy-templates-as-target/.moban.yml b/docs/level-15-copy-templates-as-target/.moban.yml index 72351dd3..2771111d 100644 --- a/docs/level-15-copy-templates-as-target/.moban.yml +++ b/docs/level-15-copy-templates-as-target/.moban.yml @@ -8,6 +8,7 @@ targets: - output: target_without_template_type template: file_extension_will_trigger.copy - target_in_short_form: as_long_as_this_one_has.copy + - output_is_copied.same_file_extension: when_source_have.same_file_extension - output: "misc-1-copying/can-create-folder/if-not-exists.txt" template: file-in-template-sources-folder.txt template_type: copy diff --git a/docs/level-15-copy-templates-as-target/README.rst b/docs/level-15-copy-templates-as-target/README.rst index 2e73a082..a153a0b5 100644 --- a/docs/level-15-copy-templates-as-target/README.rst +++ b/docs/level-15-copy-templates-as-target/README.rst @@ -23,7 +23,7 @@ Shorthand syntax:: targets: - explicit: template_file.copy - + - output_is_copied.same_file_extension: when_source_have.same_file_extension No implicit nor short hand syntax for the following directory copying unless you take a look at `force-template-type`. When you read @@ -64,6 +64,7 @@ Here is example moban file for copying:: - output: target_without_template_type template: file_extension_will_trigger.copy - target_in_short_form: as_long_as_this_one_has.copy + - output_is_copied.same_file_extension: when_source_have.same_file_extension - output: "misc-1-copying/can-create-folder/if-not-exists.txt" template: file-in-template-sources-folder.txt template_type: copy diff --git a/docs/level-15-copy-templates-as-target/template-sources/when_source_have.same_file_extension b/docs/level-15-copy-templates-as-target/template-sources/when_source_have.same_file_extension new file mode 100644 index 00000000..6ee981e1 --- /dev/null +++ b/docs/level-15-copy-templates-as-target/template-sources/when_source_have.same_file_extension @@ -0,0 +1 @@ +it is implicit copy as well \ No newline at end of file diff --git a/moban/definitions.py b/moban/definitions.py index 982e3e5d..e72f3d88 100644 --- a/moban/definitions.py +++ b/moban/definitions.py @@ -1,5 +1,9 @@ +import logging + from moban import constants +LOG = logging.getLogger(__name__) + class TemplateTarget(object): def __init__( @@ -16,6 +20,7 @@ def __init__( self.output = self.original_output self.set_template_type(template_type) + LOG.info("create a target {}".format(self)) def set_template_type(self, new_template_type): self.template_type = new_template_type diff --git a/moban/mobanfile/targets.py b/moban/mobanfile/targets.py index e4158196..161de814 100644 --- a/moban/mobanfile/targets.py +++ b/moban/mobanfile/targets.py @@ -132,10 +132,6 @@ def _handle_implicit_target(options, template_file, output): template_file, output, options[constants.LABEL_TMPL_DIRS] ): if t_type: - # now if t_type is the same as dest file's extension - # it should be 'copy' - if dest.endswith('.' + t_type): - t_type = constants.TEMPLATE_COPY yield TemplateTarget(src, common_data_file, dest, t_type) else: yield TemplateTarget( diff --git a/moban/mobanfile/templates.py b/moban/mobanfile/templates.py index 4042ac0e..354202a3 100644 --- a/moban/mobanfile/templates.py +++ b/moban/mobanfile/templates.py @@ -1,6 +1,6 @@ import logging -from moban import reporter, file_system +from moban import reporter, file_system, constants LOG = logging.getLogger(__name__) @@ -33,6 +33,9 @@ def handle_template(template_file, output, template_dirs): yield a_triple else: template_type = _get_template_type(template_file) + # output.jj2: source.jj2 means 'copy' + if template_type and output.endswith("." + template_type): + template_type = constants.TEMPLATE_COPY yield (template_file, output, template_type) diff --git a/tests/test_docs.py b/tests/test_docs.py index 2c711357..e3cc36e9 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -233,6 +233,10 @@ def test_level_15_copy_templates_as_target(self): + "so as to trigger ContentForwardEngine, 'copy' engine.\n" ), ), + ( + "output_is_copied.same_file_extension", + "it is implicit copy as well", + ), ] self.run_moban(["moban"], folder, assertions) From 8caf451279dc60c46bb09dc637f6a28836515ce1 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 11 Sep 2019 22:30:17 +0100 Subject: [PATCH 3/4] :shirt: update coding style --- .moban.d/{setup.py => moban_setup.py.jj2} | 0 moban/mobanfile/templates.py | 7 ++++++- mobanfile | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) rename .moban.d/{setup.py => moban_setup.py.jj2} (100%) diff --git a/.moban.d/setup.py b/.moban.d/moban_setup.py.jj2 similarity index 100% rename from .moban.d/setup.py rename to .moban.d/moban_setup.py.jj2 diff --git a/moban/mobanfile/templates.py b/moban/mobanfile/templates.py index 354202a3..893ee09d 100644 --- a/moban/mobanfile/templates.py +++ b/moban/mobanfile/templates.py @@ -1,6 +1,6 @@ import logging -from moban import reporter, file_system, constants +from moban import reporter, constants, file_system LOG = logging.getLogger(__name__) @@ -35,6 +35,11 @@ def handle_template(template_file, output, template_dirs): template_type = _get_template_type(template_file) # output.jj2: source.jj2 means 'copy' if template_type and output.endswith("." + template_type): + LOG.info( + "template type switched to from {0} to {1}".format( + template_type, constants.TEMPLATE_COPY + ) + ) template_type = constants.TEMPLATE_COPY yield (template_file, output, template_type) diff --git a/mobanfile b/mobanfile index 13ba64bc..e284e011 100644 --- a/mobanfile +++ b/mobanfile @@ -4,7 +4,7 @@ configuration: - ".moban.d" configuration: moban.yml targets: - - setup.py: setup.py + - setup.py: moban_setup.py.jj2 - moban/__init__.py: __init__.py.jj2 - moban/_version.py: _version.py.jj2 - docs/conf.py: custom_conf.py.jj2 From 4a669c7ff57a392d4b500250f5d7da54fac5e750 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 11 Sep 2019 22:34:10 +0100 Subject: [PATCH 4/4] :books: update change log and pump up version number --- .moban.cd/changelog.yml | 6 ++++++ .moban.cd/moban.yml | 4 ++-- CHANGELOG.rst | 11 ++++++++++- docs/conf.py | 2 +- moban/_version.py | 2 +- setup.py | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 50692331..175c5d8f 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -3,6 +3,12 @@ organisation: moremoban releases: - changes: - action: Added + details: + - "`#322`: Implicit targets with template extensions default to copy" + date: tbd + version: 0.6.2 + - changes: + - action: Fixed details: - "`#328`: update backward compatibility" date: 10.09.2019 diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index b92eef9d..6acc0cb6 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -4,8 +4,8 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.6.1 -current_version: 0.6.1 +version: 0.6.2 +current_version: 0.6.2 release: 0.6.1 branch: master master: index diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3213bdc9..2e7e14c8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,12 +1,21 @@ Change log ================================================================================ -0.6.1 - 10.09.2019 +0.6.2 - tbd -------------------------------------------------------------------------------- Added ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +#. `#322 `_: Implicit targets + with template extensions default to copy + +0.6.1 - 10.09.2019 +-------------------------------------------------------------------------------- + +Fixed +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + #. `#328 `_: update backward compatibility diff --git a/docs/conf.py b/docs/conf.py index 21913442..1bdbbf0e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ copyright = '2017-2019 Onni Software Ltd.' author = 'C. W.' # The short X.Y version -version = '0.6.1' +version = '0.6.2' # The full version, including alpha/beta/rc tags release = '0.6.1' diff --git a/moban/_version.py b/moban/_version.py index 6f26cf69..bbb51f5d 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.6.1" +__version__ = "0.6.2" __author__ = "C. W." diff --git a/setup.py b/setup.py index dcbae103..d2b70c4a 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ NAME = "moban" AUTHOR = "C. W." -VERSION = "0.6.1" +VERSION = "0.6.2" EMAIL = "wangc_2011@hotmail.com" LICENSE = "MIT" ENTRY_POINTS = {