Skip to content

Commit 7c2eeac

Browse files
committed
Make $outputpath relative (fix #24)
1 parent 082b007 commit 7c2eeac

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

Cookbook.nancy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ zip -r archive.zip .
124124
Assuming it is called `make-zip.in.sh`, it can be used thus, from a file called `make-zip.in.nancy`:
125125

126126
```
127-
\$run(make-zip.in.sh,\$outputpath)
127+
\$run(make-zip.in.sh,\$outputpath/\$path)
128128
```
129129

130130
## Processing files in the input directory

README.nancy.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ Nancy recognises these commands:
144144
input tree. This is always a template file, unless the current input path
145145
is a single file.
146146
+ *`\$realpath`* Returns the real path of the file currently being expanded.
147-
+ *`\$outputpath`* Returns the path of the output for the file currently
148-
being expanded.
147+
+ *`\$outputpath`* Returns the path of the output tree for the file currently
148+
being expanded, relative to `NANCY_OUTPUT`.
149149

150150
The last two commands are mostly useful in arguments to `\$run`.
151151

@@ -205,8 +205,7 @@ When Nancy `\$run`s a program, it sets the following environment variables:
205205
- NANCY_INPUT - the root of whichever of the input trees contains the file that
206206
is being expanded: a prefix of `\$realpath`. The file's name, relative to
207207
`NANCY_INPUT`, is `\$path`.
208-
209-
- NANCY_OUTPUT - the root of the output tree: a prefix of `\$outputpath`.
208+
- NANCY_OUTPUT - the root of the output tree.
210209

211210
### Escaping
212211

nancy/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,23 @@ def input_file(self):
269269
raise ValueError("$realpath is not available for directories")
270270
return self.root / self.path
271271

272-
def output_file(self):
273-
"""Returns the (computed) filesystem output `Path`.
272+
def output_path(self):
273+
"""Returns the relative output `Path` for the current file.
274274
275275
Raises an error if called while the filename is being expanded.
276276
"""
277277
if self._output_path is None:
278278
raise ValueError(
279279
"$outputfile is not available while expanding the filename"
280280
)
281-
return self.trees.output / self._output_path
281+
return self._output_path
282+
283+
def output_file(self):
284+
"""Returns the (computed) filesystem output `Path`.
285+
286+
Raises an error if called while the filename is being expanded.
287+
"""
288+
return self.trees.output / self.output_path()
282289

283290
def find_on_path(self, start_path: Path, file: Path) -> Optional[Path]:
284291
"""Search for file starting at the given path.
@@ -458,7 +465,7 @@ def outputpath(self, args: Optional[list[bytes]], input: Optional[bytes]) -> byt
458465
raise ValueError("$outputpath does not take arguments")
459466
if input is not None:
460467
raise ValueError("$outputpath does not take an input")
461-
return bytes(self._expand.output_file())
468+
return bytes(self._expand.output_path())
462469

463470
def expand(self, args: Optional[list[bytes]], input: Optional[bytes]) -> bytes:
464471
if args is not None:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
$run(sh,-c,printf '\a' > $expand{$run(dirname,$outputpath)}/bell.bin)
1+
$run(sh,-c,printf '\a' > $expand{$run(dirname,\\$NANCY_OUTPUT/$outputpath)}/bell.bin)

0 commit comments

Comments
 (0)