]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- changelog + some polish
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Nov 2014 17:43:54 +0000 (12:43 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Nov 2014 17:43:54 +0000 (12:43 -0500)
alembic/config.py
docs/build/changelog.rst
tests/test_config.py

index 30f3d79bd339cb93320c660ce681124990201772..b29a888a14c9935171c118546c99292d5443f411 100644 (file)
@@ -52,12 +52,20 @@ class Config(object):
      ..versionadded:: 0.4
 
     :param config_args: A dictionary of keys and values that will be used
-    for substitution in the alembic config file.
+     for substitution in the alembic config file.  The dictionary as given
+     is **copied** to a new one, stored locally as the attribute
+     ``.config_args``. When the :attr:`.Config.file_config` attribute is
+     first invoked, the replacement variable ``here`` will be added to this
+     dictionary before the dictionary is passed to ``SafeConfigParser()``
+     to parse the .ini file.
+
+     ..versionadded:: 0.7.0
 
     """
 
     def __init__(self, file_=None, ini_section='alembic', output_buffer=None,
-                 stdout=sys.stdout, cmd_opts=None, config_args = {}):
+                 stdout=sys.stdout, cmd_opts=None,
+                 config_args=util.immutabledict()):
         """Construct a new :class:`.Config`
 
         """
@@ -66,7 +74,7 @@ class Config(object):
         self.output_buffer = output_buffer
         self.stdout = stdout
         self.cmd_opts = cmd_opts
-        self.config_args = config_args
+        self.config_args = dict(config_args)
 
     cmd_opts = None
     """The command-line options passed to the ``alembic`` script.
index c188605d15a1036d34c4aa99244f1e7aa3260192..74a9fa23a66a7ac20584f7f48825c036d5e973c3 100644 (file)
@@ -5,11 +5,20 @@ Changelog
 .. changelog::
     :version: 0.7.0
 
+    .. change::
+      :tags: feature, config
+      :pullreq: bitbucket:33
+
+      Added new argument :paramref:`.Config.config_args`, allows a dictionary
+      of replacement variables to be passed which will serve as substitution
+      values when an API-produced :class:`.Config` consumes the ``.ini``
+      file.  Pull request courtesy Noufal Ibrahim.
+
     .. change::
       :tags: bug, oracle
       :tickets: 245
 
-      The Oracle dialect sets "transactional DDL" to False by default, 
+      The Oracle dialect sets "transactional DDL" to False by default,
       as Oracle does not support transactional DDL.
 
     .. change::
index c8259bd94050257dacaf32fa99a31b10ee093169..2d8f964cd2f9ebae32473dde20e9fa2f5ce6ee5d 100644 (file)
@@ -13,21 +13,27 @@ from alembic.testing.mock import Mock, call
 from alembic.testing import eq_, assert_raises_message
 from alembic.testing.fixtures import capture_db
 from alembic.testing.env import _no_sql_testing_config, clear_staging_env,\
-    staging_env
+    staging_env, _write_config_file
 
 
-class ConfigTest(TestBase):
+class FileConfigTest(TestBase):
     def test_config_args(self):
-        config_file = tempfile.mktemp()
-        with open(config_file, "w") as fp:
-            fp.write("""
+        cfg = _write_config_file("""
 [alembic]
 migrations = %(base_path)s/db/migrations
 """)
-        cfg = config.Config(config_file, config_args=dict(base_path = "/home/alembic"))
-        eq_(cfg.get_section_option("alembic", "migrations"), "/home/alembic/db/migrations")
-        print config_file
-        os.unlink(config_file)
+        test_cfg = config.Config(
+            cfg.config_file_name, config_args=dict(base_path="/home/alembic")
+        )
+        eq_(
+            test_cfg.get_section_option("alembic", "migrations"),
+            "/home/alembic/db/migrations")
+
+    def tearDown(self):
+        clear_staging_env()
+
+
+class ConfigTest(TestBase):
 
     def test_config_no_file_main_option(self):
         cfg = config.Config()