@@ -314,9 +314,9 @@ def process_block(block, src_in_lines, file_optional_tags):
314
314
def output_filename(filename):
315
315
if len(args.filename) == 2 and not args.overwrite and not args.no_overwrite:
316
316
if args.filename[0] == filename:
317
- print("sage-fixdoctests: When passing two filenames, the second one is taken as an output filename; "
318
- "this is deprecated. To pass two input filenames, use the option --overwrite.")
319
317
return args.filename[1]
318
+ else:
319
+ return None
320
320
return filename + ".fixed"
321
321
if args.no_overwrite:
322
322
return filename + ".fixed"
@@ -340,7 +340,14 @@ else:
340
340
print(f'Doctester exited with error status {status}')
341
341
sys.exit(status)
342
342
# Run the doctester, putting the output of the test into sage's temporary directory
343
- input_args = " ".join(shlex.quote(f) for f in args.filename)
343
+ if len(args.filename) == 2 and not args.overwrite and not args.no_overwrite:
344
+ print("sage-fixdoctests: When passing two filenames, the second one is taken as an output filename; "
345
+ "this is deprecated. To pass two input filenames, use the option --overwrite.")
346
+
347
+ input_filenames = [args.filename[0]]
348
+ else:
349
+ input_filenames = args.filename
350
+ input_args = " ".join(shlex.quote(f) for f in input_filenames)
344
351
cmdline = f'{shlex.quote(executable)} -t -p {environment_args}{long_args}{probe_args}{lib_args}{input_args}'
345
352
print(f'Running "{cmdline}"')
346
353
os.system(f'{cmdline} > {shlex.quote(doc_file)}')
@@ -364,7 +371,7 @@ def block_filename(block):
364
371
365
372
def expanded_filename_args():
366
373
DD = DocTestDefaults(optional='all')
367
- DC = DocTestController(DD, args.filename )
374
+ DC = DocTestController(DD, input_filenames )
368
375
DC.add_files()
369
376
DC.expand_files_into_sources()
370
377
for source in DC.sources:
@@ -418,22 +425,23 @@ def process_grouped_blocks(grouped_iterator):
418
425
persistent_optional_tags = {}
419
426
420
427
if src_in_lines != shallow_copy_of_src_in_lines:
421
- output = output_filename(input)
422
- with open(output, 'w') as test_output:
423
- for line in src_in_lines:
424
- if line is None:
425
- continue
426
- test_output.write(line)
427
- test_output.write('\n')
428
-
429
- # Show summary of changes
430
- if input != output:
431
- print("The fixed doctests have been saved as '{0}'.".format(output))
428
+ if (output := output_filename(input)) is None:
429
+ print(f"Not saving modifications made in '{input}'")
432
430
else:
433
- relative = os.path.relpath(output, SAGE_ROOT)
434
- print(f"The input file '{output}' has been overwritten.")
435
- if not relative.startswith('..'):
436
- subprocess.call(['git', '--no-pager', 'diff', relative], cwd=SAGE_ROOT)
431
+ with open(output, 'w') as test_output:
432
+ for line in src_in_lines:
433
+ if line is None:
434
+ continue
435
+ test_output.write(line)
436
+ test_output.write('\n')
437
+ # Show summary of changes
438
+ if input != output :
439
+ print("The fixed doctests have been saved as '{0}'.".format(output))
440
+ else:
441
+ relative = os.path.relpath(output, SAGE_ROOT)
442
+ print(f"The input file '{output}' has been overwritten.")
443
+ if not relative.startswith('..'):
444
+ subprocess.call(['git', '--no-pager', 'diff', relative], cwd=SAGE_ROOT)
437
445
else:
438
446
print(f"No fixes made in '{input}'")
439
447
0 commit comments