diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml new file mode 100644 index 00000000..bf2b32a1 --- /dev/null +++ b/.github/workflows/pythonpackage.yml @@ -0,0 +1,30 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.6, 3.7] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Lint with flake8 + run: | + make install_test format git-diff-check lint + - name: Test with pytest + run: | + pip install -r tests/requirements.txt + make diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index bf959001..cb507900 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,18 @@ name: moban organisation: moremoban releases: + - changes: + - action: Updated + details: + - "no verbose for error, -v for warning, -vv for warning+info, -vvv for warning+info+debug" + - "`#351`, show template plugin name, i.e. 'copying' for copy instead of 'templating'" + - action: Removed + details: + - "Message: 'Warning: Attempting to use environment vars as data...' became warning log" + - "Message: 'Warning: Both data.yml and /.../.moban.cd/data.yml does not exist' became warning log" + - "with -v, you would see them in such a situation" + date: 1.12.2019 + version: 0.6.7 - changes: - action: Added details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 069534eb..43591b40 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.6 -current_version: 0.6.6 -release: 0.6.6 +version: 0.6.7 +current_version: 0.6.7 +release: 0.6.7 branch: master master: index command_line_interface: "moban" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1d468763..612dafce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,24 @@ Change log ================================================================================ +0.6.7 - 1.12.2019 +-------------------------------------------------------------------------------- + +**Updated** + +#. no verbose for error, -v for warning, -vv for warning+info, -vvv for + warning+info+debug +#. `#351 `_, show template plugin + name, i.e. 'copying' for copy instead of 'templating' + +**Removed** + +#. Message: 'Warning: Attempting to use environment vars as data...' became + warning log +#. Message: 'Warning: Both data.yml and /.../.moban.cd/data.yml does not exist' + became warning log +#. with -v, you would see them in such a situation + 0.6.6 - 10.11.2019 -------------------------------------------------------------------------------- diff --git a/README.rst b/README.rst index da4bffaa..f4cf979c 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,6 @@ moban - 模板 Any template, any data in any location :Author: C.W. and its contributors (See contributors.rst) :Issues: http://github.com/moremoban/moban/issues :License: MIT -:Version: |version| -:Generated: |today| **moban** started with bringing the high performance template engine (JINJA2) for web @@ -82,8 +80,6 @@ Quick start $ 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 Templated 1 file. $ cat moban.output @@ -244,7 +240,7 @@ CLI documentation --exit-code tell moban to change exit code -V, --version show program's version number and exit - -v show verbose, try -v, -vv + -v show verbose, try -v, -vv, -vvv Exit codes -------------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index d7efe9e0..19387fcc 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.6' +version = '0.6.7' # The full version, including alpha/beta/rc tags -release = '0.6.6' +release = '0.6.7' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index 99a64f41..6293e594 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.6.6" +__version__ = "0.6.7" __author__ = "C. W." diff --git a/moban/constants.py b/moban/constants.py index 2f8f3f4c..530ab7f1 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -75,6 +75,8 @@ LABEL_FORCE_TEMPLATE_TYPE = "force_template_type" LABEL_TEMPLATE_TYPES = "template_types" LABEL_VERBOSE = "verbose" +LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Mobanizing" +LABEL_MOBAN_ACTION_IN_PAST_TENSE = "Mobanized" # error messages ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist" diff --git a/moban/core/context.py b/moban/core/context.py index 50d0ec4c..96e273ab 100644 --- a/moban/core/context.py +++ b/moban/core/context.py @@ -1,12 +1,15 @@ import os import copy +import logging from moban import constants, exceptions from moban.core import utils -from moban.externals import reporter from moban.program_options import OPTIONS from moban.core.data_loader import merge, load_data +LOG = logging.getLogger(__name__) +MESSAGE_USING_ENV_VARS = "Attempting to use environment vars as data..." + class Context(object): def __init__(self, context_dirs): @@ -27,7 +30,7 @@ def get_data(self, file_name): # If data file doesn't exist: # 1. Alert the user of their (potential) mistake # 2. Attempt to use environment vars as data - reporter.report_warning_message(str(exception)) - reporter.report_using_env_vars() + LOG.warn(str(exception)) + LOG.info(MESSAGE_USING_ENV_VARS) merge(custom_data, self.__cached_environ_variables) return custom_data diff --git a/moban/core/moban_factory.py b/moban/core/moban_factory.py index 101394ce..566aebed 100644 --- a/moban/core/moban_factory.py +++ b/moban/core/moban_factory.py @@ -15,7 +15,7 @@ from moban.core.hashstore import HASH_STORE from moban.externals.buffered_writer import BufferedWriter -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) PY3_ABOVE = sys.version_info[0] > 2 @@ -29,7 +29,7 @@ def register_extensions(self, extensions): for user_template_type in extensions.keys(): template_type = self.get_primary_key(user_template_type) - log.debug( + LOG.debug( "Registering extensions: {0}={1}".format( user_template_type, extensions[user_template_type] ) @@ -92,14 +92,26 @@ def __init__(self, template_fs, context_dirs, engine): self.templated_count = 0 self.file_count = 0 self.buffered_writer = BufferedWriter() + self.engine_action = getattr( + engine, + "ACTION_IN_PRESENT_CONTINUOUS_TENSE", + constants.LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE, + ) + self.engine_actioned = getattr( + engine, + "ACTION_IN_PAST_TENSE", + constants.LABEL_MOBAN_ACTION_IN_PAST_TENSE, + ) def report(self): if self.templated_count == 0: reporter.report_no_action() elif self.templated_count == self.file_count: - reporter.report_full_run(self.file_count) + reporter.report_full_run(self.engine_actioned, self.file_count) else: - reporter.report_partial_run(self.templated_count, self.file_count) + reporter.report_partial_run( + self.engine_actioned, self.templated_count, self.file_count + ) def number_of_templated_files(self): return self.templated_count @@ -119,7 +131,9 @@ def render_to_file(self, template_file, data_file, output_file): template_abs_path, template, data, output_file ) if flag: - reporter.report_templating(template_file, output_file) + reporter.report_templating( + self.engine_action, template_file, output_file + ) self.templated_count += 1 self.buffered_writer.close() @@ -133,7 +147,9 @@ def render_string_to_file( template_abs_path, template, data, output_file ) if flag: - reporter.report_templating(template_abs_path, output_file) + reporter.report_templating( + self.engine_action, template_abs_path, output_file + ) self.templated_count += 1 self.buffered_writer.close() @@ -159,7 +175,7 @@ def apply_template(self, template_abs_path, template, data, output_file): return flag except exceptions.FileNotFound: # the template is a string from command line - log.info("{} is not a file".format(template_abs_path)) + LOG.info("{} is not a file".format(template_abs_path)) self.buffered_writer.write_file_out(output_file, rendered_content) return True @@ -186,7 +202,9 @@ def _render_with_finding_template_first(self, template_file_index): template_abs_path, template, data, output ) if flag: - reporter.report_templating(template_file, output) + reporter.report_templating( + self.engine_action, template_file, output + ) self.templated_count += 1 self.file_count += 1 @@ -202,13 +220,15 @@ def _render_with_finding_data_first(self, data_file_index): template_abs_path, template, data, output ) if flag: - reporter.report_templating(template_file, output) + reporter.report_templating( + self.engine_action, template_file, output + ) self.templated_count += 1 self.file_count += 1 def expand_template_directories(dirs): - log.debug("Expanding %s..." % dirs) + LOG.debug("Expanding %s..." % dirs) if not isinstance(dirs, list): dirs = [dirs] @@ -217,7 +237,7 @@ def expand_template_directories(dirs): def expand_template_directory(directory): - log.debug("Expanding %s..." % directory) + LOG.debug("Expanding %s..." % directory) translated_directory = None if ":" in directory and directory[1] != ":" and "://" not in directory: translated_directory = deprecated_moban_path_notation(directory) diff --git a/moban/externals/reporter.py b/moban/externals/reporter.py index e7fb2eec..101f61c5 100644 --- a/moban/externals/reporter.py +++ b/moban/externals/reporter.py @@ -2,23 +2,26 @@ import moban.constants as constants -MESSAGE_TEMPLATING = "Templating {0} to {1}" +MESSAGE_TEMPLATING = "{0} {1} to {2}" MESSAGE_UP_TO_DATE = "Everything is up to date!" -MESSAGE_NO_TEMPLATING = "No templating" -MESSAGE_REPORT = "Templated {0} out of {1} files." -MESSAGE_TEMPLATED_ALL = "Templated {0} files." +MESSAGE_NO_TEMPLATING = "No actions performed" +MESSAGE_REPORT = "{0} {1} out of {2} files." +MESSAGE_TEMPLATED_ALL = "{0} {1} files." MESSAGE_PULLING_REPO = "Updating {0}..." MESSAGE_CLONING_REPO = "Cloning {0}..." -MESSAGE_USING_ENV_VARS = "Attempting to use environment vars as data..." MESSAGE_TEMPLATE_NOT_IN_MOBAN_FILE = "{0} is not defined in your moban file!" MESSAGE_FILE_EXTENSION_NOT_NEEDED = "File extension is not required for ad-hoc\ type" -def report_templating(source_file, destination_file): +def report_templating( + action_in_present_continuous_tense, source_file, destination_file +): print( MESSAGE_TEMPLATING.format( - crayons.yellow(source_file), crayons.green(destination_file) + action_in_present_continuous_tense, + crayons.yellow(source_file), + crayons.green(destination_file), ) ) @@ -27,16 +30,16 @@ def report_no_action(): print(crayons.yellow(MESSAGE_NO_TEMPLATING, bold=True)) -def report_full_run(file_count): +def report_full_run(action_in_past_tense, file_count): figure = crayons.green(str(file_count), bold=True) - message = MESSAGE_TEMPLATED_ALL.format(figure) + message = MESSAGE_TEMPLATED_ALL.format(action_in_past_tense, figure) print(_format_single(message, file_count)) -def report_partial_run(file_count, total): +def report_partial_run(action_in_past_tense, file_count, total): figure = crayons.green(str(file_count), bold=True) total_figure = crayons.yellow(str(total), bold=True) - message = MESSAGE_REPORT.format(figure, total_figure) + message = MESSAGE_REPORT.format(action_in_past_tense, figure, total_figure) print(_format_single(message, total)) @@ -74,10 +77,6 @@ def report_git_clone(repo): print(MESSAGE_CLONING_REPO.format(colored_repo)) -def report_using_env_vars(): - report_warning_message(MESSAGE_USING_ENV_VARS) - - def report_template_not_in_moban_file(template): message = MESSAGE_TEMPLATE_NOT_IN_MOBAN_FILE.format(template) report_warning_message(message) diff --git a/moban/main.py b/moban/main.py index ff498414..ed7abf5a 100644 --- a/moban/main.py +++ b/moban/main.py @@ -28,7 +28,7 @@ from io import StringIO LOG = logging.getLogger() -LOG_LEVEL = [logging.WARNING, logging.INFO, logging.DEBUG] +LOG_LEVEL = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] def main(): @@ -170,7 +170,7 @@ def create_parser(): action="count", dest=constants.LABEL_VERBOSE, default=0, - help="show verbose, try -v, -vv", + help="show verbose, try -v, -vv, -vvv", ) return parser @@ -301,7 +301,7 @@ def handle_custom_extensions(list_of_definitions): def handle_verbose(verbose_level): if verbose_level > len(LOG_LEVEL): - verbose_level = 3 + verbose_level = len(LOG_LEVEL) - 1 level = LOG_LEVEL[verbose_level] logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", diff --git a/moban/plugins/copy.py b/moban/plugins/copy.py index 455c9227..d92d1473 100644 --- a/moban/plugins/copy.py +++ b/moban/plugins/copy.py @@ -21,6 +21,9 @@ class ContentForwardEngine(object): templating mechanism. """ + ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Copying" + ACTION_IN_PAST_TENSE = "Copied" + def __init__(self, template_fs, extensions=None): self.template_fs = template_fs diff --git a/moban/plugins/jinja2/engine.py b/moban/plugins/jinja2/engine.py index 88080157..507d33e3 100644 --- a/moban/plugins/jinja2/engine.py +++ b/moban/plugins/jinja2/engine.py @@ -59,6 +59,10 @@ def __init__(self): constants.TEMPLATE_ENGINE_EXTENSION, tags=["jinja2", "jinja", "jj2", "j2"] ) class Engine(object): + + ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Templating" + ACTION_IN_PAST_TENSE = "Templated" + def __init__(self, template_fs, options=None): """ Contruct a jinja2 template engine diff --git a/setup.py b/setup.py index 9fc2d682..bff29798 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ NAME = "moban" AUTHOR = "C. W." -VERSION = "0.6.6" +VERSION = "0.6.7" 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.6.tar.gz" % URL +DOWNLOAD_URL = "%s/archive/0.6.7.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.6 " + - "Find 0.6.6 in changelog for more details") +GS_COMMAND = ("gs moban v0.6.7 " + + "Find 0.6.7 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/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 7ba46eb6..25e82f27 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -455,6 +455,22 @@ def test_debug_option(fake_config): with patch.object(sys, "argv", test_args): from moban.main import main + try: + main() + except IOError: + fake_config.assert_called_with( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + level=20, + ) + + +@patch("logging.basicConfig") +def test_debug_five_verbose_option(fake_config, *_): + fake_config.side_effect = [IOError("stop test")] + test_args = ["moban", "-vvvvv"] + with patch.object(sys, "argv", test_args): + from moban.main import main + try: main() except IOError: diff --git a/tests/test_reporter.py b/tests/test_reporter.py index 6450e9b1..ad578a4f 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -15,17 +15,17 @@ def test_partial_run(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_partial_run(1, 20) + reporter.report_partial_run("Actioned", 1, 20) patcher.stop() - eq_(fake_stdout.getvalue(), "Templated 1 out of 20 files.\n") + eq_(fake_stdout.getvalue(), "Actioned 1 out of 20 files.\n") def test_full_run(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_full_run(20) + reporter.report_full_run("Worked on", 20) patcher.stop() - eq_(fake_stdout.getvalue(), "Templated 20 files.\n") + eq_(fake_stdout.getvalue(), "Worked on 20 files.\n") def test_error_message(): @@ -55,9 +55,9 @@ def test_warning_message(): def test_report_templating(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_templating("a", "b") + reporter.report_templating("Transforming", "a", "b") patcher.stop() - eq_(fake_stdout.getvalue(), "Templating a to b\n") + eq_(fake_stdout.getvalue(), "Transforming a to b\n") def test_no_action(): @@ -65,7 +65,7 @@ def test_no_action(): fake_stdout = patcher.start() reporter.report_no_action() patcher.stop() - eq_(fake_stdout.getvalue(), "No templating\n") + eq_(fake_stdout.getvalue(), "No actions performed\n") def test_format_single():