]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- pep3147-compatible version of locating .pyc
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Feb 2011 22:14:39 +0000 (17:14 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 25 Feb 2011 22:14:39 +0000 (17:14 -0500)
alembic/script.py
alembic/util.py

index 41e03cd8bb1b8f223b498d5410cb5719ec2a6bc5..ed075f6b3e40b3de3a8cc7b8c9c907a4d8a8f71b 100644 (file)
@@ -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:
index 59dee9c53155c6202c865cc83948ddd4dc10c54a..5a598cdf491dc4deb7a9ca9cfdbf0fe4ae776621 100644 (file)
@@ -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]