Skip to content

Commit 3b9cf86

Browse files
committed
Small fix. Comment updates.
More comments and note on creating parent dirs in dry run. Parent dirs were not created in one case.
1 parent 8aa15b4 commit 3b9cf86

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

‎repren‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,17 @@ def transform_file(transform, source_path, dest_path,
321321
temp_suffix=TEMP_SUFFIX,
322322
by_line=False,
323323
dry_run=False):
324-
'''Transform full contents of file at source_path in memory with specified
325-
function, writing dest_path atomically and keeping a backup. Source and
326-
destination may be the same path.'''
324+
'''Transform full contents of file at source_path with specified function,
325+
either line-by-line or at once in memory, writing dest_path atomically and keeping a backup.
326+
Source and destination may be the same path.'''
327327
counts = _MatchCounts()
328328
global _tally
329329
changed = False
330330
if transform:
331331
orig_path = source_path + orig_suffix
332332
temp_path = dest_path + temp_suffix
333+
# TODO: This will create a directory even in dry_run mode, but perhaps that's acceptable.
334+
# https://github.com/jlevy/repren/issues/6
333335
make_parent_dirs(temp_path)
334336
perms = os.stat(source_path).st_mode & 0o777
335337
with open(source_path, "rb") as stream_in:
@@ -342,7 +344,7 @@ def transform_file(transform, source_path, dest_path,
342344
move_file(source_path, orig_path, clobber=True)
343345
move_file(temp_path, dest_path, clobber=False)
344346
else:
345-
# If we're not in dry-run mode, or if there were no changes at all, just forget the output.
347+
# If we're in dry-run mode, or if there were no changes at all, just forget the output.
346348
os.remove(temp_path)
347349

348350
_tally.files += 1
@@ -354,6 +356,7 @@ def transform_file(transform, source_path, dest_path,
354356
changed = True
355357
elif dest_path != source_path:
356358
if not dry_run:
359+
make_parent_dirs(dest_path)
357360
move_file(source_path, dest_path, clobber=False)
358361
_tally.files += 1
359362
_tally.renames += 1

‎tests/tests-clean.log‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ uname
66
Darwin
77

88
python -V
9-
Python 2.7.10
9+
Python 2.7.11
1010

11-
repren || expect_error
11+
run || expect_error
1212
Usage: repren -p <pattern-file> [options] [path ...]
1313

1414
repren: error: must specify --patterns or both --from and --to

‎tests/tests.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uname
3939

4040
python -V
4141

42-
repren || expect_error
42+
run || expect_error
4343

4444
# Text replacements, no renames.
4545

0 commit comments

Comments
 (0)