[Python-checkins] gh-97669: Move difflib examples to Doc/includes/ (#97964)

ambv webhook-mailer at python.org
Fri Oct 7 13:57:56 EDT 2022


https://github.com/python/cpython/commit/002252c4ade6a5aeb7a397776dbe3c1de0740e84
commit: 002252c4ade6a5aeb7a397776dbe3c1de0740e84
branch: main
author: Victor Stinner <vstinner at python.org>
committer: ambv <lukasz at langa.pl>
date: 2022-10-07T10:57:48-07:00
summary:

gh-97669: Move difflib examples to Doc/includes/ (#97964)

Remove diff.py and ndiff.py scripts of Tools/scripts/: move them to
Doc/includes/.

* diff.py and ndiff.py files are no longer executable. Remove also
  their shebang ("#!/usr/bin/env python3").
* Remove the -profile command from ndiff.py to simply the code.
* Remove ndiff.py copyright and history command. The Python
  documentation examples are distributed under the "Zero Clause BSD
  License".

files:
A Doc/includes/diff.py
A Doc/includes/ndiff.py
D Tools/scripts/diff.py
D Tools/scripts/ndiff.py
M Doc/library/difflib.rst

diff --git a/Tools/scripts/diff.py b/Doc/includes/diff.py
old mode 100755
new mode 100644
similarity index 98%
rename from Tools/scripts/diff.py
rename to Doc/includes/diff.py
index 96199b85116d..001619f5f83f
--- a/Tools/scripts/diff.py
+++ b/Doc/includes/diff.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python3
 """ Command line interface to difflib.py providing diffs in four formats:
 
 * ndiff:    lists every line and highlights interline changes.
diff --git a/Tools/scripts/ndiff.py b/Doc/includes/ndiff.py
old mode 100755
new mode 100644
similarity index 80%
rename from Tools/scripts/ndiff.py
rename to Doc/includes/ndiff.py
index c6d09b8f242f..32c251bce912
--- a/Tools/scripts/ndiff.py
+++ b/Doc/includes/ndiff.py
@@ -1,16 +1,3 @@
-#! /usr/bin/env python3
-
-# Module ndiff version 1.7.0
-# Released to the public domain 08-Dec-2000,
-# by Tim Peters (tim.one at home.com).
-
-# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
-
-# ndiff.py is now simply a front-end to the difflib.ndiff() function.
-# Originally, it contained the difflib.SequenceMatcher class as well.
-# This completes the raiding of reusable code from this formerly
-# self-contained script.
-
 """ndiff [-q] file1 file2
     or
 ndiff (-r1 | -r2) < ndiff_output > file1_or_file2
@@ -121,13 +108,4 @@ def restore(which):
     sys.stdout.writelines(restored)
 
 if __name__ == '__main__':
-    args = sys.argv[1:]
-    if "-profile" in args:
-        import profile, pstats
-        args.remove("-profile")
-        statf = "ndiff.pro"
-        profile.run("main(args)", statf)
-        stats = pstats.Stats(statf)
-        stats.strip_dirs().sort_stats('time').print_stats()
-    else:
-        main(args)
+    main(sys.argv[1:])
diff --git a/Doc/library/difflib.rst b/Doc/library/difflib.rst
index c5a279688a44..5ee1f4a02c68 100644
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -145,8 +145,6 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
       The arguments for this method are the same as those for the :meth:`make_file`
       method.
 
-   :file:`Tools/scripts/diff.py` is a command-line front-end to this class and
-   contains a good example of its use.
 
 
 .. function:: context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n')
@@ -240,8 +238,6 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
    function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
    blank or tab; it's a bad idea to include newline in this!).
 
-   :file:`Tools/scripts/ndiff.py` is a command-line front-end to this function.
-
       >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
       ...              'ore\ntree\nemu\n'.splitlines(keepends=True))
       >>> print(''.join(diff), end="")
@@ -759,7 +755,12 @@ A command-line interface to difflib
 -----------------------------------
 
 This example shows how to use difflib to create a ``diff``-like utility.
-It is also contained in the Python source distribution, as
-:file:`Tools/scripts/diff.py`.
 
-.. literalinclude:: ../../Tools/scripts/diff.py
+.. literalinclude:: ../includes/diff.py
+
+ndiff example
+-------------
+
+This example shows how to use :func:`difflib.ndiff`.
+
+.. literalinclude:: ../includes/ndiff.py



More information about the Python-checkins mailing list