Skip to content

Commit

Permalink
Merge pull request #321 from klauer/mnt_template_backcompat
Browse files Browse the repository at this point in the history
MNT: back-compat for 'pytmc template' delimiter-less filename
  • Loading branch information
klauer authored Jul 31, 2023
2 parents e8e3874 + 668b6a9 commit 288f0f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pytmc/bin/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,15 @@ def split_input_output(arg: str) -> tuple[str, str]:
input_filename : str
The input filename.
output_filename : str
The output filename.
The output filename. Empty filename implies stdout.
"""
delim = ":"

num_delim = arg.count(delim)
if num_delim == 0:
raise ValueError(
f"Invalid input: {arg!r} should be in the format "
f"'input_filename:output_filename'"
)
# Without a delimiter, assume the file is the template filename
# and the user wants to write to standard output
return arg, ""

if num_delim == 1:
# Our job is easy in this scenario
Expand Down
9 changes: 7 additions & 2 deletions pytmc/tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ def test_template_smoke(project_filename, template):
"argument, input_filename, output_filename",
[
pytest.param(
"a", "", "", marks=pytest.mark.xfail(strict=True, reason="no delimiter")
"a", "a", "",
id="template-file-to-stdout"
),
pytest.param(
"-", "-", "",
id="stdin-to-stdout",
),
pytest.param(
"a:b", "a", "b",
Expand Down Expand Up @@ -157,7 +162,7 @@ def test_filename_split(
):

def exists(fn: str) -> bool:
if fn == "-":
if fn in {"-", ""}:
return False
print("Exists?", fn, fn in {input_filename, output_filename})
return fn in {input_filename, output_filename}
Expand Down

0 comments on commit 288f0f7

Please sign in to comment.