Skip to content

Commit 9e18752

Browse files
authored
Merge pull request #382 from moremoban/dev
release 0.7.5
2 parents 53ea91a + 98bf8de commit 9e18752

File tree

24 files changed

+197
-71
lines changed

24 files changed

+197
-71
lines changed

.moban.cd/changelog.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: moban
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Added
6+
details:
7+
- "`#167`: reverse what moban have done: delete"
8+
date: 21.5.2020
9+
version: 0.7.5
410
- changes:
511
- action: Fixed
612
details:

.moban.cd/moban.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ organisation: moremoban
44
author: C. W.
55
66
license: MIT
7-
version: 0.7.4
8-
current_version: 0.7.4
9-
release: 0.7.4
7+
version: 0.7.5
8+
current_version: 0.7.5
9+
release: 0.7.5
1010
branch: master
1111
master: index
1212
command_line_interface: "moban"

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change log
22
================================================================================
33

4+
0.7.5 - 21.5.2020
5+
--------------------------------------------------------------------------------
6+
7+
**Added**
8+
9+
#. `#167 <https://github.com/moremoban/moban/issues/167>`_: reverse what moban
10+
have done: delete
11+
412
0.7.4 - 13.5.2020
513
--------------------------------------------------------------------------------
614

docs/README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ This section covers the use cases for moban. Please check them out individually.
2424
#. `Select a group target to run`_
2525
#. `Template files in a zip or tar`_
2626
#. `Template copying from a zip to a zip`_
27-
#. `Intermeidate targets`_
27+
#. `Intermediate targets`_
2828
#. `Mobanfile inheritance`_
2929
#. `Files over http(s)`_
30+
#. `Remove intermediate targets`_
3031

3132
.. _Jinja2 command line: level-1-jinja2-cli
3233
.. _Template inheritance: level-2-template-inheritance
@@ -49,6 +50,7 @@ This section covers the use cases for moban. Please check them out individually.
4950
.. _Select a group target to run: level-19-moban-a-sub-group-in-targets
5051
.. _Template files in a zip or tar: level-20-templates-configs-in-zip-or-tar
5152
.. _Template copying from a zip to a zip: level-21-copy-templates-into-an-alien-file-system
52-
.. _Intermeidate targets: level-22-intermediate-targets
53+
.. _Intermediate targets: level-22-intermediate-targets
5354
.. _Mobanfile inheritance: level-23-inherit-organisational-moban-file
5455
.. _Files over http(s): level-24-files-over-http
56+
.. _Remove intermediate targets: level-25-delete-intermediate

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
copyright = '2017-2020 Onni Software Ltd.'
2626
author = 'C. W.'
2727
# The short X.Y version
28-
version = '0.7.4'
28+
version = '0.7.5'
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.7.4'
30+
release = '0.7.5'
3131

3232
# -- General configuration ---------------------------------------------------
3333

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ examples folder.
3939
level-22-intermediate-targets/README.rst
4040
level-23-inherit-organisational-moban-file/README.rst
4141
level-24-files-over-http/README.rst
42+
level-25-delete-intermediate/README.rst
4243

4344

4445
For more complex use case, please look at `its usage in pyexcel project <http://pyexcel.readthedocs.io/en/latest/guide.html>`_
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
targets:
2+
- intermediate.jj2: original.jj2
3+
- intermediate2.jj2: original.jj2
4+
- intermediate3.jj2: original.jj2
5+
- final: intermediate.jj2
6+
- output: what_ever_here_will_be_ignored
7+
template: intermediate.jj2
8+
template_type: delete
9+
- output: ''
10+
template: intermediate2.jj2
11+
- delete!: intermediate3.jj2
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Level 25: delete intermediate targets
2+
================================================================================
3+
4+
Continue with level 22, we would like to delete intermediate files.
5+
6+
.. note::
7+
8+
What is intermediate targets? Simply they are the files moban generates
9+
but in the end those files are not really used.
10+
11+
12+
For safety reasons, we only delete intermediate targets. We are not allowing
13+
moban to delete any files in template folders and staic folder.
14+
15+
Here is the short syntax::
16+
17+
targets:
18+
- delete!: intermediate_file.jj2
19+
20+
Here are the full syntax::
21+
22+
targets:
23+
- output: what_ever_here_will_be_ignored
24+
template: intermediate.jj2
25+
template_type: delete
26+
- output: ''
27+
template: intermediate2.jj2
28+
29+
30+
Example mobanfile::
31+
32+
targets:
33+
- intermediate.jj2: original.jj2
34+
- intermediate2.jj2: original.jj2
35+
- intermediate3.jj2: original.jj2
36+
- output: x
37+
template: intermediate.jj2
38+
template_type: delete
39+
- output: ''
40+
template: intermediate2.jj2
41+
- delete!: intermediate3.jj2
42+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello: world
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a {{hello}}

moban/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.7.4"
1+
__version__ = "0.7.5"
22
__author__ = "C. W."

moban/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Template type
44
TEMPLATE_JINJA2 = "jinja2"
55
TEMPLATE_COPY = "copy"
6+
TEMPLATE_DELETE = "delete"
67

78
# Configurations
89
PROGRAM_NAME = "moban"

moban/core/definitions.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,3 @@ def __repr__(self):
4646
self.output,
4747
self.template_type,
4848
)
49-
50-
51-
class Store:
52-
def __init__(self):
53-
self.init()
54-
55-
def add(self, target):
56-
self.targets.append(target)
57-
self.look_up_by_output[target.output] = target
58-
59-
def init(self):
60-
self.targets = []
61-
self.look_up_by_output = {}

moban/core/moban_factory.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,24 @@ def _render_with_finding_data_first(self, data_file_index):
219219
data = self.context.get_data(data_file)
220220
for (template_file, output) in template_output_pairs:
221221
template = self.engine.get_template(template_file)
222-
template_abs_path = self.template_fs.geturl(
223-
template_file, purpose="fs"
224-
)
225-
flag = self.apply_template(
226-
template_abs_path, template, data, output
227-
)
228-
if flag:
229-
reporter.report_templating(
230-
self.engine_action, template_file, output
222+
if isinstance(template, bool):
223+
if template:
224+
reporter.report_templating(
225+
self.engine_action, template_file, None
226+
)
227+
self.templated_count += 1
228+
else:
229+
template_abs_path = self.template_fs.geturl(
230+
template_file, purpose="fs"
231231
)
232-
self.templated_count += 1
232+
flag = self.apply_template(
233+
template_abs_path, template, data, output
234+
)
235+
if flag:
236+
reporter.report_templating(
237+
self.engine_action, template_file, output
238+
)
239+
self.templated_count += 1
233240
self.file_count += 1
234241

235242

moban/core/mobanfile/store.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
from moban.core.definitions import Store
1+
class Store:
2+
def __init__(self):
3+
self.init()
4+
5+
def add(self, target):
6+
self.targets.append(target)
7+
self.look_up_by_output[target.output] = target
8+
9+
def init(self):
10+
self.targets = []
11+
self.look_up_by_output = {}
12+
self.intermediate_targets = []
13+
214

315
STORE = Store()

moban/core/mobanfile/targets.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ def parse_targets(options, targets):
5555
STORE.add(template_target)
5656
else:
5757
for output, template_file in target.items():
58-
if isinstance(template_file, str) is False:
58+
if isinstance(template_file, str):
59+
for template_target in _handle_implicit_target(
60+
options, template_file, output
61+
):
62+
STORE.add(template_target)
63+
else:
5964
# grouping by template type feature
6065
group_template_type = output
6166
a_list_short_hand_targets = template_file
6267
for template_target in _handle_group_target(
6368
options, a_list_short_hand_targets, group_template_type
6469
):
6570
STORE.add(template_target)
66-
else:
67-
for template_target in _handle_implicit_target(
68-
options, template_file, output
69-
):
70-
STORE.add(template_target)
7171

7272

7373
def _handle_explicit_target(options, target):
@@ -78,7 +78,10 @@ def _handle_explicit_target(options, target):
7878
)
7979
data_file = target.get(constants.LABEL_CONFIG, common_data_file)
8080
output = target[constants.LABEL_OUTPUT]
81-
template_type = target.get(constants.LABEL_TEMPLATE_TYPE)
81+
if output:
82+
template_type = target.get(constants.LABEL_TEMPLATE_TYPE)
83+
else:
84+
template_type = constants.TEMPLATE_DELETE
8285
if template_type and len(template_type) > 0:
8386
if constants.TEMPLATE_TYPES_FILE_EXTENSIONS in template_type:
8487
reporter.report_file_extension_not_needed()

moban/core/mobanfile/templates.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ def handle_template(template_file, output, template_dirs):
2020
fs, source_dir, output
2121
)
2222
else:
23-
if STORE.look_up_by_output.get(template_file) is None:
24-
reporter.report_error_message(
25-
f"{template_file} cannot be found"
26-
)
23+
reporter.report_error_message(f"{template_file} cannot be found")
2724
else:
28-
_, fs = multi_fs.which(template_file)
29-
if fs is None:
30-
if STORE.look_up_by_output.get(template_file) is None:
25+
if STORE.look_up_by_output.get(template_file) is None:
26+
_, fs = multi_fs.which(template_file)
27+
if fs is None:
3128
reporter.report_error_message(
3229
f"{template_file} cannot be found"
3330
)
31+
elif fs.isdir(template_file):
32+
yield from _list_dir_files(fs, template_file, output)
3433
else:
3534
yield _create_a_single_target(template_file, output)
36-
elif fs.isdir(template_file):
37-
yield from _list_dir_files(fs, template_file, output)
3835
else:
36+
# when template_file is not found, it means
37+
it_is_generated_by_moban = template_file
38+
STORE.intermediate_targets.append(it_is_generated_by_moban)
3939
yield _create_a_single_target(template_file, output)
4040

4141

@@ -66,7 +66,10 @@ def _listing_directory_files_recusively(fs, source, dest):
6666

6767

6868
def _create_a_single_target(template_file, output):
69-
template_type = _get_template_type(template_file)
69+
if output == constants.TEMPLATE_DELETE + "!":
70+
template_type = constants.TEMPLATE_DELETE
71+
else:
72+
template_type = _get_template_type(template_file)
7073
# output.jj2: source.jj2 means 'copy'
7174
if template_type and output.endswith("." + template_type):
7275
LOG.info(

moban/core/plugins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"moban.plugins.yaml_loader",
88
"moban.plugins.json_loader",
99
"moban.plugins.copy",
10+
"moban.plugins.delete",
1011
]
1112

1213

moban/externals/file_system.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ def wrapper(*args, **kwds):
3636
try:
3737
return function_in_this_module(*args, **kwds)
3838
except fs.errors.CreateFailed:
39-
from moban.externals import reporter
40-
4139
message = "Failed to open %s" % args[0]
4240
LOG.debug(message)
43-
reporter.report_error_message(message)
4441
raise exceptions.FileNotFound(args[0])
4542
except fs.opener.errors.UnsupportedProtocol as e:
4643
LOG.exception(e)

moban/externals/reporter.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
def report_templating(
1818
action_in_present_continuous_tense, source_file, destination_file
1919
):
20-
do_print(
21-
MESSAGE_TEMPLATING.format(
22-
action_in_present_continuous_tense,
23-
crayons.yellow(source_file),
24-
crayons.green(destination_file),
20+
if destination_file:
21+
do_print(
22+
MESSAGE_TEMPLATING.format(
23+
action_in_present_continuous_tense,
24+
crayons.yellow(source_file),
25+
crayons.green(destination_file),
26+
)
27+
)
28+
else:
29+
do_print(
30+
f"{action_in_present_continuous_tense} {crayons.yellow(source_file)}"
2531
)
26-
)
2732

2833

2934
def report_no_action():

moban/plugins/delete.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import fs
2+
from lml.plugin import PluginInfo
3+
4+
from moban import constants
5+
from moban.core.mobanfile.store import STORE
6+
7+
8+
@PluginInfo(constants.TEMPLATE_ENGINE_EXTENSION, tags=["delete"])
9+
class ContentForwardEngine(object):
10+
"""
11+
Does no templating but delete generated intermediate targets
12+
13+
"""
14+
15+
ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Deleting"
16+
ACTION_IN_PAST_TENSE = "Deleted"
17+
18+
def __init__(self, template_fs, extensions=None):
19+
self.template_fs = template_fs
20+
21+
def get_template(self, template_file):
22+
if template_file in STORE.intermediate_targets:
23+
with fs.open_fs(".") as the_fs:
24+
if the_fs.exists(template_file):
25+
the_fs.remove(template_file)
26+
return True
27+
else:
28+
return False
29+
else:
30+
raise Exception(f"Cannot remove {template_file}")
31+
32+
def get_template_from_string(self, string):
33+
raise NotImplementedError("Not sure what to do")
34+
35+
def apply_template(self, template, *_):
36+
raise NotImplementedError("Not sure what to do")

0 commit comments

Comments
 (0)