Skip to content

Commit 60550b0

Browse files
committed
Prevent PLY to overwrite its generated files.
Ref astropy#5581, fixes astropy#5726. After astropy#5526 updated PLY to 3.9, some files were re-generated at runtime (astropy/coordinates/{angle_lextab.py,angle_parsetab.py}). This is because of this line https://github.com/dabeaz/ply/blob/master/ply/lex.py#L901 which assumes that the lextab parameter in `lex.lex` is a str only, not unicode, which leads to some surprise when unicode_literals is used on Python 2 ! So this commit just wraps the lextab value to make sure that a str is always passed to `lex.lex`.
1 parent c4923dd commit 60550b0

4 files changed

Lines changed: 11 additions & 21 deletions

File tree

‎astropy/coordinates/angle_utilities.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def t_error(t):
126126
"Invalid character at col {0}".format(t.lexpos))
127127

128128
# Build the lexer
129-
lexer = lex.lex(optimize=True, lextab='angle_lextab',
129+
lexer = lex.lex(optimize=True, lextab=str('angle_lextab'),
130130
outputdir=os.path.dirname(__file__))
131131

132132
def p_angle(p):
@@ -251,7 +251,7 @@ def p_arcminute(p):
251251
def p_error(p):
252252
raise ValueError
253253

254-
parser = yacc.yacc(debug=False, tabmodule='angle_parsetab',
254+
parser = yacc.yacc(debug=False, tabmodule=str('angle_parsetab'),
255255
outputdir=os.path.dirname(__file__),
256256
write_tables=True)
257257

‎astropy/units/format/cds.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def t_error(t):
124124
raise ValueError(
125125
"Invalid character at col {0}".format(t.lexpos))
126126

127-
lexer = lex.lex(optimize=True, lextab='cds_lextab',
127+
lexer = lex.lex(optimize=True, lextab=str('cds_lextab'),
128128
outputdir=os.path.dirname(__file__),
129129
reflags=re.UNICODE)
130130

@@ -257,7 +257,7 @@ def p_signed_float(p):
257257
def p_error(p):
258258
raise ValueError()
259259

260-
parser = yacc.yacc(debug=False, tabmodule='cds_parsetab',
260+
parser = yacc.yacc(debug=False, tabmodule=str('cds_parsetab'),
261261
outputdir=os.path.dirname(__file__),
262262
write_tables=True)
263263

‎astropy/units/format/generic.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,9 @@ def t_error(t):
156156
raise ValueError(
157157
"Invalid character at col {0}".format(t.lexpos))
158158

159-
try:
160-
from . import generic_lextab
161-
lexer = lex.lex(optimize=True, lextab=generic_lextab,
162-
reflags=re.UNICODE)
163-
except ImportError:
164-
lexer = lex.lex(optimize=True, lextab='generic_lextab',
165-
outputdir=os.path.dirname(__file__),
166-
reflags=re.UNICODE)
159+
lexer = lex.lex(optimize=True, lextab=str('generic_lextab'),
160+
outputdir=os.path.dirname(__file__),
161+
reflags=re.UNICODE)
167162

168163
return lexer
169164

@@ -423,13 +418,8 @@ def p_function(p):
423418
def p_error(p):
424419
raise ValueError()
425420

426-
try:
427-
from . import generic_parsetab
428-
parser = yacc.yacc(debug=False, tabmodule=generic_parsetab,
429-
write_tables=False)
430-
except ImportError:
431-
parser = yacc.yacc(debug=False, tabmodule='generic_parsetab',
432-
outputdir=os.path.dirname(__file__))
421+
parser = yacc.yacc(debug=False, tabmodule=str('generic_parsetab'),
422+
outputdir=os.path.dirname(__file__))
433423

434424
return parser
435425

‎astropy/units/format/ogip.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def t_error(t):
163163
raise ValueError(
164164
"Invalid character at col {0}".format(t.lexpos))
165165

166-
lexer = lex.lex(optimize=True, lextab='ogip_lextab',
166+
lexer = lex.lex(optimize=True, lextab=str('ogip_lextab'),
167167
outputdir=os.path.dirname(__file__))
168168

169169
return lexer
@@ -353,7 +353,7 @@ def p_signed_float(p):
353353
def p_error(p):
354354
raise ValueError()
355355

356-
parser = yacc.yacc(debug=False, tabmodule='ogip_parsetab',
356+
parser = yacc.yacc(debug=False, tabmodule=str('ogip_parsetab'),
357357
outputdir=os.path.dirname(__file__),
358358
write_tables=True)
359359

0 commit comments

Comments
 (0)