Skip to content

Commit 5897970

Browse files
akbakb
authored andcommitted
Rename pipeline to code
1 parent 25815f8 commit 5897970

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

README.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Define new commands in your config file which provide aliases to other commands.
341341
[[alias.stage]]
342342
343343
command = "map"
344-
options = {pipeline="json.loads ! types.SimpleNameSpace(**x)"}
344+
options = {code="json.loads ! types.SimpleNameSpace(**x)"}
345345
346346
347347
Now we can use it like a regular command:
@@ -383,7 +383,7 @@ Convenient for removing trailing commas.
383383
[[alias.stage]]
384384
385385
command = "stack"
386-
options = {pipeline="yaml.safe_load ! json.dumps"}
386+
options = {code="yaml.safe_load ! json.dumps"}
387387
388388
Search for xpath elements with xpath
389389
+++++++++++++++++++++++++++++++++++++++++
@@ -420,7 +420,7 @@ Pull text out of xml documents.
420420
421421
[[alias.stage]]
422422
command = "stack"
423-
options= {pipeline="x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
423+
options= {code="x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
424424
425425
[[alias.stage]]
426426
command="chain"
@@ -447,26 +447,26 @@ Generate json objects
447447
448448
[[alias.stage]]
449449
command = "eval"
450-
options = {pipeline="pairs"}
450+
options = {code="pairs"}
451451
452452
[[alias.stage]]
453453
command = "map"
454-
options = {pipeline="shlex.split(x, posix=False)"}
454+
options = {code="shlex.split(x, posix=False)"}
455455
456456
[[alias.stage]]
457457
command = "chain"
458458
459459
[[alias.stage]]
460460
command = "map"
461-
options = {pipeline="x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\g<value>\"', x[2]))]"}
461+
options = {code="x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\g<value>\"', x[2]))]"}
462462
463463
[[alias.stage]]
464464
command = "apply"
465-
options = {"pipeline"="dict"}
465+
options = {"code"="dict"}
466466
467467
[[alias.stage]]
468468
command = "map"
469-
options = {pipeline="json.dumps"}
469+
options = {code="json.dumps"}
470470
471471
472472

src/mario/interpret.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,21 @@ async def _mario_runner({howsig.value}):
131131
return source
132132

133133

134-
def build_name_to_module(pipeline):
134+
def build_name_to_module(code):
135135
name_to_module = {}
136-
components = split_pipestring(pipeline)
136+
components = split_pipestring(code)
137137
module_names = {name for c in components for name in find_maybe_module_names(c)}
138138
for name in module_names:
139139
name_to_module.update(_get_autoimport_module(name))
140140

141141
return name_to_module
142142

143143

144-
def build_function(pipeline, global_namespace, howcall):
145-
name_to_module = build_name_to_module(pipeline)
144+
def build_function(code, global_namespace, howcall):
145+
name_to_module = build_name_to_module(code)
146146
global_namespace = {**name_to_module, **global_namespace}
147147

148-
source = build_source(split_pipestring(pipeline), howcall)
148+
source = build_source(split_pipestring(code), howcall)
149149
exec(source, global_namespace)
150150
function = global_namespace["_mario_runner"]
151151
return Function(function, global_namespace, source)

src/mario/plugins/basic.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def calculate_function(traversal, howcall=None):
2525
)
2626
)
2727

28-
if "pipeline" in traversal.specific_invocation_params:
28+
if "code" in traversal.specific_invocation_params:
2929

3030
return {
3131
"function": interpret.build_function(
32-
traversal.specific_invocation_params["pipeline"],
32+
traversal.specific_invocation_params["code"],
3333
global_namespace=global_namespace,
3434
howcall=howcall,
3535
)
@@ -41,7 +41,7 @@ def calculate_function(traversal, howcall=None):
4141
def calculate_reduce(traversal):
4242

4343
function = interpret.build_function(
44-
traversal.specific_invocation_params["pipeline"],
44+
traversal.specific_invocation_params["code"],
4545
traversal.global_invocation_options.global_options["global_namespace"],
4646
howcall=interpret.HowCall.VARARGS,
4747
)
@@ -146,38 +146,37 @@ async def async_chain(items, exit_stack):
146146

147147

148148
subcommands = [
149-
click.Command("map", short_help="Call <pipeline> on each line of input."),
150-
click.Command("async-map", short_help="Call <pipeline> on each line of input."),
151-
click.Command("apply", short_help="Call <pipeline> on input as a sequence."),
149+
click.Command("map", short_help="Call <code> on each line of input."),
150+
click.Command("async-map", short_help="Call <code> on each line of input."),
151+
click.Command("apply", short_help="Call <code> on input as a sequence."),
152152
click.Command(
153-
"async-apply",
154-
short_help="Call <pipeline> asynchronously on input as a sequence.",
153+
"async-apply", short_help="Call <code> asynchronously on input as a sequence."
155154
),
156155
click.Command(
157156
"filter",
158-
short_help="Call <pipeline> on each line of input and exclude false values.",
157+
short_help="Call <code> on each line of input and exclude false values.",
159158
),
160159
click.Command(
161160
"async-filter",
162-
short_help="Async call <pipeline> on each line of input and exclude false values.",
161+
short_help="Async call <code> on each line of input and exclude false values.",
163162
),
164163
click.Command(
165-
"stack", short_help="Call <pipeline> on input as a single concatenated string."
164+
"stack", short_help="Call <code> on input as a single concatenated string."
166165
),
167166
click.Command(
168167
"async-map-unordered",
169-
short_help="Call <pipeline> on each line of input, ignoring order of input items.",
168+
short_help="Call <code> on each line of input, ignoring order of input items.",
170169
),
171170
click.Command(
172171
"dropwhile",
173172
short_help="Evaluate <predicate> on function and drop values until first falsy.",
174173
),
175-
click.Command("eval", short_help="Evaluate a python expression <pipeline>"),
174+
click.Command("eval", short_help="Evaluate a python expression <code>"),
176175
]
177176

178177

179178
def build_callback(sub_command):
180-
def callback(pipeline, autocall, **parameters):
179+
def callback(code, autocall, **parameters):
181180
if autocall:
182181
howcall = interpret.HowCall.SINGLE
183182
else:
@@ -187,7 +186,7 @@ def callback(pipeline, autocall, **parameters):
187186
{
188187
"name": sub_command.name.replace("-", "_"),
189188
"howcall": howcall,
190-
"pipeline": pipeline,
189+
"code": code,
191190
"parameters": parameters,
192191
}
193192
]
@@ -203,7 +202,7 @@ def callback(pipeline, autocall, **parameters):
203202

204203
subcommand.params = [
205204
click.Option(["--autocall/--no-autocall"], is_flag=True, default=True),
206-
click.Argument(["pipeline"]),
205+
click.Argument(["code"]),
207206
]
208207
subcommand.callback = build_callback(subcommand)
209208
subcommand = option_exec_before(subcommand)
@@ -220,19 +219,19 @@ def callback(pipeline, autocall, **parameters):
220219
def _reduce(function_name, **parameters):
221220
return [
222221
{
223-
"pipeline": f"toolz.curry({function_name})",
222+
"code": f"toolz.curry({function_name})",
224223
"name": "reduce",
225224
"parameters": parameters,
226225
}
227226
]
228227

229228

230229
# @registry.add_cli(name="eval")
231-
# @click.command("eval", short_help="Call <pipeline> without any input.")
230+
# @click.command("eval", short_help="Call <code> without any input.")
232231
# @option_exec_before
233232
# @click.argument("expression")
234233
# def _eval(expression, **parameters):
235-
# return [{"pipeline": expression, "name": "eval", "parameters": parameters}]
234+
# return [{"code": expression, "name": "eval", "parameters": parameters}]
236235

237236

238237
more_commands = [

tests/data/config/jsonl_alias.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ short_help = "Load jsonlines into python objects"
66
[[alias.stage]]
77

88
command = "map"
9-
options = {pipeline="json.loads ! attr.make_class('X', list(x.keys()))(**x)"}
9+
options = {code="json.loads ! attr.make_class('X', list(x.keys()))(**x)"}

tests/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_raises_on_nonexistent_option(option, runner):
5353

5454

5555
def test_eval_main(capsys):
56-
mario.app.main([[{"name": "eval", "pipeline": "1+1", "parameters": {}}]])
56+
mario.app.main([[{"name": "eval", "code": "1+1", "parameters": {}}]])
5757
assert capsys.readouterr().out == "2\n"
5858

5959

0 commit comments

Comments
 (0)