Skip to content

Commit 1ef3741

Browse files
committed
Use user input, not prefixed, for missing operations/deploys
We search ["$userinput", "$userinput.pyinfra.[operations|facts]"] and showing the second in errors is confusing.
1 parent 2c715b9 commit 1ef3741

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

pyinfra_cli/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ def try_import_module_attribute(path, prefix=None, raise_for_none=True):
180180

181181
if module is None:
182182
if raise_for_none:
183-
raise CliError(f"No such module: {possible_modules[-1]}")
183+
raise CliError(f"No such module: {possible_modules[0]}")
184184
return
185185

186186
attr = getattr(module, attr_name, None)
187187
if attr is None:
188188
if raise_for_none:
189-
raise CliError(f"No such attribute in module {possible_modules[-1]}: {attr_name}")
189+
raise CliError(f"No such attribute in module {possible_modules[0]}: {attr_name}")
190190
return
191191

192192
return attr

tests/test_cli/test_cli_exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def test_invalid_fact(self):
3838
def test_no_fact_module(self):
3939
self.assert_cli_exception(
4040
["my-server.net", "fact", "not_a_module.SomeFact"],
41-
"No such module: pyinfra.facts.not_a_module",
41+
"No such module: not_a_module",
4242
)
4343

4444
def test_no_fact_cls(self):
4545
self.assert_cli_exception(
4646
["my-server.net", "fact", "server.NotAFact"],
47-
"No such attribute in module pyinfra.facts.server: NotAFact",
47+
"No such attribute in module server: NotAFact",
4848
)
4949

5050

tests/test_cli/test_cli_util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ def test_json_encode_set(self):
3030
def test_setup_no_module(self):
3131
with self.assertRaises(CliError) as context:
3232
get_func_and_args(("no.op",))
33-
assert context.exception.message == "No such module: pyinfra.operations.no"
33+
assert context.exception.message == "No such module: no"
3434

3535
def test_setup_no_op(self):
3636
with self.assertRaises(CliError) as context:
3737
get_func_and_args(("server.no",))
3838

39-
assert (
40-
context.exception.message == "No such attribute in module pyinfra.operations.server: no"
41-
)
39+
assert context.exception.message == "No such attribute in module server: no"
4240

4341
def test_setup_op_and_args(self):
4442
commands = ("pyinfra.operations.server.user", "one", "two", "hello=world")

0 commit comments

Comments
 (0)