Skip to content

Commit

Permalink
Merge pull request #362 from moremoban/dev
Browse files Browse the repository at this point in the history
Release 0.7.0
  • Loading branch information
chfw authored Jan 18, 2020
2 parents a823a37 + 3f36a29 commit 24ecad3
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 126 deletions.
10 changes: 10 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Removed
details:
- "`#360`: make gitfs2 and pypifs optional."
- "`#303`: python 2.7 support is dropped."
- action: Updated
details:
- "`#360`: show friendlier error when unknown protocol exception was raised."
date: 18.01.2020
version: 0.7.0
- changes:
- action: Updated
details:
Expand Down
11 changes: 5 additions & 6 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.8
current_version: 0.6.8
release: 0.6.8
version: 0.7.0
current_version: 0.7.0
release: 0.7.0
branch: master
master: index
command_line_interface: "moban"
Expand All @@ -27,12 +27,11 @@ dependencies:
- appdirs>=1.4.3
- crayons>= 0.1.0
- fs>=2.4.11
- gitfs2>=0.0.2
- pypifs>=0.0.1
- jinja2-fsloader>=0.2.0
description: Yet another jinja2 cli command for static text generation
description: General purpose static text generator
scm_host: github.com
lint_command: make install_test format git-diff-check lint
moban_command: make update git-diff-check
setup_use_markers: true
setup_use_markers_fix: true
python_requires: ">=3.6"
3 changes: 0 additions & 3 deletions .moban.d/moban_travis.yml.jj2
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ env:

{%block custom_python_versions%}
python:
- &pypy2 pypy2.7-6.0
- 3.7
- 3.6
- 3.5
- 2.7
- 3.8
{%endblock%}
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ language: python
notifications:
email: false
python:
- &pypy2 pypy2.7-6.0
- 3.7
- 3.6
- 3.5
- 2.7
- 3.8
env:
- MINREQ=0
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Change log
================================================================================

0.7.0 - 18.01.2020
--------------------------------------------------------------------------------

**Removed**

#. `#360 <https://github.com/moremoban/moban/issues/360>`_: make gitfs2 and
pypifs optional.
#. `#303 <https://github.com/moremoban/moban/issues/303>`_: python 2.7 support
is dropped.

**Updated**

#. `#360 <https://github.com/moremoban/moban/issues/360>`_: show friendlier
error when unknown protocol exception was raised.

0.6.8 - 7.12.2019
--------------------------------------------------------------------------------

Expand Down
29 changes: 26 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
================================================================================
moban - 模板 Any template, any data in any location
mó bǎn - 模板 General purpose static text generator
================================================================================

.. image:: https://api.travis-ci.org/moremoban/moban.svg?branch=master
Expand Down Expand Up @@ -28,6 +28,17 @@ moban - 模板 Any template, any data in any location
:License: MIT


Announcement
================================================================================

For existing moban users, python 2 support has been dropped. Please stay with
versions lower than 0.7.0 if you are still using python 2.

From 2020 onwards, minimum requirement is Python 3.6

Introduction
================================================================================

**moban** started with bringing the high performance template engine (JINJA2) for web
into static text generation. It has been used in `pyexcel` and `coala` project to keep
documentation consistent across the documentations of individual libraries in the same
Expand All @@ -38,6 +49,11 @@ haml, slim and tornado, can read other data format: json and yaml, and can acces
template file and configuration file in
any location: zip, git, pypi package, s3, etc.

Vision
================================================================================

Any template, any data in any location

Support
================================================================================

Expand All @@ -49,6 +65,11 @@ the project and develop it further.
With your financial support, I will be able to invest
a little bit more time in coding, documentation and writing interesting extensions.

Credit
================================================================================

`jinja2-fsloader` is the key component to enable PyFilesystem2 support in moban
v0.6x. Please show your stars there too!

Installation
================================================================================
Expand Down Expand Up @@ -129,7 +150,8 @@ All use cases are documented `here <http://moban.readthedocs.org/en/latest/#tuto
Work with files in a git repo
================================================================================

`gitfs2 <https://github.com/moremoban/gitfs2>`_ is installed by default since v0.6.1
`gitfs2 <https://github.com/moremoban/gitfs2>`_ is optional since v0.7.0 but was
installed by default since v0.6.1


You can do the following with moban:
Expand All @@ -150,7 +172,8 @@ You can do the following with moban:
Work with files in a python package
================================================================================

`pypifs <https://github.com/moremoban/pypifs>`_ is installed by default since v0.6.1
`pypifs <https://github.com/moremoban/pypifs>`_ is optional since v0.7.0 but
was installed by default since v0.6.1

You can do the following with moban:

Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
DESCRIPTION = (
'Yet another jinja2 cli command for static text generation' +
'General purpose static text generator' +
''
)
# Configuration file for the Sphinx documentation builder.
Expand All @@ -25,9 +25,9 @@
copyright = '2017-2019 Onni Software Ltd.'
author = 'C. W.'
# The short X.Y version
version = '0.6.8'
version = '0.7.0'
# The full version, including alpha/beta/rc tags
release = '0.6.8'
release = '0.7.0'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 0 additions & 2 deletions min_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ lml==0.0.9
appdirs==1.4.3
crayons== 0.1.0
fs==2.4.11
gitfs2==0.0.2
pypifs==0.0.1
jinja2-fsloader==0.2.0
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.8"
__version__ = "0.7.0"
__author__ = "C. W."
12 changes: 2 additions & 10 deletions moban/core/hashstore.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import sys
import json
import hashlib

from moban import constants
from moban.externals import file_system

PY2 = sys.version_info[0] == 2


class HashStore:
IGNORE_CACHE_FILE = False

def __init__(self):
self.cache_file = file_system.to_unicode(
constants.DEFAULT_MOBAN_CACHE_FILE
)
self.cache_file = constants.DEFAULT_MOBAN_CACHE_FILE
if (
file_system.exists(self.cache_file)
and self.IGNORE_CACHE_FILE is False
Expand Down Expand Up @@ -68,13 +63,10 @@ def get_file_hash(afile):

def get_hash(content):
md5 = hashlib.md5()
if PY2 and content.__class__.__name__ == "unicode":
content = content.encode("utf-8")
md5.update(content)
return md5.digest().decode("latin1")


def _mix(content, file_permissions_copy):
if not PY2:
file_permissions_copy = file_permissions_copy.encode("utf-8")
file_permissions_copy = file_permissions_copy.encode("utf-8")
return content + file_permissions_copy
13 changes: 6 additions & 7 deletions moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def number_of_templated_files(self):
return self.templated_count

def render_to_file(self, template_file, data_file, output_file):
template_file = file_system.to_unicode(template_file)
data = self.context.get_data(data_file)
template = self.engine.get_template(template_file)
try:
Expand All @@ -143,7 +142,7 @@ def render_string_to_file(
self, template_in_string, data_file, output_file
):
template = self.engine.get_template_from_string(template_in_string)
template_abs_path = template_in_string[:10] + "..."
template_abs_path = f"{template_in_string[:10]}..."
data = self.context.get_data(data_file)
flag = self.apply_template(
template_abs_path, template, data, output_file
Expand Down Expand Up @@ -178,7 +177,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(f"{template_abs_path} is not a file")
self.buffered_writer.write_file_out(output_file, rendered_content)
return True

Expand All @@ -197,7 +196,7 @@ def _render_with_finding_template_first(self, template_file_index):
for (template_file, data_output_pairs) in template_file_index.items():
template = self.engine.get_template(template_file)
template_abs_path = self.template_fs.geturl(
file_system.to_unicode(template_file), purpose="fs"
template_file, purpose="fs"
)
for (data_file, output) in data_output_pairs:
data = self.context.get_data(data_file)
Expand All @@ -217,7 +216,7 @@ def _render_with_finding_data_first(self, data_file_index):
for (template_file, output) in template_output_pairs:
template = self.engine.get_template(template_file)
template_abs_path = self.template_fs.geturl(
file_system.to_unicode(template_file), purpose="fs"
template_file, purpose="fs"
)
flag = self.apply_template(
template_abs_path, template, data, output
Expand All @@ -231,7 +230,7 @@ def _render_with_finding_data_first(self, data_file_index):


def expand_template_directories(dirs):
LOG.debug("Expanding %s..." % dirs)
LOG.debug(f"Expanding {dirs}...")
if not isinstance(dirs, list):
dirs = [dirs]

Expand All @@ -240,7 +239,7 @@ def expand_template_directories(dirs):


def expand_template_directory(directory):
LOG.debug("Expanding %s..." % directory)
LOG.debug(f"Expanding {directory}...")
translated_directory = None
if ":" in directory and directory[1] != ":" and "://" not in directory:
translated_directory = deprecated_moban_path_notation(directory)
Expand Down
4 changes: 2 additions & 2 deletions moban/core/mobanfile/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def extract_target(options):
if template:
if output is None:
raise Exception(
"Please specify a output file name for %s." % template
f"Please specify a output file name for {template}"
)
if config:
result = {
Expand All @@ -43,7 +43,7 @@ def extract_group_targets(group, targets):
if isinstance(group_targets, str) is False and group_name == group:
# grouping by template type feature
return [{group_name: group_targets}]
raise exceptions.GroupTargetNotFound("%s is not found" % group)
raise exceptions.GroupTargetNotFound(f"{group} is not found")


def parse_targets(options, targets):
Expand Down
34 changes: 15 additions & 19 deletions moban/core/mobanfile/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@


def handle_template(template_file, output, template_dirs):
LOG.info("handling %s" % template_file)
LOG.info(f"handling {template_file}")

template_file = file_system.to_unicode(template_file)
template_file = template_file
multi_fs = file_system.get_multi_fs(template_dirs)
if template_file.endswith("**"):
source_dir = template_file[:-3]
_, fs = multi_fs.which(source_dir)
if fs:
for a_triple in _listing_directory_files_recusively(
yield from _listing_directory_files_recusively(
fs, source_dir, output
):
yield a_triple
)
else:
if STORE.look_up_by_output.get(template_file) is None:
reporter.report_error_message(
"{0} cannot be found".format(template_file)
f"{template_file} cannot be found"
)
else:
_, fs = multi_fs.which(template_file)
if fs is None:
if STORE.look_up_by_output.get(template_file) is None:
reporter.report_error_message(
"{0} cannot be found".format(template_file)
f"{template_file} cannot be found"
)
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
yield from _list_dir_files(fs, template_file, output)
else:
yield _create_a_single_target(template_file, output)

Expand All @@ -47,35 +45,33 @@ def _list_dir_files(fs, source, dest):
# hence the following statement looks like cross platform
# src_file_under_dir = os.path.join(source, file_name)
# but actually it breaks windows instead.
src_file_under_dir = "%s/%s" % (source, file_name)
src_file_under_dir = f"{source}/{file_name}"
if fs.isfile(src_file_under_dir):
dest_file_under_dir = dest + "/" + file_name
dest_file_under_dir = f"{dest}/{file_name}"
template_type = _get_template_type(src_file_under_dir)
yield (src_file_under_dir, dest_file_under_dir, template_type)


def _listing_directory_files_recusively(fs, source, dest):
for file_name in fs.listdir(source):
src_file_under_dir = source + "/" + file_name
dest_file_under_dir = dest + "/" + file_name
src_file_under_dir = f"{source}/{file_name}"
dest_file_under_dir = f"{dest}/{file_name}"
if fs.isfile(src_file_under_dir):
template_type = _get_template_type(src_file_under_dir)
yield (src_file_under_dir, dest_file_under_dir, template_type)
elif fs.isdir(src_file_under_dir):
for a_triple in _listing_directory_files_recusively(
yield from _listing_directory_files_recusively(
fs, src_file_under_dir, dest_file_under_dir
):
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
)
f"template type switched to from {template_type} to "
+ constants.TEMPLATE_COPY
)
template_type = constants.TEMPLATE_COPY
return (template_file, output, template_type)
Expand Down
Loading

0 comments on commit 24ecad3

Please sign in to comment.