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
4 changes: 2 additions & 2 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
line_length=79
# Ignore generated files
skip=setup.py, moban/__init__.py
known_first_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, nose
known_third_party=fs, lml, crayons, jinja2, ruamel.yaml, mock, nose
indent=' '
multi_line_output=3
length_sort=1
include_trailing_comma=true
default_section=FIRSTPARTY
no_lines_before=LOCALFOLDER
sections=FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,LOCALFOLDER
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import csv

from moban import constants
from lml.plugin import PluginInfo

from moban import constants


@PluginInfo(constants.DATA_LOADER_EXTENSION, tags=["custom"])
def open_custom(file_name):
Expand Down
3 changes: 2 additions & 1 deletion moban/core/data_loader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from collections import OrderedDict

from moban import constants
from lml.plugin import PluginManager

from moban import constants
from moban.externals import file_system


Expand Down
3 changes: 2 additions & 1 deletion moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import logging
from collections import defaultdict

from moban import constants, exceptions
from fs.errors import ResourceNotFound
from lml.plugin import PluginManager

from moban import constants, exceptions
from moban.core import utils
from moban.externals import reporter, file_system
from moban.deprecated import deprecated_moban_path_notation
Expand Down
3 changes: 2 additions & 1 deletion moban/core/mobanfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import logging
from collections import OrderedDict

from moban import core, constants
from lml.utils import do_import

from moban import core, constants
from moban.externals import reporter
from moban.core.utils import verify_the_existence_of_directories
from moban.deprecated import handle_copy, handle_requires
Expand Down
3 changes: 2 additions & 1 deletion moban/core/plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from moban import constants
from lml.loader import scan_plugins_regex

from moban import constants

BUILTIN_EXENSIONS = [
"moban.plugins.jinja2.engine",
"moban.plugins.yaml_loader",
Expand Down
12 changes: 0 additions & 12 deletions moban/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import errno
import logging

from moban import constants, exceptions
Expand All @@ -8,16 +6,6 @@
LOG = logging.getLogger(__name__)


def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise


def verify_the_existence_of_directories(dirs):
LOG.debug("Verifying the existence: %s", dirs)
if not isinstance(dirs, list):
Expand Down
3 changes: 2 additions & 1 deletion moban/deprecated/library.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from moban import constants
from lml.plugin import PluginManager

from moban import constants


class LibraryManager(PluginManager):
def __init__(self):
Expand Down
3 changes: 1 addition & 2 deletions moban/deprecated/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from moban import constants, exceptions
from moban.externals import reporter, file_system
from moban.core.utils import mkdir_p


def git_clone(requires):
Expand All @@ -16,7 +15,7 @@ def git_clone(requires):
make_sure_git_is_available()

moban_home = get_moban_home()
mkdir_p(moban_home)
file_system.mkdir_p(moban_home)

for require in requires:
repo_name = get_repo_name(require.git_url)
Expand Down
4 changes: 2 additions & 2 deletions moban/externals/buffered_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import fs
import fs.path
from moban.core import utils

from moban.externals import file_system

PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -44,6 +44,6 @@ def write_file_out(filename, content):
if not file_system.is_zip_alike_url(filename):
dest_folder = os.path.dirname(filename)
if dest_folder:
utils.mkdir_p(dest_folder)
file_system.mkdir_p(dest_folder)

file_system.write_bytes(filename, content)
14 changes: 13 additions & 1 deletion moban/externals/file_system.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
import sys
import stat
import errno
import logging
from contextlib import contextmanager

import fs
import fs.path
from moban import exceptions
from fs.multifs import MultiFS

from moban import exceptions

try:
from urllib.parse import urlparse
except ImportError:
Expand Down Expand Up @@ -260,3 +262,13 @@ def get_multi_fs(directories):
for directory in directories:
filesystem.add_fs(directory, fs.open_fs(directory))
return filesystem


def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
1 change: 1 addition & 0 deletions moban/externals/reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import crayons

import moban.constants as constants

MESSAGE_TEMPLATING = "Templating {0} to {1}"
Expand Down
22 changes: 10 additions & 12 deletions moban/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import logging.config
from collections import defaultdict

from moban import core, constants, exceptions
from moban.core import mobanfile
from moban import constants, exceptions
from moban.core import ENGINES, plugins, hashstore, mobanfile, data_loader
from moban._version import __version__
from moban.externals import reporter, file_system
from moban.core.hashstore import HASH_STORE
from moban.program_options import OPTIONS
from moban.core.data_loader import merge, load_data

LOG = logging.getLogger()
LOG_LEVEL = [logging.WARNING, logging.INFO, logging.DEBUG]
Expand All @@ -34,7 +32,7 @@ def main():
options = vars(parser.parse_args())
handle_verbose(options[constants.LABEL_VERBOSE])
load_engine_factory_and_engines() # Error: jinja2 if removed
HASH_STORE.IGNORE_CACHE_FILE = options[constants.LABEL_FORCE]
hashstore.HASH_STORE.IGNORE_CACHE_FILE = options[constants.LABEL_FORCE]
options[constants.CLI_DICT] = handle_custom_variables(
options.pop(constants.LABEL_DEFINE)
)
Expand Down Expand Up @@ -174,7 +172,7 @@ def handle_moban_file(moban_file, options):
"""
act upon default moban file
"""
moban_file_configurations = load_data(None, moban_file)
moban_file_configurations = data_loader.load_data(None, moban_file)
if moban_file_configurations is None:
raise exceptions.MobanfileGrammarException(
constants.ERROR_INVALID_MOBAN_FILE % moban_file
Expand All @@ -196,7 +194,7 @@ def handle_moban_file(moban_file, options):
raise exceptions.MobanfileGrammarException(
constants.MESSAGE_FILE_VERSION_NOT_SUPPORTED % version
)
HASH_STORE.save_hashes()
hashstore.HASH_STORE.save_hashes()


def check_none(data, moban_file):
Expand Down Expand Up @@ -225,8 +223,8 @@ def handle_command_line(options):
"""
act upon command options
"""
options = merge(options, constants.DEFAULT_OPTIONS)
engine = core.ENGINES.get_engine(
options = data_loader.merge(options, constants.DEFAULT_OPTIONS)
engine = ENGINES.get_engine(
options[constants.LABEL_TEMPLATE_TYPE],
options[constants.LABEL_TMPL_DIRS],
options[constants.LABEL_CONFIG_DIR],
Expand All @@ -251,7 +249,7 @@ def handle_command_line(options):
options[constants.LABEL_OUTPUT],
)
engine.report()
HASH_STORE.save_hashes()
hashstore.HASH_STORE.save_hashes()
exit_code = reporter.convert_to_shell_exit_code(
engine.number_of_templated_files()
)
Expand All @@ -268,7 +266,7 @@ def find_default_moban_file():


def load_engine_factory_and_engines():
core.plugins.make_sure_all_pkg_are_loaded()
plugins.make_sure_all_pkg_are_loaded()


def handle_custom_variables(list_of_definitions):
Expand All @@ -287,7 +285,7 @@ def handle_custom_extensions(list_of_definitions):
for definition in list_of_definitions:
key, value = definition.split("=")
user_extensions[key].add(value)
core.ENGINES.register_extensions(user_extensions)
ENGINES.register_extensions(user_extensions)


def handle_verbose(verbose_level):
Expand Down
3 changes: 2 additions & 1 deletion moban/plugins/copy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from moban import constants
from lml.plugin import PluginInfo

from moban import constants
from moban.externals import file_system


Expand Down
6 changes: 3 additions & 3 deletions moban/plugins/jinja2/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from importlib import import_module

import fs.errors
from moban import constants
from jinja2 import Template, Environment
from lml.loader import scan_plugins_regex
from lml.plugin import PluginInfo, PluginManager
from moban.externals import file_system
from jinja2_fsloader import FSLoader
from jinja2.exceptions import TemplateNotFound

from jinja2_fsloader import FSLoader
from moban import constants
from moban.externals import file_system

JINJA2_LIBRARIES = "^moban_jinja2_.+$"
JINJA2_EXTENSIONS = [
Expand Down
3 changes: 2 additions & 1 deletion moban/plugins/jinja2/extensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from moban import constants
from lml.plugin import PluginInfo

from moban import constants


class JinjaFilter(PluginInfo):
def __init__(self):
Expand Down
3 changes: 2 additions & 1 deletion moban/plugins/json_loader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json

from moban import constants
from lml.plugin import PluginInfo

from moban import constants
from moban.externals.file_system import open_file


Expand Down
3 changes: 2 additions & 1 deletion moban/plugins/yaml_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from moban import constants
from lml.plugin import PluginInfo
from ruamel.yaml import YAML

from moban import constants
from moban.externals.file_system import open_file


Expand Down
1 change: 1 addition & 0 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fs.path
from nose.tools import eq_

from moban.core.context import Context


Expand Down
3 changes: 2 additions & 1 deletion tests/core/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import fs.path
from mock import patch
from moban.core import ENGINES
from nose.tools import eq_

from moban.core import ENGINES
from moban.definitions import TemplateTarget
from moban.jinja2.engine import Engine
from moban.data_loaders.yaml import open_yaml
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import sys

import fs.path
import moban.exceptions as exceptions
from mock import patch
from lml.plugin import PluginInfo
from moban.core import ENGINES
from nose.tools import eq_, raises

import moban.exceptions as exceptions
from moban.core import ENGINES
from moban.core.context import Context
from moban.jinja2.engine import (
Engine,
Expand Down
1 change: 1 addition & 0 deletions tests/data_loaders/test_json_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs.path
from nose.tools import eq_

from moban.data_loaders.json_loader import open_json


Expand Down
1 change: 1 addition & 0 deletions tests/data_loaders/test_overrides.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from nose.tools import eq_

from moban.data_loaders.manager import load_data


Expand Down
1 change: 1 addition & 0 deletions tests/data_loaders/test_yaml_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs.path
from nose.tools import eq_, raises

from moban.data_loaders.yaml import open_yaml
from moban.data_loaders.manager import load_data

Expand Down
1 change: 1 addition & 0 deletions tests/deprecated/test_handle_requires.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from mock import patch
from nose.tools import eq_

from moban.deprecated import GitRequire


Expand Down
1 change: 1 addition & 0 deletions tests/deprecated/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs.path
from mock import patch
from nose.tools import eq_, raises

from moban.deprecated import GitRequire
from moban.exceptions import NoGitCommand
from moban.deprecated.repo import (
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from mock import MagicMock, patch
from nose import SkipTest
from nose.tools import eq_, raises, assert_raises

from moban.core.definitions import TemplateTarget

try:
Expand Down
3 changes: 2 additions & 1 deletion tests/jinja2/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

from moban import file_system
from nose.tools import eq_

from moban import file_system
from moban.jinja2.engine import Engine


Expand Down
Loading