From 8ee45b0dacbbf5fb33dd87f44cf16b44e6bcbe32 Mon Sep 17 00:00:00 2001 From: jaska Date: Sat, 12 Oct 2019 20:40:27 +0100 Subject: [PATCH] :sparkles: Int targets (#343) * :sparkles: prototype to support intermediate targets. step 1 for #335 * :sparkles: synchronize with pypi-mobans * :microscope: :books: test and document intermediate targets] * :shirt: coding style fix * :shirt: fix yaml lint warning * :green_heart: fix broken tests * :green_heart: make sure store is empty before next parsing session * :hammer: code refactoring * :books: update change log * :microscope: more tests * :green_heart: update unit test * :books: update doc * :books: update documentation links * :books: update release date --- .gitignore | 1 + .moban.cd/changelog.yml | 6 + .moban.d/moban_gitignore.jj2 | 1 + CHANGELOG.rst | 179 +++++++----------- docs/README.rst | 2 + docs/conf.py | 5 +- docs/index.rst | 1 + .../level-22-intermediate-targets/.moban.yaml | 3 + docs/level-22-intermediate-targets/REAME.rst | 19 ++ docs/level-22-intermediate-targets/data.yml | 1 + .../original.jj2 | 1 + moban/core/definitions.py | 13 ++ moban/core/mobanfile/__init__.py | 4 +- moban/core/mobanfile/store.py | 3 + moban/core/mobanfile/targets.py | 10 +- moban/core/mobanfile/templates.py | 41 ++-- setup.py | 2 +- tests/mobanfile/test_mobanfile.py | 3 + tests/test_definitions.py | 10 +- tests/test_docs.py | 6 + 20 files changed, 171 insertions(+), 140 deletions(-) create mode 100644 docs/level-22-intermediate-targets/.moban.yaml create mode 100644 docs/level-22-intermediate-targets/REAME.rst create mode 100644 docs/level-22-intermediate-targets/data.yml create mode 100644 docs/level-22-intermediate-targets/original.jj2 create mode 100644 moban/core/mobanfile/store.py diff --git a/.gitignore b/.gitignore index 95e2ceaf..ff3b5057 100644 --- a/.gitignore +++ b/.gitignore @@ -532,3 +532,4 @@ docs/level-19-moban-a-sub-group-in-targets/test-dir/ docs/level-19-moban-a-sub-group-in-targets/test-recursive-dir/ docs/level-6-complex-configuration/a.output docs/level-7-use-custom-jinja2-filter-test-n-global/filter.output +docs/level-8-pass-a-folder-full-of-templates/templated-folder diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index a0dd2995..31fef9d2 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: + - changes: + - action: Updated + details: + - "`#335`: support intermediate targets in moban file" + date: 13.10.2019 + version: 0.6.5 - changes: - action: Updated details: diff --git a/.moban.d/moban_gitignore.jj2 b/.moban.d/moban_gitignore.jj2 index 7f19ac2f..b7ab25e9 100644 --- a/.moban.d/moban_gitignore.jj2 +++ b/.moban.d/moban_gitignore.jj2 @@ -27,4 +27,5 @@ docs/level-19-moban-a-sub-group-in-targets/test-dir/ docs/level-19-moban-a-sub-group-in-targets/test-recursive-dir/ docs/level-6-complex-configuration/a.output docs/level-7-use-custom-jinja2-filter-test-n-global/filter.output +docs/level-8-pass-a-folder-full-of-templates/templated-folder {% endblock %} \ No newline at end of file diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 972070f8..131748f8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,11 +1,18 @@ Change log ================================================================================ +0.6.5 - 13.10.2019 +-------------------------------------------------------------------------------- + +**Updated** + +#. `#335 `_: support intermediate + targets in moban file + 0.6.4 - 4.10.2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Command options have been grouped. --template_type became --template-type #. Increment gitfs2 to version 0.0.2. `gitfs#4 @@ -14,8 +21,7 @@ Updated 0.6.3 - 25.09.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#260 `_: jinja-cli parity: support command line pipe stream. @@ -23,8 +29,7 @@ Added 0.6.2 - 15.09.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#322 `_: Implicit targets with template extensions default to copy @@ -36,8 +41,7 @@ Added 0.6.1 - 10.09.2019 -------------------------------------------------------------------------------- -Fixed -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Fixed** #. `#328 `_: update backward compatibility @@ -45,8 +49,7 @@ Fixed 0.6.0 - 10.09.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#205 `_: support `pyFilesystem2 `_ @@ -58,8 +61,7 @@ Added #. `#256 `_: jinja2-cli parity: '-d hello=world' to define custom variable on cli -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#275 `_: fix moban 0.4.5 test failures on openSUSE Tumbleweed @@ -67,8 +69,7 @@ Updated 0.5.0 - 14.07.2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#277 `_: Restored dependency git-url-parse, replacing incompatible giturlparse which was used during moban @@ -94,8 +95,7 @@ Updated 0.4.5 - 07.07.2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#271 `_: support git branch change in later run. @@ -103,8 +103,7 @@ Updated 0.4.4 - 26.05.2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#265 `_: Use simple `read binary` to read instead of encoding @@ -112,20 +111,17 @@ Updated 0.4.3 - 16.03.2019 -------------------------------------------------------------------------------- -Removed -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Removed** #. `#253 `_: symbolic link in regression pack causes python setup.py to do recursive include -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#209 `_: Alert moban user when `git` is not available and is used. -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#261 `_: since moban group template files per template type, this fill use first come first register to @@ -134,16 +130,14 @@ Updated 0.4.2 - 08.03.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#234 `_: Define template parameters on the fly inside `targets` section #. `#62 `_: select a group target to run -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#180 `_: No longer two statistics will be shown in v0.4.x. legacy copy targets are injected into a @@ -158,8 +152,7 @@ Updated 0.4.1 - 28.02.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#235 `_: user defined template types so that custom file extensions, template configurations can be @@ -171,13 +164,11 @@ Added 0.4.0 - 20.02.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#165 `_: Copy as plugins -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#219 `_: git clone depth set to 2 @@ -187,8 +178,7 @@ Updated 0.3.10 - 03.02.2019 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#174 `_: Store git cache in XDG_CACHE_DIR @@ -197,8 +187,7 @@ Added #. `#164 `_: support additional data formats -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#178 `_: UnboundLocalError: local variable 'target' referenced before assignment @@ -208,8 +197,7 @@ Updated 0.3.9 - 18-1-2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#90 `_: allow adding extra jinja2 extensions. `jinja2.ext.do`, `jinja2.ext.loopcontrols` are included by @@ -221,8 +209,7 @@ Updated 0.3.8 - 12-1-2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#141 `_: disable file permissions copy feature and not to check file permission changes on windows. @@ -235,8 +222,7 @@ Updated 0.3.7 - 6-1-2019 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#146 `_: added a low-setup usage mode via environment variables to moban @@ -247,8 +233,7 @@ Updated 0.3.6 - 30-12-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#143 `_: moban shall report permission error and continue the rest of the copying task. @@ -259,8 +244,7 @@ Updated 0.3.5 - 10-12-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#37 `_: moban will report line number where the value is empty and the name of mobanfile. Switch from pyyaml @@ -269,8 +253,7 @@ Updated 0.3.4.1 - 28-11-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#137 `_: missing contributors.rst file @@ -278,23 +261,20 @@ Updated 0.3.4 - 18-11-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. global variables to store the target and template file names in the jinja2 engine #. moban-handlebars is tested to work well with this version and above -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Template engine interface has been clarified and documented 0.3.3 - 05-11-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. alternative and expanded syntax for requires, so as to accomendate github submodule recursive @@ -302,8 +282,7 @@ Added 0.3.2 - 04-11-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. configuration dirs may be located by `requires`, i.e. configuration files may be in a python package or git repository. @@ -311,8 +290,7 @@ Added 0.3.1 - 02-11-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#97 `_: requires will clone a repo if given. Note: only github, gitlab, bitbucket for now @@ -320,21 +298,18 @@ Added 0.3.0 - 27-18-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#89 `_: Install pypi-hosted mobans through requires syntax -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#96 `_: Fix for FileNotFoundError for plugins #. various documentation updates -Removed -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Removed** #. `#88 `_: removed python 2.6 support @@ -343,8 +318,7 @@ Removed 0.2.4 - 14-07-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#32 `_: option 1 copy a directory without its subdirectories. @@ -354,8 +328,7 @@ Added 0.2.3 - 10-07-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#76 `_: running moban as a module from python command @@ -367,14 +340,12 @@ Added 0.2.2 - 16-06-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#31 `_: create directory if missing during copying -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#28 `_: if a template has been copied once before, it is skipped in the next moban call @@ -382,8 +353,7 @@ Updated 0.2.1 - 13-06-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. templates using the same template engine will be templated as a group #. update lml dependency to 0.0.3 @@ -391,8 +361,7 @@ Updated 0.2.0 - 11-06-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#18 `_: file exists test #. `#23 `_: custom jinja plugins @@ -402,8 +371,7 @@ Added #. `#58 `_: allow template type per template -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#34 `_: fix plural message if single file is processed @@ -411,8 +379,7 @@ Updated 0.1.4 - 29-May-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. `#21 `_: targets become optional @@ -424,16 +391,14 @@ Updated 0.1.3 - 12-Mar-2018 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. handle unicode on python 2 0.1.2 - 10-Jan-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#13 `_: strip off new lines in the templated file @@ -441,8 +406,7 @@ Added 0.1.1 - 08-Jan-2018 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. the ability to present a long text as multi-line paragraph with a custom upper limit @@ -453,8 +417,7 @@ Added 0.1.0 - 19-Dec-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#14 `_, provide shell exit code @@ -462,8 +425,7 @@ Added 0.0.9 - 24-Nov-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#11 `_, recognize .moban.yaml as well as .moban.yml. @@ -472,8 +434,7 @@ Added #. `-m` option is added to allow you to specify a custom moban file. kinda related to issue 11. -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. use explicit version name: `moban_file_spec_version` so that `version` can be used by users. `#10 `_ Please @@ -485,23 +446,20 @@ Updated 0.0.8 - 18-Nov-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. `#8 `_, verify the existence of custom template and configuration directories. default .moban.td, .moban.cd are ignored if they do not exist. -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Colorize error messages and processing messages. crayons become a dependency. 0.0.7 - 19-Jul-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. Bring the visibility of environment variable into jinja2 templating process: `#7 `_ @@ -509,13 +467,11 @@ Added 0.0.6 - 16-Jun-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. added '-f' flag to force moban to template all files despite of .moban.hashes -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. moban will not template target file in the situation where the changes occured in target file than in the source: the template file + the data @@ -525,8 +481,7 @@ Updated 0.0.5 - 17-Mar-2017 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. Create a default hash store when processing a moban file. It will save unnecessary file write to the disc if the rendered content is not changed. @@ -535,8 +490,7 @@ Added 0.0.4 - 11-May-2016 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Bug fix `#5 `_, should detect duplicated targets in `.moban.yml` file. @@ -544,8 +498,7 @@ Updated 0.0.3 - 09-May-2016 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Bug fix `#4 `_, keep trailing new lines @@ -553,8 +506,7 @@ Updated 0.0.2 - 27-Apr-2016 -------------------------------------------------------------------------------- -Updated -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Updated** #. Bug fix `#1 `_, failed to save utf-8 characters @@ -562,7 +514,6 @@ Updated 0.0.1 - 23-Mar-2016 -------------------------------------------------------------------------------- -Added -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**Added** #. Initial release diff --git a/docs/README.rst b/docs/README.rst index cfbe4a9f..74debb58 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -24,6 +24,7 @@ This section covers the use cases for moban. Please check them out individually. #. `Select a group target to run`_ #. `Template files in a zip or tar`_ #. `Template copying from a zip to a zip`_ +#. `Intermeidate targets`_ .. _Jinja2 command line: level-1-jinja2-cli .. _Template inheritance: level-2-template-inheritance @@ -46,3 +47,4 @@ This section covers the use cases for moban. Please check them out individually. .. _Select a group target to run: level-19-moban-a-sub-group-in-targets .. _Template files in a zip or tar: level-20-templates-configs-in-zip-or-tar .. _Template copying from a zip to a zip: level-21-copy-templates-into-an-alien-file-system +.. _Intermeidate targets: level-22-intermediate-targets diff --git a/docs/conf.py b/docs/conf.py index 8468720d..7c7630d0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -7,7 +7,7 @@ # # This file only contains a selection of the most common options. For a full # list see the documentation: -# http://www.sphinx-doc.org/en/master/config +# https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- @@ -68,8 +68,7 @@ # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} - +intersphinx_mapping = {'https://docs.python.org/3/': None} # TODO: html_theme not configurable upstream html_theme = 'default' diff --git a/docs/index.rst b/docs/index.rst index e5deaaf5..b6c3946d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,6 +36,7 @@ examples folder. level-19-moban-a-sub-group-in-targets/README.rst level-20-templates-configs-in-zip-or-tar/README.rst level-21-copy-templates-into-an-alien-file-system/README.rst + level-22-intermediate-targets/README.rst For more complex use case, please look at `its usage in pyexcel project `_ diff --git a/docs/level-22-intermediate-targets/.moban.yaml b/docs/level-22-intermediate-targets/.moban.yaml new file mode 100644 index 00000000..8493915e --- /dev/null +++ b/docs/level-22-intermediate-targets/.moban.yaml @@ -0,0 +1,3 @@ +targets: + - intermediate.jj2: original.jj2 + - final: intermediate.jj2 diff --git a/docs/level-22-intermediate-targets/REAME.rst b/docs/level-22-intermediate-targets/REAME.rst new file mode 100644 index 00000000..5a667e99 --- /dev/null +++ b/docs/level-22-intermediate-targets/REAME.rst @@ -0,0 +1,19 @@ +Level 22: intermediate targets +================================================================================ + +It is natural to allow intermediate target to be source so that different +moban plugins can interact with each other. The good news is since moban verion +0.6.5, it is support. + +.. note:: + The bad news is, folder as imtermediate target is not supported yet and will be + considered in next incremental build. For now, the date cannot be confirmed. + +Here are the syntax:: + + targets: + - intermediate.jj2: original.jj2 + - final: intermediate.jj2 + +With moban 0.6.4-, above syntax cannot result in `final` file to be generated +because `intermediate.jj2` does not exist until moban is run. diff --git a/docs/level-22-intermediate-targets/data.yml b/docs/level-22-intermediate-targets/data.yml new file mode 100644 index 00000000..bb56b055 --- /dev/null +++ b/docs/level-22-intermediate-targets/data.yml @@ -0,0 +1 @@ +hello: world diff --git a/docs/level-22-intermediate-targets/original.jj2 b/docs/level-22-intermediate-targets/original.jj2 new file mode 100644 index 00000000..8b08a03e --- /dev/null +++ b/docs/level-22-intermediate-targets/original.jj2 @@ -0,0 +1 @@ +a {{hello}} diff --git a/moban/core/definitions.py b/moban/core/definitions.py index e72f3d88..d81fd2e0 100644 --- a/moban/core/definitions.py +++ b/moban/core/definitions.py @@ -46,3 +46,16 @@ def __repr__(self): self.output, self.template_type, ) + + +class Store: + def __init__(self): + self.init() + + def add(self, target): + self.targets.append(target) + self.look_up_by_output[target.output] = target + + def init(self): + self.targets = [] + self.look_up_by_output = {} diff --git a/moban/core/mobanfile/__init__.py b/moban/core/mobanfile/__init__.py index ffb2e641..34d3f921 100644 --- a/moban/core/mobanfile/__init__.py +++ b/moban/core/mobanfile/__init__.py @@ -17,6 +17,7 @@ extract_target, extract_group_targets, ) +from .store import STORE LOG = logging.getLogger(__name__) @@ -89,7 +90,8 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options): def handle_targets(merged_options, targets): LOG.info("handling targets") - list_of_templating_parameters = parse_targets(merged_options, targets) + parse_targets(merged_options, targets) + list_of_templating_parameters = STORE.targets jobs_for_each_engine = OrderedDict() for target in list_of_templating_parameters: diff --git a/moban/core/mobanfile/store.py b/moban/core/mobanfile/store.py new file mode 100644 index 00000000..eda34174 --- /dev/null +++ b/moban/core/mobanfile/store.py @@ -0,0 +1,3 @@ +from moban.core.definitions import Store + +STORE = Store() diff --git a/moban/core/mobanfile/targets.py b/moban/core/mobanfile/targets.py index 492399fa..f0a6a2d8 100644 --- a/moban/core/mobanfile/targets.py +++ b/moban/core/mobanfile/targets.py @@ -4,7 +4,8 @@ from moban import core, constants, exceptions from moban.externals import reporter from moban.core.definitions import TemplateTarget -from moban.core.mobanfile.templates import handle_template +from .store import STORE +from .templates import handle_template LOG = logging.getLogger(__name__) @@ -47,10 +48,11 @@ def extract_group_targets(group, targets): def parse_targets(options, targets): LOG.info("paring targets..") + STORE.init() for target in targets: if constants.LABEL_OUTPUT in target: for template_target in _handle_explicit_target(options, target): - yield template_target + STORE.add(template_target) else: for output, template_file in target.items(): if isinstance(template_file, str) is False: @@ -60,12 +62,12 @@ def parse_targets(options, targets): for template_target in _handle_group_target( options, a_list_short_hand_targets, group_template_type ): - yield template_target + STORE.add(template_target) else: for template_target in _handle_implicit_target( options, template_file, output ): - yield template_target + STORE.add(template_target) def _handle_explicit_target(options, target): diff --git a/moban/core/mobanfile/templates.py b/moban/core/mobanfile/templates.py index b344ec79..5de94640 100644 --- a/moban/core/mobanfile/templates.py +++ b/moban/core/mobanfile/templates.py @@ -2,6 +2,7 @@ from moban import constants from moban.externals import reporter, file_system +from .store import STORE LOG = logging.getLogger(__name__) @@ -20,29 +21,24 @@ def handle_template(template_file, output, template_dirs): ): yield a_triple else: - reporter.report_error_message( - "{0} cannot be found".format(template_file) - ) + if STORE.look_up_by_output.get(template_file) is None: + reporter.report_error_message( + "{0} cannot be found".format(template_file) + ) else: _, fs = multi_fs.which(template_file) if fs is None: - reporter.report_error_message( - "{0} cannot be found".format(template_file) - ) + if STORE.look_up_by_output.get(template_file) is None: + reporter.report_error_message( + "{0} cannot be found".format(template_file) + ) + else: + yield _create_a_single_target(template_file, output) elif fs.isdir(template_file): for a_triple in _list_dir_files(fs, template_file, output): 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): - 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) + yield _create_a_single_target(template_file, output) def _list_dir_files(fs, source, dest): @@ -72,6 +68,19 @@ def _listing_directory_files_recusively(fs, source, dest): yield a_triple +def _create_a_single_target(template_file, output): + 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 + return (template_file, output, template_type) + + def _get_template_type(template_file): _, extension = file_system.path_splitext(template_file) if extension: diff --git a/setup.py b/setup.py index 95ba5d2d..f2d2c60f 100644 --- a/setup.py +++ b/setup.py @@ -140,7 +140,7 @@ def run(self): self.status(NO_GS_MESSAGE) if run_status: if os.system(PUBLISH_COMMAND) != 0: - self.status(UPLOAD_FAILED_MSG % PUBLISH_COMMAND) + self.status(UPLOAD_FAILED_MSG) sys.exit() diff --git a/tests/mobanfile/test_mobanfile.py b/tests/mobanfile/test_mobanfile.py index 5375ad39..905a72df 100644 --- a/tests/mobanfile/test_mobanfile.py +++ b/tests/mobanfile/test_mobanfile.py @@ -41,6 +41,9 @@ def test_handle_targets(fake_renderer): @patch("moban.core.moban_factory.MobanEngine.render_to_files") def test_handle_targets_sequence(fake_renderer): from moban.core.mobanfile import handle_targets + from moban.core.mobanfile.store import STORE + + STORE.init() # required to reset the store TEMPLATE1 = "a.template.jj2" OUTPUT1 = "filterme.handlebars" # in the future, this could dynamic output diff --git a/tests/test_definitions.py b/tests/test_definitions.py index a9a6a9d5..8992ca38 100644 --- a/tests/test_definitions.py +++ b/tests/test_definitions.py @@ -1,7 +1,7 @@ from nose.tools import eq_ from moban.deprecated import GitRequire -from moban.core.definitions import TemplateTarget +from moban.core.definitions import Store, TemplateTarget def test_git_require_repr(): @@ -43,3 +43,11 @@ def test_branch_params(): actual = require.clone_params() expected = {"single_branch": True, "branch": "ghpages", "depth": 2} eq_(expected, actual) + + +def test_store(): + store = Store() + output = "output" + target = TemplateTarget("template_file", "data_file", output) + store.add(target) + eq_(target, store.look_up_by_output.get(output)) diff --git a/tests/test_docs.py b/tests/test_docs.py index e3cc36e9..eae9e2cd 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -311,6 +311,12 @@ def test_level_19_with_group_target(self): # make sure only copy target is executed eq_(False, os.path.exists("a.output")) + def test_level_22_intermediate_targets(self): + expected = "a world\n" + + folder = "level-22-intermediate-targets" + self.run_moban(["moban"], folder, [("final", expected)]) + def test_misc_1(self): expected = "test file\n"