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
6 changes: 6 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Added
details:
- "`requires` shall support configuration dirs. In other words, configuration file could be stored in python package or git repository."
date: unreleased
version: 0.3.2
- changes:
- action: Added
details:
Expand Down
4 changes: 2 additions & 2 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ organisation: moremoban
author: C. W.
contact: wangc_2011@hotmail.com
license: MIT
version: 0.3.1
current_version: 0.3.1
version: 0.3.2
current_version: 0.3.2
release: 0.3.1
branch: master
command_line_interface: "moban"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change log
================================================================================

0.3.2 - unreleased
--------------------------------------------------------------------------------

Added
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. `requires` shall support configuration dirs. In other words, configuration
file could be stored in python package or git repository.

0.3.1 - 02-11-2018
--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# The short X.Y version
version = u'0.3.1'
# The full version, including alpha/beta/rc tags
release = u'0.3.1'
release = u'0.3.2'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ examples folder.
level-7-use-custom-jinja2-filter-test-n-global/README.rst
level-8-pass-a-folder-full-of-templates/README.rst
level-9-moban-dependency-as-pypi-package/README.rst
level-10-moban-dependency-as-git-repo/README.rst

In pratice, the following use cases were found interesting to go along with.

Expand Down
1 change: 1 addition & 0 deletions docs/level-10-moban-dependency-as-git-repo/.moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configuration:
- "pypi-mobans:templates"
- local
configuration: config.yml
configuration_dir: "pypi-mobans:config"
targets:
- mytravis.yml: travis.yml.jj2
- test.txt: demo.txt.jj2
1 change: 1 addition & 0 deletions docs/level-10-moban-dependency-as-git-repo/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
overrides: data.yml
level10: "moban dependency as git repo"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{level10}}
{{name}}: {{level10}}
1 change: 1 addition & 0 deletions docs/level-9-moban-dependency-as-pypi-package/.moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ configuration:
- "pypi-mobans-pkg:templates"
- local
configuration: config.yml
configuration_dir: "pypi-mobans-pkg:config"
targets:
- mytravis.yml: travis.yml.jj2
- test.txt: demo.txt.jj2
1 change: 1 addition & 0 deletions docs/level-9-moban-dependency-as-pypi-package/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
overrides: data.yml
level9: "moban dependency as pypi package"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{level9}}
{{name}}: {{level9}}
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.3.1"
__version__ = "0.3.2"
__author__ = "C. W."
49 changes: 30 additions & 19 deletions moban/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, template_dirs, context_dirs):
scan_plugins_regex(MOBAN_ALL, "moban", None, BUILTIN_EXENSIONS)
template_dirs = list(expand_template_directories(template_dirs))
verify_the_existence_of_directories(template_dirs)
context_dirs = expand_template_directory(context_dirs)
template_loader = FileSystemLoader(template_dirs)
self.jj2_environment = Environment(
loader=template_loader,
Expand Down Expand Up @@ -219,27 +220,37 @@ def expand_template_directories(dirs):
dirs = [dirs]

for directory in dirs:
if ":" in directory:
library_or_repo_name, relative_path = directory.split(":")
potential_repo_path = os.path.join(
utils.get_moban_home(), library_or_repo_name
)
if os.path.exists(potential_repo_path):
# expand repo template path
if relative_path:
yield os.path.join(potential_repo_path, relative_path)
else:
yield potential_repo_path
yield expand_template_directory(directory)


def expand_template_directory(directory):
translated_directory = None
if ":" in directory:
library_or_repo_name, relative_path = directory.split(":")
potential_repo_path = os.path.join(
utils.get_moban_home(), library_or_repo_name
)
if os.path.exists(potential_repo_path):
# expand repo template path
if relative_path:
translated_directory = os.path.join(
potential_repo_path, relative_path
)
else:
# expand pypi template path
library_path = LIBRARIES.resource_path_of(library_or_repo_name)
if relative_path:
yield os.path.join(library_path, relative_path)
else:
yield library_path
translated_directory = potential_repo_path
else:
# local template path
yield os.path.abspath(directory)
# expand pypi template path
library_path = LIBRARIES.resource_path_of(library_or_repo_name)
if relative_path:
translated_directory = os.path.join(
library_path, relative_path
)
else:
translated_directory = library_path
else:
# local template path
translated_directory = os.path.abspath(directory)
return translated_directory


def verify_the_existence_of_directories(dirs):
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import sys
import codecs
from shutil import rmtree
from setuptools import setup, find_packages, Command

from setuptools import Command, setup, find_packages

PY2 = sys.version_info[0] == 2
PY26 = PY2 and sys.version_info[1] < 7

NAME = 'moban'
AUTHOR = 'C. W.'
VERSION = '0.3.1'
VERSION = '0.3.2'
EMAIL = 'wangc_2011@hotmail.com'
LICENSE = 'MIT'
ENTRY_POINTS = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def test_level_8(self):
self._raw_moban(["moban"], folder, expected, "templated-folder/my")

def test_level_9(self):
expected = "moban dependency as pypi package"
expected = "pypi-mobans: moban dependency as pypi package"
folder = "level-9-moban-dependency-as-pypi-package"
self._raw_moban(["moban"], folder, expected, "test.txt")

def test_level_10(self):
expected = "moban dependency as git repo"
expected = "pypi-mobans: moban dependency as git repo"
folder = "level-10-moban-dependency-as-git-repo"
self._raw_moban(["moban"], folder, expected, "test.txt")

Expand Down