Skip to content

Commit 80acb13

Browse files
committed
Remove $realpath (fix #21)
1 parent a641566 commit 80acb13

File tree

11 files changed

+17
-67
lines changed

11 files changed

+17
-67
lines changed

Cookbook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ $run(make-zip.in.sh,\$outputpath/\$path)
232232

233233
## Processing files in the input directory
234234

235-
Sometimes we would like to process input files using a command other than `nancy`. For example, a file can display its own modification date using `$realpath` like this:
235+
Sometimes we would like to process input files using a command other than `nancy`. For example, a file can display its own modification date using `NANCY_INPUT` like this:
236236

237237
```
238-
$run(date,-d,@$run(stat,-c%Y,$realpath),+%F)
238+
$run(date,-d,@$run(sh,-c,stat -c%Y \\$NANCY_INPUT/$path),+%F)
239239
```
240240

241241
We might want to process a different file. For example, [`timeplate.in.html`](#website-example) could display the modification date of `main.in.html` using `$filename` like this:

Cookbook.nancy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ Assuming it is called `make-zip.in.sh`, it can be used thus, from a file called
129129

130130
## Processing files in the input directory
131131

132-
Sometimes we would like to process input files using a command other than `nancy`. For example, a file can display its own modification date using `\$realpath` like this:
132+
Sometimes we would like to process input files using a command other than `nancy`. For example, a file can display its own modification date using `NANCY_INPUT` like this:
133133

134134
```
135-
\$run(date,-d,@$run(stat,-c%Y,$realpath),+%F)
135+
\$run(date,-d,@$run(sh,-c,stat -c%Y \\$NANCY_INPUT/$path),+%F)
136136
```
137137

138138
We might want to process a different file. For example, [`timeplate.in.html`](#website-example) could display the modification date of `main.in.html` using `\$filename` like this:

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ Nancy recognises these commands:
160160
+ *`$path`* Expands to the file currently being expanded, relative to the
161161
input tree. This is always a template file, unless the current input path
162162
is a single file.
163-
+ *`$realpath`* Returns the real path of the file currently being expanded.
164163
+ *`$outputpath`* Returns the path of the output tree for the file currently
165164
being expanded, relative to `NANCY_OUTPUT`.
166165

@@ -210,18 +209,17 @@ See the [date example](Cookbook.md#date-example) in the Cookbook for more
210209
detail.
211210

212211
If one command is nested inside another, the inner command will be processed
213-
first. This means that if, for example, `$realpath` is passed as an
214-
argument to a program, the program will be given the actual path, rather
215-
than the string `$realpath`. Arguments and command inputs are processed
216-
from left to right.
212+
first. This means that if, for example, `$path` is passed as an argument to
213+
a program, the program will be given the actual path, rather than the string
214+
`$path`. Arguments and command inputs are processed from left to right.
217215

218216
### Environment variables provided by `$run`
219217

220218
When Nancy `$run`s a program, it sets the following environment variables:
221219

222-
- NANCY_INPUT - the root of whichever of the input trees contains the file that
223-
is being expanded: a prefix of `$realpath`. The file's name, relative to
224-
`NANCY_INPUT`, is `$path`.
220+
- NANCY_INPUT - the root of whichever of the input trees contains the file
221+
that is being expanded. The file's name, relative to `NANCY_INPUT`, is
222+
`$path`.
225223
- NANCY_OUTPUT - the root of the output tree.
226224

227225
### Escaping

README.nancy.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ Nancy recognises these commands:
143143
+ *`\$path`* Expands to the file currently being expanded, relative to the
144144
input tree. This is always a template file, unless the current input path
145145
is a single file.
146-
+ *`\$realpath`* Returns the real path of the file currently being expanded.
147146
+ *`\$outputpath`* Returns the path of the output tree for the file currently
148147
being expanded, relative to `NANCY_OUTPUT`.
149148

@@ -193,18 +192,17 @@ See the [date example](Cookbook.md#date-example) in the Cookbook for more
193192
detail.
194193

195194
If one command is nested inside another, the inner command will be processed
196-
first. This means that if, for example, `\$realpath` is passed as an
197-
argument to a program, the program will be given the actual path, rather
198-
than the string `\$realpath`. Arguments and command inputs are processed
199-
from left to right.
195+
first. This means that if, for example, `\$path` is passed as an argument to
196+
a program, the program will be given the actual path, rather than the string
197+
`\$path`. Arguments and command inputs are processed from left to right.
200198

201199
### Environment variables provided by `\$run`
202200

203201
When Nancy `\$run`s a program, it sets the following environment variables:
204202

205-
- NANCY_INPUT - the root of whichever of the input trees contains the file that
206-
is being expanded: a prefix of `\$realpath`. The file's name, relative to
207-
`NANCY_INPUT`, is `\$path`.
203+
- NANCY_INPUT - the root of whichever of the input trees contains the file
204+
that is being expanded. The file's name, relative to `NANCY_INPUT`, is
205+
`\$path`.
208206
- NANCY_OUTPUT - the root of the output tree.
209207

210208
### Escaping

nancy/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def __init__(
266266
def input_file(self):
267267
"""Returns the filesystem input `Path`."""
268268
if self.root is None:
269-
raise ValueError("$realpath is not available for directories")
269+
raise ValueError("input_file() is not available for directories")
270270
return self.root / self.path
271271

272272
def output_path(self):
@@ -453,13 +453,6 @@ def path(self, args: Optional[list[bytes]], input: Optional[bytes]) -> bytes:
453453
raise ValueError("$path does not take an input")
454454
return bytes(self._expand.path)
455455

456-
def realpath(self, args: Optional[list[bytes]], input: Optional[bytes]) -> bytes:
457-
if args is not None:
458-
raise ValueError("$realpath does not take arguments")
459-
if input is not None:
460-
raise ValueError("$realpath does not take an input")
461-
return bytes(self._expand.input_file())
462-
463456
def outputpath(self, args: Optional[list[bytes]], input: Optional[bytes]) -> bytes:
464457
if args is not None:
465458
raise ValueError("$outputpath does not take arguments")

tests/test-files/realpath-arg.nancy.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test-files/realpath-expected.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test-files/realpath-in-dirname-src/$realpath/dummy.in

Whitespace-only changes.

tests/test-files/realpath-input.nancy.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test-files/realpath.nancy.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)