Skip to content

Commit 5cece38

Browse files
REV: 96727cf
This is a Python 2 script, and will remain so for some time. Instead of simply reverting the commit, use try/except to find the proper way to import which.
1 parent f807a0b commit 5cece38

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

numpy/linalg/lapack_lite/clapack_scrub.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import os
44
import re
55
import sys
6-
from io import StringIO
76

87
from plex import Scanner, Str, Lexicon, Opt, Bol, State, AnyChar, TEXT, IGNORE
98
from plex.traditional import re as Re
109

10+
try:
11+
from io import BytesIO as UStringIO # Python 2
12+
except ImportError:
13+
from io import StringIO as UStringIO # Python 3
14+
1115

1216
class MyScanner(Scanner):
1317
def __init__(self, info, name='<default>'):
@@ -23,8 +27,8 @@ def sep_seq(sequence, sep):
2327
return pat
2428

2529
def runScanner(data, scanner_class, lexicon=None):
26-
info = StringIO(data)
27-
outfo = StringIO()
30+
info = UStringIO(data)
31+
outfo = UStringIO()
2832
if lexicon is not None:
2933
scanner = scanner_class(lexicon, info)
3034
else:
@@ -191,7 +195,7 @@ def HaveBlankLines(line):
191195
return SourceLines
192196

193197
state = SourceLines
194-
for line in StringIO(source):
198+
for line in UStringIO(source):
195199
state = state(line)
196200
comments.flushTo(lines)
197201
return lines.getValue()
@@ -219,7 +223,7 @@ def OutOfHeader(line):
219223
return OutOfHeader
220224

221225
state = LookingForHeader
222-
for line in StringIO(source):
226+
for line in UStringIO(source):
223227
state = state(line)
224228
return lines.getValue()
225229

@@ -228,7 +232,7 @@ def removeSubroutinePrototypes(source):
228232
r'/\* Subroutine \*/^\s*(?:(?:inline|static)\s+){0,2}(?!else|typedef|return)\w+\s+\*?\s*(\w+)\s*\([^0]+\)\s*;?'
229233
)
230234
lines = LineQueue()
231-
for line in StringIO(source):
235+
for line in UStringIO(source):
232236
if not expression.match(line):
233237
lines.add(line)
234238

@@ -250,7 +254,7 @@ def InBuiltInFunctions(line):
250254
return InBuiltInFunctions
251255

252256
state = LookingForBuiltinFunctions
253-
for line in StringIO(source):
257+
for line in UStringIO(source):
254258
state = state(line)
255259
return lines.getValue()
256260

numpy/linalg/lapack_lite/make_lite.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import fortran
2222
import clapack_scrub
2323

24-
from shutil import which
24+
try:
25+
from distutils.spawn import find_executable as which # Python 2
26+
except ImportError:
27+
from shutil import which # Python 3
2528

2629
# Arguments to pass to f2c. You'll always want -A for ANSI C prototypes
2730
# Others of interest: -a to not make variables static by default

0 commit comments

Comments
 (0)