Skip to content

Commit

Permalink
👕 whitening the code
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Jun 8, 2018
1 parent 5cb460b commit ff0db91
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
4 changes: 3 additions & 1 deletion copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


class Copier(object):

def __init__(self, template_dirs):
self.template_dirs = template_dirs
self._count = 0
Expand All @@ -19,7 +20,8 @@ def copy_files(self, file_list):
self._count = self._count + 1
else:
reporter.report_error_message(
"{0} cannot be found".format(src))
"{0} cannot be found".format(src)
)

def number_of_copied_files(self):
return self._count
Expand Down
10 changes: 5 additions & 5 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


BUILTIN_EXENSIONS = [
'moban.filters.repr',
'moban.filters.github',
'moban.filters.text',
'moban.tests.files'
"moban.filters.repr",
"moban.filters.github",
"moban.filters.text",
"moban.tests.files",
]

_FILTERS = JinjaFilterManager()
_TESTS = JinjaTestManager()
_GLOBALS = JinjaGlobalsManager()
scan_plugins('moban_', 'moban', None, BUILTIN_EXENSIONS)
scan_plugins("moban_", "moban", None, BUILTIN_EXENSIONS)


class EngineFactory(object):
Expand Down
26 changes: 15 additions & 11 deletions extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,33 @@ def get_all(self):


class JinjaFilterManager(PluginManager, PluginMixin):

def __init__(self):
super(JinjaFilterManager, self).__init__(
constants.JINJA_FILTER_EXTENSION
)
)


class JinjaFilter(PluginInfo):

def __init__(self, filter_name):
super(JinjaFilter, self).__init__(constants.JINJA_FILTER_EXTENSION,
tags=[filter_name])
super(JinjaFilter, self).__init__(
constants.JINJA_FILTER_EXTENSION, tags=[filter_name]
)


class JinjaTestManager(PluginManager, PluginMixin):

def __init__(self):
super(JinjaTestManager, self).__init__(
constants.JINJA_TEST_EXTENSION
)
super(JinjaTestManager, self).__init__(constants.JINJA_TEST_EXTENSION)


class JinjaTest(PluginInfo):

def __init__(self, test_name):
super(JinjaTest, self).__init__(
constants.JINJA_TEST_EXTENSION,
tags=[test_name])
constants.JINJA_TEST_EXTENSION, tags=[test_name]
)


def jinja_tests(**keywords):
Expand All @@ -44,20 +47,21 @@ def jinja_tests(**keywords):


class JinjaGlobalsManager(PluginManager, PluginMixin):

def __init__(self):
super(JinjaGlobalsManager, self).__init__(
constants.JINJA_GLOBALS_EXTENSION
)
)


class PluginHelper(object):

def __init__(self, identifier, payload_obj):
self.payload = payload_obj
self.__name__ = identifier


def jinja_global(identifier, dict_obj):
plugin = PluginInfo(constants.JINJA_GLOBALS_EXTENSION,
tags=[identifier])
plugin = PluginInfo(constants.JINJA_GLOBALS_EXTENSION, tags=[identifier])
helper = PluginHelper(identifier, dict_obj)
plugin(helper)
2 changes: 1 addition & 1 deletion filters/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ISSUES = "issues"


@JinjaFilter('github_expand')
@JinjaFilter("github_expand")
def github_expand(line, name, organisation):
result = re.match(ISSUE, line)
if result:
Expand Down
2 changes: 1 addition & 1 deletion filters/repr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from moban.extensions import JinjaFilter


@JinjaFilter('repr')
@JinjaFilter("repr")
def repr_function(string):
if isinstance(string, list):
return ["'{0}'".format(str(element)) for element in string]
Expand Down
2 changes: 1 addition & 1 deletion filters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from moban.extensions import JinjaFilter


@JinjaFilter('split_length')
@JinjaFilter("split_length")
def split_length(input_line, length):
start = 0
limit = length
Expand Down
6 changes: 4 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ def handle_moban_file(moban_file, options):
raise exceptions.MobanfileGrammarException(
constants.ERROR_INVALID_MOBAN_FILE % moban_file
)
if (constants.LABEL_TARGETS not in moban_file_configurations and
constants.LABEL_COPY not in moban_file_configurations):
if (
constants.LABEL_TARGETS not in moban_file_configurations
and constants.LABEL_COPY not in moban_file_configurations
):
raise exceptions.MobanfileGrammarException(
constants.ERROR_NO_TARGETS % moban_file
)
Expand Down
16 changes: 6 additions & 10 deletions mobanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def handle_copy(template_dirs, copy_config):


def handle_targets(merged_options, targets):
list_of_templating_parameters = parse_targets(
merged_options, targets,
)
list_of_templating_parameters = parse_targets(merged_options, targets)
engine_class = EngineFactory.get_engine(
merged_options[constants.LABEL_TEMPLATE_TYPE]
)
Expand All @@ -48,13 +46,11 @@ def handle_plugin_dirs(plugin_dirs):
plugin_path = os.path.dirname(os.path.abspath(plugin_dir))
if plugin_path not in sys.path:
sys.path.append(plugin_path)
pysearchre = re.compile('.py$', re.IGNORECASE)
pluginfiles = filter(pysearchre.search,
os.listdir(plugin_dir))
plugins = list(map(lambda fp: os.path.splitext(fp)[0],
pluginfiles))
pysearchre = re.compile(".py$", re.IGNORECASE)
pluginfiles = filter(pysearchre.search, os.listdir(plugin_dir))
plugins = list(map(lambda fp: os.path.splitext(fp)[0], pluginfiles))
for plugin in plugins:
plugin_module = os.path.basename(plugin_dir) + '.' + plugin
plugin_module = os.path.basename(plugin_dir) + "." + plugin
do_import(plugin_module)


Expand All @@ -79,7 +75,7 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options):
if constants.LABEL_COPY in moban_file_configurations:
number_of_copied_files = handle_copy(
merged_options[constants.LABEL_TMPL_DIRS],
moban_file_configurations[constants.LABEL_COPY]
moban_file_configurations[constants.LABEL_COPY],
)
else:
number_of_copied_files = 0
Expand Down
3 changes: 1 addition & 2 deletions tests/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
link=islink,
exists=exists,
link_exists=lexists,

# path testing
is_abs=isabs,
abs=isabs,
is_same_file=samefile,
same_file=samefile,
is_mount=ismount,
mount=ismount
mount=ismount,
)

0 comments on commit ff0db91

Please sign in to comment.