Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 3 additions & 3 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/moremoban/moban/issues/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
--------------------------------------------------------------------------------

Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
--------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion moban/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.6.6"
__version__ = "0.6.7"
__author__ = "C. W."
2 changes: 2 additions & 0 deletions moban/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions moban/core/context.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
42 changes: 31 additions & 11 deletions moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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]
)
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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]

Expand All @@ -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)
Expand Down
29 changes: 14 additions & 15 deletions moban/externals/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
)

Expand All @@ -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))


Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions moban/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions moban/plugins/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions moban/plugins/jinja2/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading