Skip to content

Commit

Permalink
Remove restriction that OUTPUT cannot be in any input directory
Browse files Browse the repository at this point in the history
We need this for nancy-invoice, for example.

This restriction was moved to Nancy from Linton. It makes sense in
Linton (and in many or even most Nany uses), but not always for Nancy.
  • Loading branch information
rrthomas committed Nov 28, 2024
1 parent fa9ea0a commit 6fea0a1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ options:
The INPUT-PATH is a ':'-separated list; the inputs are merged
in left-to-right order.
OUTPUT cannot be in any input directory.
```

## Operation <a name="operation"></a>
Expand Down
26 changes: 5 additions & 21 deletions nancy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ def main(argv: List[str] = sys.argv[1:]) -> None:
description="A simple templating system.",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=f"The INPUT-PATH is a '{os.path.pathsep}'-separated list; the inputs are merged\n"
+ "in left-to-right order.\n\n"
+ "OUTPUT cannot be in any input directory.",
+ "in left-to-right order."
)
parser.add_argument(
"input",
Expand Down Expand Up @@ -303,25 +302,10 @@ def main(argv: List[str] = sys.argv[1:]) -> None:

# Deal with special case where INPUT is a single file and --path is not
# given.
single_file_no_path = False
if args.path is None and len(inputs) == 1:
if os.path.isfile(inputs[0]):
single_file_no_path = True
args.path = inputs[0]
inputs[0] = os.getcwd()

# Check output is not under an input path provided we're not dealing with
# the special case above.
if not single_file_no_path:
for root in inputs:
relative = os.path.relpath(args.output, start=root)
if (
args.output != "-"
and relative != ""
and not relative.startswith("..")
and not os.path.isabs(relative)
):
raise ValueError("output cannot be in any input directory")
if args.path is None and len(inputs) == 1 and os.path.isfile(inputs[0]):
args.path = inputs[0]
inputs[0] = os.getcwd()

expand(inputs, args.output, args.path)
except Exception as err: # pylint: disable=broad-exception-caught
if "DEBUG" in os.environ:
Expand Down
14 changes: 0 additions & 14 deletions tests/test_nancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,6 @@ def test_absolute_build_path_causes_an_error(
)


def test_output_to_subdirectory_of_input_causes_an_error(
capsys: CaptureFixture[str],
caplog: LogCaptureFixture,
) -> None:
with chdir(tests_dir):
failing_cli_test(
capsys,
caplog,
["webpage-src"],
"output cannot be in any input directory",
"webpage-src/foo",
)


# pylint: disable-next=invalid-name
def test_empty_INPUT_PATH_causes_an_error(
capsys: CaptureFixture[str],
Expand Down

0 comments on commit 6fea0a1

Please sign in to comment.