comparison config.py @ 83:37c4ad87583c

Several small fixes Bug fix: testconf.py bytecode is written on Python 2.5. It is not written on newer versions of Python, but Python 2.5 lacks the facility to disable writing it; before this fix, the code just raised an unhandled exception. Bug fix: callable validators no longer require the outfile configuration variable to be set. Bug fix: the pause configuration variable (if not callable) is run in a shell just like it did in test.py v1; in particular, auto-detected values of the pause configuration variable now work again. Extras: *.{class,orig} added to .hgignore; Sublime Text 1 project file removed as I am using Sublime Text 2 now.
author Oleg Oshmyan <chortos@inbox.lv>
date Thu, 24 Feb 2011 00:10:19 +0000
parents 06356af50bf9
children cd347cfca272
comparison
equal deleted inserted replaced
82:06356af50bf9 83:37c4ad87583c
88 self.file.close() 88 self.file.close()
89 os.remove(self.name) 89 os.remove(self.name)
90 90
91 def load_problem(problem_name): 91 def load_problem(problem_name):
92 global builtins 92 global builtins
93 dwb = sys.dont_write_bytecode 93 try:
94 sys.dont_write_bytecode = True 94 dwb = sys.dont_write_bytecode
95 sys.dont_write_bytecode = True
96 except AttributeError:
97 pass
95 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration') 98 metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration')
96 module = None 99 module = None
97 with CompatBuiltins() as builtins: 100 with CompatBuiltins() as builtins:
98 if zipimport and isinstance(metafile.archive, files.ZipArchive): 101 if zipimport and isinstance(metafile.archive, files.ZipArchive):
99 try: 102 try:
155 except TypeError: 158 except TypeError:
156 newmap[key] = oldmap[key] 159 newmap[key] = oldmap[key]
157 setattr(module, name, newmap) 160 setattr(module, name, newmap)
158 if options.no_maxtime: 161 if options.no_maxtime:
159 module.maxcputime = module.maxwalltime = 0 162 module.maxcputime = module.maxwalltime = 0
160 sys.dont_write_bytecode = dwb 163 try:
164 sys.dont_write_bytecode = dwb
165 except NameError:
166 pass
161 for name in patterns: 167 for name in patterns:
162 if hasattr(module, name): 168 if hasattr(module, name):
163 setattr(module, name, getattr(module, name).replace('%', problem_name)) 169 setattr(module, name, getattr(module, name).replace('%', problem_name))
164 return module 170 return module
165 171
166 def load_global(): 172 def load_global():
167 global builtins 173 global builtins
168 dwb = sys.dont_write_bytecode 174 try:
169 sys.dont_write_bytecode = True 175 dwb = sys.dont_write_bytecode
176 sys.dont_write_bytecode = True
177 except AttributeError:
178 pass
170 metafile = files.File('testconf.py', True, 'configuration') 179 metafile = files.File('testconf.py', True, 'configuration')
171 module = None 180 module = None
172 with CompatBuiltins() as builtins: 181 with CompatBuiltins() as builtins:
173 if zipimport and isinstance(metafile.archive, files.ZipArchive): 182 if zipimport and isinstance(metafile.archive, files.ZipArchive):
174 try: 183 try:
197 setattr(module, name, getattr(module, name, defaults_noerase[name])) 206 setattr(module, name, getattr(module, name, defaults_noerase[name]))
198 if hasattr(module, 'tasknames'): 207 if hasattr(module, 'tasknames'):
199 module.problems = module.tasknames 208 module.problems = module.tasknames
200 global globalconf 209 global globalconf
201 globalconf = module 210 globalconf = module
202 sys.dont_write_bytecode = dwb 211 try:
212 sys.dont_write_bytecode = dwb
213 except NameError:
214 pass
203 return module 215 return module