Skip to content

Commit b2ad799

Browse files
akbakb
authored andcommitted
Rename alias to command
1 parent e0f9fd4 commit b2ad799

File tree

4 files changed

+48
-45
lines changed

4 files changed

+48
-45
lines changed

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mario>=0.0.122
1+
mario>=0.0.123
22
pyyaml
33
lxml

src/mario_addons/plugins/addons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mario import plug
55

66

7-
registry = plug.make_plugin_aliases_registry("mario_addons.plugins")
7+
registry = plug.make_plugin_commands_registry("mario_addons.plugins")
88

99

1010
def read_csv(

src/mario_addons/plugins/addons.toml

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
### Convert yaml to json
22

3-
[[alias]]
3+
[[command]]
44

55
name = "yml2json"
66
short_help = "Convert yaml to json"
77

8-
[[alias.stage]]
8+
[[command.stage]]
99
command = "stack"
1010
options = {code="yaml.safe_load ! json.dumps"}
1111

12-
[[alias.test]]
12+
[[command.test]]
1313
invocation = ["yml2json"]
1414
input = '''{"x": 1,}
1515
'''
@@ -19,22 +19,25 @@ output = '''{"x": 1}
1919

2020
### Search for xpath elements with xpath
2121

22-
[[alias]]
22+
[[command]]
2323
name="xpath"
2424
short_help = "Find xml elements matching xpath query."
2525
arguments = [{name="query", type="str"}]
2626
inject_values=["query"]
2727

28-
[[alias.stage]]
28+
29+
help = """Pull data out of xml documents using xpath."""
30+
31+
[[command.stage]]
2932

3033
command = "stack"
3134
options= {code="x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
3235

33-
[[alias.stage]]
36+
[[command.stage]]
3437
command="chain"
3538

3639

37-
[[alias.test]]
40+
[[command.test]]
3841
invocation = ["xpath", "//", "map", "x.text"]
3942
input = '''
4043
<slide type="all">
@@ -51,132 +54,132 @@ Anything in here
5154

5255
### Generate json objects
5356

54-
[[alias]]
57+
[[command]]
5558
name="jo"
5659
short_help="Make json objects"
5760
arguments=[{name="pairs", type="str"}]
5861
inject_values=["pairs"]
5962

6063

61-
[[alias.stage]]
64+
[[command.stage]]
6265
command = "eval"
6366
options = {code="pairs"}
6467

65-
[[alias.stage]]
68+
[[command.stage]]
6669
command = "map"
6770
options = {code="shlex.split(x, posix=False)"}
6871

69-
[[alias.stage]]
72+
[[command.stage]]
7073
command = "chain"
7174

72-
[[alias.stage]]
75+
[[command.stage]]
7376
command = "map"
7477
options = {code="x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\g<value>\"', x[2]))]"}
7578

76-
[[alias.stage]]
79+
[[command.stage]]
7780
command = "apply"
7881
options = {"code"="dict"}
7982

80-
[[alias.stage]]
83+
[[command.stage]]
8184
command = "map"
8285
options = {code="json.dumps"}
8386

8487

85-
[[alias.test]]
88+
[[command.test]]
8689
invocation = ["jo", "x=1 y=2"]
8790
input = ""
8891
output = "{\"x\": 1, \"y\": 2}\n"
8992

9093

91-
[[alias]]
94+
[[command]]
9295
name = "read-jsonl"
9396
short_help = "Load jsonlines into python objects"
9497
section ="Read"
9598

96-
[[alias.stage]]
99+
[[command.stage]]
97100

98101
command = "map"
99102

100103
options = {code="json.loads"}
101104

102-
[[alias.test]]
105+
[[command.test]]
103106
invocation = ["read-jsonl"]
104107
input = """{"name": "Alice", "age": "21"}\n{"name": "Bob", "age": "22"}\n"""
105108
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
106109

107110

108-
[[alias]]
111+
[[command]]
109112
name = "read-csv"
110113
short_help = "Load csv rows into python objects"
111114
inject_values=["delimiter", "header"]
112115
section ="Read"
113116

114-
[[alias.options]]
117+
[[command.options]]
115118
name = "--delimiter"
116119
default = ","
117-
help = "field delimiter character"
120+
help = "Field delimiter character"
118121

119-
[[alias.options]]
122+
[[command.options]]
120123
name = "--header/--no-header"
121124
default=true
122125
help = "Treat the first row as a header?"
123126

124-
[[alias.stage]]
127+
[[command.stage]]
125128
command = "apply"
126129
options = {code="mario_addons.plugins.addons.read_csv(x, header=header)"}
127130

128-
[[alias.stage]]
131+
[[command.stage]]
129132
command = "chain"
130133

131-
[[alias.stage]]
134+
[[command.stage]]
132135
command = "map"
133136
options = {code="dict(x)"}
134137

135-
[[alias.test]]
138+
[[command.test]]
136139
invocation = ["read-csv"]
137140
input = """name,age\nAlice,21\nBob,22\n"""
138141
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
139142

140143

141-
[[alias]]
144+
[[command]]
142145
name = "read-yaml"
143146
short_help = "Read yaml document"
144147
section = "Read"
145148

146-
[[alias.stage]]
149+
[[command.stage]]
147150
command = "stack"
148151
options = {code="yaml.safe_load"}
149152

150-
[[alias.test]]
153+
[[command.test]]
151154
invocation = ["read-yaml"]
152155
input = "{'x': 1,}\n"
153156
output = "{'x': 1}\n"
154157

155-
[[alias]]
158+
[[command]]
156159
name = 'write-json'
157160
short_help = "Write json document"
158161
section = "Write"
159162

160-
[[alias.stage]]
163+
[[command.stage]]
161164
command = "apply"
162165
options={code="json.dumps"}
163166

164-
[[alias.test]]
167+
[[command.test]]
165168
invocation = ["stack", "str.split", "write-json"]
166169
input = "1 2\n"
167170
output ="[[\"1\", \"2\"]]\n"
168171

169172

170-
[[alias]]
173+
[[command]]
171174
name = 'write-toml'
172175
short_help = "Write toml document"
173176
section = "Write"
174177

175-
[[alias.stage]]
178+
[[command.stage]]
176179
command = "map"
177180
options={code="toml.dumps"}
178181

179-
[[alias.test]]
182+
[[command.test]]
180183
invocation = ["stack", "json.loads", "write-toml"]
181184
input = '''{"x": 1}
182185
'''

tests/test_mario_addons.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import subprocess
22
import sys
33

4-
import mario.aliasing
4+
import mario.declarative
55
import pytest
66

77
import mario_addons.plugins.addons
88

99

10-
ALIASES = mario_addons.plugins.addons.registry.aliases.values()
10+
ALIASES = mario_addons.plugins.addons.registry.commands.values()
1111

12-
SPECS = [spec for alias in ALIASES for spec in alias.test_specs]
12+
SPECS = [spec for command in ALIASES for spec in command.test_specs]
1313

1414

1515
@pytest.mark.parametrize("test_spec", SPECS)
16-
def test_alias_test_spec(test_spec: mario.aliasing.AliasTestSpec):
16+
def test_command_test_spec(test_spec: mario.declarative.CommandTestSpec):
1717
"""The invocation and input generate the expected output."""
1818

1919
output = subprocess.check_output(
@@ -23,7 +23,7 @@ def test_alias_test_spec(test_spec: mario.aliasing.AliasTestSpec):
2323
assert output == test_spec.output
2424

2525

26-
@pytest.mark.parametrize("alias", ALIASES)
27-
def test_alias_has_test(alias):
28-
"""All aliases must have at least one test."""
29-
assert alias.test_specs
26+
@pytest.mark.parametrize("command", ALIASES)
27+
def test_command_has_test(command):
28+
"""All commands must have at least one test."""
29+
assert command.test_specs

0 commit comments

Comments
 (0)