@@ -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
0 commit comments