From: Mike Bayer Date: Fri, 25 Feb 2011 22:14:39 +0000 (-0500) Subject: - pep3147-compatible version of locating .pyc X-Git-Tag: rel_0_1_0~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec365e359acd18ba87388d0eae4a9caf4e4ad59f;p=thirdparty%2Fsqlalchemy%2Falembic.git - pep3147-compatible version of locating .pyc --- diff --git a/alembic/script.py b/alembic/script.py index 41e03cd8..ed075f6b 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -108,8 +108,9 @@ class ScriptDirectory(object): def write(self, rev_id, content): path = self._rev_path(rev_id) open(path, 'w').write(content) - if os.access(path + "c", os.F_OK): - os.unlink(path + "c") + pyc_path = util.pyc_file_from_path(path) + if os.access(pyc_path, os.F_OK): + os.unlink(pyc_path) script = Script.from_path(path) old = self._revision_map[script.revision] if old.down_revision != script.down_revision: diff --git a/alembic/util.py b/alembic/util.py index 59dee9c5..5a598cdf 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -68,6 +68,21 @@ def load_python_file(dir_, filename): del sys.modules[module_id] return module +def pyc_file_from_path(path): + """Given a python source path, locate the .pyc. + + See http://www.python.org/dev/peps/pep-3147/ + #detecting-pep-3147-availability + http://www.python.org/dev/peps/pep-3147/#file-extension-checks + + """ + import imp + has3147 = hasattr(imp, 'get_tag') + if has3147: + return imp.cache_from_source(path) + else: + return path + "c" + def rev_id(): val = int(uuid.uuid4()) % 100000000000000 return hex(val)[2:-1]