Skip to content

Commit 97ae2e9

Browse files
vstinnermpage
authored andcommitted
pythongh-97669: Move difflib examples to Doc/includes/ (python#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".
1 parent 4ca8bb0 commit 97ae2e9

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

Tools/scripts/diff.py renamed to Doc/includes/diff.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python3
21
""" Command line interface to difflib.py providing diffs in four formats:
32
43
* ndiff: lists every line and highlights interline changes.

Tools/scripts/ndiff.py renamed to Doc/includes/ndiff.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
#! /usr/bin/env python3
2-
3-
# Module ndiff version 1.7.0
4-
# Released to the public domain 08-Dec-2000,
5-
# by Tim Peters ([email protected]).
6-
7-
# Provided as-is; use at your own risk; no warranty; no promises; enjoy!
8-
9-
# ndiff.py is now simply a front-end to the difflib.ndiff() function.
10-
# Originally, it contained the difflib.SequenceMatcher class as well.
11-
# This completes the raiding of reusable code from this formerly
12-
# self-contained script.
13-
141
"""ndiff [-q] file1 file2
152
or
163
ndiff (-r1 | -r2) < ndiff_output > file1_or_file2
@@ -121,13 +108,4 @@ def restore(which):
121108
sys.stdout.writelines(restored)
122109

123110
if __name__ == '__main__':
124-
args = sys.argv[1:]
125-
if "-profile" in args:
126-
import profile, pstats
127-
args.remove("-profile")
128-
statf = "ndiff.pro"
129-
profile.run("main(args)", statf)
130-
stats = pstats.Stats(statf)
131-
stats.strip_dirs().sort_stats('time').print_stats()
132-
else:
133-
main(args)
111+
main(sys.argv[1:])

Doc/library/difflib.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
145145
The arguments for this method are the same as those for the :meth:`make_file`
146146
method.
147147

148-
:file:`Tools/scripts/diff.py` is a command-line front-end to this class and
149-
contains a good example of its use.
150148

151149

152150
.. 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.
240238
function :func:`IS_CHARACTER_JUNK`, which filters out whitespace characters (a
241239
blank or tab; it's a bad idea to include newline in this!).
242240

243-
:file:`Tools/scripts/ndiff.py` is a command-line front-end to this function.
244-
245241
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True),
246242
... 'ore\ntree\nemu\n'.splitlines(keepends=True))
247243
>>> print(''.join(diff), end="")
@@ -759,7 +755,12 @@ A command-line interface to difflib
759755
-----------------------------------
760756

761757
This example shows how to use difflib to create a ``diff``-like utility.
762-
It is also contained in the Python source distribution, as
763-
:file:`Tools/scripts/diff.py`.
764758

765-
.. literalinclude:: ../../Tools/scripts/diff.py
759+
.. literalinclude:: ../includes/diff.py
760+
761+
ndiff example
762+
-------------
763+
764+
This example shows how to use :func:`difflib.ndiff`.
765+
766+
.. literalinclude:: ../includes/ndiff.py

0 commit comments

Comments
 (0)