diff --git a/lib-python/2.7/compileall.py b/Lib/compileall.py rename from lib-python/2.7/compileall.py rename to Lib/compileall.py --- a/lib-python/2.7/compileall.py +++ b/Lib/compileall.py @@ -86,7 +86,7 @@ try: mtime = int(os.stat(fullname).st_mtime) expect = struct.pack('<4sl', imp.get_magic(), mtime) - cfile = fullname + (__debug__ and 'c' or 'o') + cfile = fullname.replace('.py', '$py.class') with open(cfile, 'rb') as chandle: actual = chandle.read(8) if expect == actual: diff --git a/bugtests/test403.py b/bugtests/test403.py new file mode 100644 --- /dev/null +++ b/bugtests/test403.py @@ -0,0 +1,34 @@ +""" +test fix for bug #1672 + +""" + +import os +import compileall + +PACKAGE = "test403" +PYC_GREETER = os.path.join(PACKAGE, "greeter.pyc") +PYCLASS_GREETER = os.path.join(PACKAGE, "greeter$py.class") +PYCLASS_TEST = os.path.join(PACKAGE, "test$py.class") + +def cleanup(): + try: + for f in (PYC_GREETER, PYCLASS_TEST, PYCLASS_GREETER): + os.unlink(f) + except OSError: + pass + + +# setup +cleanup() +open(PYC_GREETER, "a").close() + +# test +compileall.compile_dir(PACKAGE) +print PYCLASS_TEST +print PYCLASS_GREETER +assert os.path.exists(PYCLASS_TEST) +assert os.path.exists(PYCLASS_GREETER) + +# teardown +cleanup() diff --git a/bugtests/test403/greeter.py b/bugtests/test403/greeter.py new file mode 100644 --- /dev/null +++ b/bugtests/test403/greeter.py @@ -0,0 +1,2 @@ +def greet(): + print 'Hello world' diff --git a/bugtests/test403/test.py b/bugtests/test403/test.py new file mode 100644 --- /dev/null +++ b/bugtests/test403/test.py @@ -0,0 +1,3 @@ +from greeter import greet + +greet()