changeset 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 953a5baa406d
files .hgignore config.py problem.py testcases.py upreckon-vcs upreckon.sublime-project
diffstat 6 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Feb 23 23:35:27 2011 +0000
+++ b/.hgignore	Thu Feb 24 00:10:19 2011 +0000
@@ -1,2 +1,2 @@
-\.pyc$
+\.(pyc|pyo|class|orig)$
 (/|^)suite$
\ No newline at end of file
--- a/config.py	Wed Feb 23 23:35:27 2011 +0000
+++ b/config.py	Thu Feb 24 00:10:19 2011 +0000
@@ -90,8 +90,11 @@
 
 def load_problem(problem_name):
 	global builtins
-	dwb = sys.dont_write_bytecode
-	sys.dont_write_bytecode = True
+	try:
+		dwb = sys.dont_write_bytecode
+		sys.dont_write_bytecode = True
+	except AttributeError:
+		pass
 	metafile = files.File('/'.join((problem_name, 'testconf.py')), True, 'configuration')
 	module = None
 	with CompatBuiltins() as builtins:
@@ -157,7 +160,10 @@
 			setattr(module, name, newmap)
 	if options.no_maxtime:
 		module.maxcputime = module.maxwalltime = 0
-	sys.dont_write_bytecode = dwb
+	try:
+		sys.dont_write_bytecode = dwb
+	except NameError:
+		pass
 	for name in patterns:
 		if hasattr(module, name):
 			setattr(module, name, getattr(module, name).replace('%', problem_name))
@@ -165,8 +171,11 @@
 
 def load_global():
 	global builtins
-	dwb = sys.dont_write_bytecode
-	sys.dont_write_bytecode = True
+	try:
+		dwb = sys.dont_write_bytecode
+		sys.dont_write_bytecode = True
+	except AttributeError:
+		pass
 	metafile = files.File('testconf.py', True, 'configuration')
 	module = None
 	with CompatBuiltins() as builtins:
@@ -199,5 +208,8 @@
 		module.problems = module.tasknames
 	global globalconf
 	globalconf = module
-	sys.dont_write_bytecode = dwb
+	try:
+		sys.dont_write_bytecode = dwb
+	except NameError:
+		pass
 	return module
\ No newline at end of file
--- a/problem.py	Wed Feb 23 23:35:27 2011 +0000
+++ b/problem.py	Thu Feb 24 00:10:19 2011 +0000
@@ -207,7 +207,8 @@
 			sys.stdout.flush()
 			return weighted, prob.config.taskweight
 		finally:
-			if options.erase and (not prob.config.stdio or case and case.validator):
+			if options.erase and (not prob.config.stdio or case and
+				(case.validator and not callable(case.validator))):
 				for var in 'in', 'out':
 					name = getattr(prob.config, var + 'name')
 					if name:
--- a/testcases.py	Wed Feb 23 23:35:27 2011 +0000
+++ b/testcases.py	Thu Feb 24 00:10:19 2011 +0000
@@ -279,7 +279,7 @@
 				contextmgr = Copying(case.infile, inputdatafname)
 			with contextmgr:
 				with open(inputdatafname) as infile:
-					with tempfile.TemporaryFile('w+') if options.erase and not case.validator else open(case.problem.config.outname, 'w+') as outfile:
+					with tempfile.TemporaryFile('w+') if options.erase and (not case.validator or callable(case.validator)) else open(case.problem.config.outname, 'w+') as outfile:
 						call(case.problem.config.path, case=case, stdin=infile, stdout=outfile, stderr=devnull, universal_newlines=True, bufsize=-1)
 						if config.globalconf.force_zero_exitcode and case.process.returncode or case.process.returncode < 0:
 							raise NonZeroExitCode(case.process.returncode)
--- a/upreckon-vcs	Wed Feb 23 23:35:27 2011 +0000
+++ b/upreckon-vcs	Thu Feb 24 00:10:19 2011 +0000
@@ -161,4 +161,4 @@
 		globalconf.pause()
 	else:
 		with open(os.devnull, 'w') as devnull:
-			subprocess.call(globalconf.pause, stdout=devnull, stderr=subprocess.STDOUT)
\ No newline at end of file
+			subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT)
\ No newline at end of file
--- a/upreckon.sublime-project	Wed Feb 23 23:35:27 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-<!-- Documentation is available at http://www.sublimetext.com/docs/projects -->
-<project>
-	<mount name="2.00" dir="." exclude="*.png,*.jpg,*.exe,*.dll,*.obj,*.pyc" direxclude=".svn,.git,.hg,CVS,bin,*"/>
-	<!-- <mount name="1.21" dir=".." include="*.py" direxclude="*"/> -->
-	<options>
-<![CDATA[
-buildFile Packages/C++/Make.sublime-build
-]]>
-	</options>
-</project>