@@ -100,8 +100,9 @@ def find_replacements(location, package_regex=None, verbose=False):
100
100
EXAMPLES::
101
101
102
102
sage: from sage.misc.replace_dot_all import *
103
- sage: location = sage.env.SAGE_SRC + '/sage/structure/element.pyx'
104
- sage: find_replacements(location, verbose=True)
103
+ sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
104
+ sage: find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True)
105
+ [[..., ..., 'from sage.plot.graphics import Graphics']]
105
106
"""
106
107
if package_regex is None :
107
108
package_regex = default_package_regex
@@ -259,7 +260,7 @@ def find_replacements(location, package_regex=None, verbose=False):
259
260
return replacements
260
261
261
262
262
- def process_line (location , line , replacements , import_index , verbose = False ):
263
+ def process_line (location , line , replacements , row_index , verbose = False ):
263
264
r"""
264
265
Modify a single source code ``line`` according to the given ``replacements``.
265
266
@@ -268,7 +269,7 @@ def process_line(location, line, replacements, import_index, verbose=False):
268
269
- ``location`` -- a file path; only used for logging
269
270
- ``line`` -- a source code line
270
271
- ``replacements`` -- the array output from :func:`find_replacements`
271
- - ``import_index `` -- the column number where ``import`` appears
272
+ - ``row_index `` -- the line number where ``import`` appears
272
273
- ``verbose`` -- if True, issue print statements when interesting examples are found
273
274
274
275
OUTPUT:
@@ -283,22 +284,27 @@ def process_line(location, line, replacements, import_index, verbose=False):
283
284
Replacing the first line which needs a replacement in the file with filepath ``src/sage/structure/element.pyx``::
284
285
285
286
sage: from sage.misc.replace_dot_all import *
286
- sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/structure/element.pyx')
287
- sage: replacements = find_replacements(location, verbose=True)
287
+ sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
288
+ sage: replacements = find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True); replacements
289
+ [[471, 24, 'from sage.plot.graphics import Graphics']]
288
290
sage: with open(location, "r") as file:
289
291
....: lines = file.readlines()
290
- sage: row_index, import_index, *_ = replacements[0]
291
- sage: line = lines[row_index]; line
292
- sage: new_line, replacements = process_line(location, line, replacements, import_index)
293
- sage: new_line
292
+ sage: row_index, col_number, *_ = replacements[0]
293
+ sage: line = lines[row_index]
294
+ sage: print(line.rstrip())
295
+ from sage.plot.all import Graphics
296
+ sage: new_line, replacements = process_line(location, line, replacements, row_index)
297
+ sage: print(new_line)
298
+ from sage.plot.graphics import Graphics
294
299
sage: replacements
300
+ []
295
301
"""
296
302
line = line .rstrip () # stripping line break
297
303
new_line = ''
298
304
global log_messages , interesting_examples
299
305
if len (replacements ) == 0 :
300
306
return line , replacements
301
- if import_index == replacements [0 ][0 ]: # if line marked as containing .all
307
+ if row_index == replacements [0 ][0 ]: # if line marked as containing .all
302
308
replacement = replacements .pop (0 )
303
309
leading_space = 0
304
310
while line and line [leading_space ] == ' ' and leading_space < len (line )- 1 :
0 commit comments