]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- [feature] script_location can be interpreted
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Feb 2012 05:30:14 +0000 (00:30 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Feb 2012 05:30:14 +0000 (00:30 -0500)
  by pkg_resources.resource_filename(), if
  it is a non-absolute URI that contains
  colons.   This scheme is the same
  one used by Pyramid.  [#29]

CHANGES
alembic/script.py
alembic/util.py
docs/build/conf.py
docs/build/tutorial.rst

diff --git a/CHANGES b/CHANGES
index 6bdca5184c186dac8435bd53fbf9783342b39c22..27945569b175fe566c17644c08ffeeda5d3e4fb8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,12 @@
 - [bug] setup.py won't install argparse if on
   Python 2.7/3.2
 
+- [feature] script_location can be interpreted
+  by pkg_resources.resource_filename(), if
+  it is a non-absolute URI that contains 
+  colons.   This scheme is the same
+  one used by Pyramid.  [#29]
+
 0.2.1
 =====
 - [bug] Fixed the generation of CHECK constraint,
index f9e0224009793656788b043c6c37ba57a3d1b42a..952b572fa4e851ffb06370e81e33371015b38ac0 100644 (file)
@@ -30,7 +30,9 @@ class ScriptDirectory(object):
     @classmethod
     def from_config(cls, config):
         return ScriptDirectory(
-                    config.get_main_option('script_location'),
+                    util.coerce_resource_to_filename(
+                        config.get_main_option('script_location')
+                    ),
                     file_template = config.get_main_option(
                                         'file_template', 
                                         _default_file_template)
index 3ae15f911cb80e18db3832cbb22d6c45f8bfdfd5..3599531d7ac6833c2a76fdd972dfcb3295ec73e2 100644 (file)
@@ -111,6 +111,18 @@ def create_module_class_proxy(cls, globals_, locals_):
             else:
                 attr_names.add(methname)
 
+def coerce_resource_to_filename(fname):
+    """Interpret a filename as either a filesystem location or as a package resource.
+    
+    Names that are non absolute paths and contain a colon
+    are interpreted as resources and coerced to a file location.
+    
+    """
+    if not os.path.isabs(fname) and ":" in fname:
+        import pkg_resources
+        fname = pkg_resources.resource_filename(*fname.split(':'))
+    return fname
+
 def status(_statmsg, fn, *arg, **kw):
     msg(_statmsg + "...", False)
     try:
index 165fa60e30e6371d4550f89349db2d2d3929e4df..44dde4b64f0c6efb543c70d7a3eb1d891a67d66b 100644 (file)
@@ -206,4 +206,6 @@ latex_documents = [
 
 #{'python': ('http://docs.python.org/3.2', None)}
 
-intersphinx_mapping = {'sqla':('http://www.sqlalchemy.org/docs/', None)}
+intersphinx_mapping = {
+    'sqla':('http://www.sqlalchemy.org/docs/', None), 
+}
index c5bee931d409774e397f68fc00eeddd25099b56a..8e47f1be5e49eee6d832b0adaba39eb79208202f 100644 (file)
@@ -114,7 +114,7 @@ The file generated with the "generic" configuration looks like::
 
     [alembic]
     # path to migration scripts
-    script_location = %(here)s/alembic
+    script_location = alembic
 
     # template used to generate migration files
     # file_template = %%(rev)s_%%(slug)s
@@ -165,11 +165,22 @@ This file contains the following features:
 
 * ``[alembic]`` - this is the section read by Alembic to determine configuration.  Alembic
   itself does not directly read any other areas of the file.
-* ``script_location`` - this is the location of the Alembic environment, relative to 
-  the current directory, unless the path is an absolute file path.
+* ``script_location`` - this is the location of the Alembic environment.   It is normally
+  specified as a filesystem location, either relative or absolute.  If the location is 
+  a relative path, it's interpreted as relative to the current directory.
+
   This is the only key required by Alembic in all cases.   The generation 
   of the .ini file by the command ``alembic init alembic`` automatically placed the 
-  directory name ``alembic`` here.
+  directory name ``alembic`` here.   The special variable ``%(here)s`` can also be used,
+  as in ``%(here)s/alembic``.
+
+  For support of applications that package themselves into .egg files, the value can 
+  also be specified
+  as a `package resource <http://packages.python.org/distribute/pkg_resources.html>`_, in which
+  case ``resource_filename()`` is used to find the file (new in 0.2.2).  Any non-absolute
+  URI which contains colons is interpreted here as a resource name, rather than 
+  a straight filename.
+
 * ``file_template`` - this is the naming scheme used to generate new migration files.
   The value present is the default, so is commented out.   The two tokens available
   are ``%%(rev)s`` and ``%%(slug)s``, where ``%%(slug)s`` is a truncated string derived