Skip to content

Commit da8b6d1

Browse files
Rename alias to command
Rename alias to command
2 parents 1013232 + f7736df commit da8b6d1

File tree

8 files changed

+120
-122
lines changed

8 files changed

+120
-122
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.2
2+
current_version = 0.1.3
33
commit = True
44
tag = True
55

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
year = "2019"
2929
author = "Mario contributors"
3030
copyright = "{0}, {1}".format(year, author)
31-
version = release = "0.1.2"
31+
version = release = "0.1.3"
3232

3333
pygments_style = "trac"
3434
templates_path = ["."]

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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def read(*names, **kwargs):
3333
# Enable code coverage for C code: we can't use CFLAGS=-coverage in tox.ini, since that may mess with compiling
3434
setup(
3535
name="mario-addons",
36-
version="0.1.2",
36+
version="0.1.3",
3737
description="More commands for Mario.",
3838
long_description="%s\n%s"
3939
% (

src/mario_addons/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.2"
1+
__version__ = "0.1.3"

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: 106 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
### Convert yaml to json
22

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

5-
name = "yml2json"
6-
help = "Convert yaml to json"
5+
name = "yml2json"
6+
short_help = "Convert yaml to json"
77

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

12-
[[alias.test]]
13-
invocation = ["yml2json"]
14-
input = '''{"x": 1,}
12+
[[command.test]]
13+
invocation = ["yml2json"]
14+
input = '''{"x": 1,}
1515
'''
16-
output = '''{"x": 1}
16+
output = '''{"x": 1}
1717
'''
1818

1919

2020
### Search for xpath elements with xpath
2121

22-
[[alias]]
23-
name="xpath"
24-
help = "Find xml elements matching xpath query."
25-
arguments = [{name="query", type="str"}]
26-
inject_values=["query"]
22+
[[command]]
23+
name="xpath"
24+
short_help = "Find xml elements matching xpath query."
25+
arguments = [{name="query", type="str"}]
26+
inject_values=["query"]
2727

28-
[[alias.stage]]
2928

30-
command = "stack"
31-
options= {code="x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
29+
help = """Pull data out of xml documents using xpath."""
3230

33-
[[alias.stage]]
34-
command="chain"
31+
[[command.stage]]
3532

33+
command = "stack"
34+
options= {code="x.encode() ! io.BytesIO ! lxml.etree.parse ! x.findall(query) ! map(lambda y: y, x) ! list" }
3635

37-
[[alias.test]]
38-
invocation = ["xpath", "//", "map", "x.text"]
39-
input = """
40-
<slide type="all">
41-
<title>Overview</title>
42-
<item>Anything in here</item>
43-
</slide>
44-
"""
45-
output = """
36+
[[command.stage]]
37+
command="chain"
38+
39+
40+
[[command.test]]
41+
invocation = ["xpath", "//", "map", "x.text"]
42+
input = '''
43+
<slide type="all">
44+
<title>Overview</title>
45+
<item>Anything in here</item>
46+
</slide>
47+
'''
48+
output = """
4649
Overview
4750
Anything in here
4851
"""
@@ -51,137 +54,132 @@ Anything in here
5154

5255
### Generate json objects
5356

54-
[[alias]]
55-
56-
57-
name="jo"
58-
help="Make json objects"
59-
arguments=[{name="pairs", type="str"}]
60-
inject_values=["pairs"]
61-
57+
[[command]]
58+
name="jo"
59+
short_help="Make json objects"
60+
arguments=[{name="pairs", type="str"}]
61+
inject_values=["pairs"]
6262

63-
[[alias.stage]]
64-
command = "eval"
65-
options = {code="pairs"}
6663

67-
[[alias.stage]]
68-
command = "map"
69-
options = {code="shlex.split(x, posix=False)"}
64+
[[command.stage]]
65+
command = "eval"
66+
options = {code="pairs"}
7067

71-
[[alias.stage]]
72-
command = "chain"
68+
[[command.stage]]
69+
command = "map"
70+
options = {code="shlex.split(x, posix=False)"}
7371

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

78-
[[alias.stage]]
79-
command = "apply"
80-
options = {"code"="dict"}
75+
[[command.stage]]
76+
command = "map"
77+
options = {code="x.partition('=') ! [x[0], ast.literal_eval(re.sub(r'^(?P<value>[A-Za-z]+)$', r'\"\\g<value>\"', x[2]))]"}
8178

82-
[[alias.stage]]
83-
command = "map"
84-
options = {code="json.dumps"}
79+
[[command.stage]]
80+
command = "apply"
81+
options = {"code"="dict"}
8582

83+
[[command.stage]]
84+
command = "map"
85+
options = {code="json.dumps"}
8686

87-
[[alias.test]]
88-
invocation = ["jo", "x=1 y=2"]
89-
input = ""
90-
output = "{\"x\": 1, \"y\": 2}\n"
9187

88+
[[command.test]]
89+
invocation = ["jo", "x=1 y=2"]
90+
input = ""
91+
output = "{\"x\": 1, \"y\": 2}\n"
9292

93-
[[alias]]
9493

95-
name = "read-jsonl"
96-
help = "Load jsonlines into python objects"
97-
section ="Read"
94+
[[command]]
95+
name = "read-jsonl"
96+
short_help = "Load jsonlines into python objects"
97+
section ="Read"
9898

99-
[[alias.stage]]
99+
[[command.stage]]
100100

101-
command = "map"
101+
command = "map"
102102

103-
options = {code="json.loads"}
103+
options = {code="json.loads"}
104104

105-
[[alias.test]]
106-
invocation = ["read-jsonl"]
107-
input = """{"name": "Alice", "age": "21"}\n{"name": "Bob", "age": "22"}\n"""
108-
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
105+
[[command.test]]
106+
invocation = ["read-jsonl"]
107+
input = """{"name": "Alice", "age": "21"}\n{"name": "Bob", "age": "22"}\n"""
108+
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
109109

110110

111-
[[alias]]
112-
name = "read-csv"
113-
help = "Load csv rows into python objects"
114-
inject_values=["delimiter", "header"]
115-
section ="Read"
111+
[[command]]
112+
name = "read-csv"
113+
short_help = "Load csv rows into python objects"
114+
inject_values=["delimiter", "header"]
115+
section ="Read"
116116

117-
[[alias.options]]
118-
name = "--delimiter"
119-
default = ","
120-
help = "field delimiter character"
117+
[[command.options]]
118+
name = "--delimiter"
119+
default = ","
120+
help = "Field delimiter character"
121121

122-
[[alias.options]]
123-
name = "--header/--no-header"
124-
default=true
125-
help = "Treat the first row as a header?"
122+
[[command.options]]
123+
name = "--header/--no-header"
124+
default=true
125+
help = "Treat the first row as a header?"
126126

127-
[[alias.stage]]
128-
command = "apply"
129-
options = {code="mario_addons.plugins.addons.read_csv(x, header=header)"}
127+
[[command.stage]]
128+
command = "apply"
129+
options = {code="mario_addons.plugins.addons.read_csv(x, header=header)"}
130130

131-
[[alias.stage]]
132-
command = "chain"
131+
[[command.stage]]
132+
command = "chain"
133133

134-
[[alias.stage]]
135-
command = "map"
136-
options = {code="dict(x)"}
134+
[[command.stage]]
135+
command = "map"
136+
options = {code="dict(x)"}
137137

138-
[[alias.test]]
139-
invocation = ["read-csv"]
140-
input = """name,age\nAlice,21\nBob,22\n"""
141-
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
138+
[[command.test]]
139+
invocation = ["read-csv"]
140+
input = """name,age\nAlice,21\nBob,22\n"""
141+
output = """{'name': 'Alice', 'age': '21'}\n{'name': 'Bob', 'age': '22'}\n"""
142142

143143

144-
[[alias]]
144+
[[command]]
145145
name = "read-yaml"
146-
help = "Read yaml document"
146+
short_help = "Read yaml document"
147147
section = "Read"
148148

149-
[[alias.stage]]
149+
[[command.stage]]
150150
command = "stack"
151151
options = {code="yaml.safe_load"}
152152

153-
[[alias.test]]
153+
[[command.test]]
154154
invocation = ["read-yaml"]
155155
input = "{'x': 1,}\n"
156156
output = "{'x': 1}\n"
157157

158-
[[alias]]
158+
[[command]]
159159
name = 'write-json'
160-
help = "Write json document"
160+
short_help = "Write json document"
161161
section = "Write"
162162

163-
[[alias.stage]]
163+
[[command.stage]]
164164
command = "apply"
165165
options={code="json.dumps"}
166166

167-
[[alias.test]]
167+
[[command.test]]
168168
invocation = ["stack", "str.split", "write-json"]
169169
input = "1 2\n"
170170
output ="[[\"1\", \"2\"]]\n"
171171

172172

173-
174-
175-
[[alias]]
173+
[[command]]
176174
name = 'write-toml'
177-
help = "Write toml document"
175+
short_help = "Write toml document"
178176
section = "Write"
179177

180-
[[alias.stage]]
178+
[[command.stage]]
181179
command = "map"
182180
options={code="toml.dumps"}
183181

184-
[[alias.test]]
182+
[[command.test]]
185183
invocation = ["stack", "json.loads", "write-toml"]
186184
input = '''{"x": 1}
187185
'''

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)