summaryrefslogtreecommitdiff
path: root/alembic
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-10-20 14:24:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-10-20 14:24:41 -0400
commitfd2a172df623650145d99bbe96b3f35bb3dd3ba3 (patch)
tree877f00c0e1b1937188f642fb2342086b3f43a4d9 /alembic
parentd81619b50b9df7ff445884d84d155c01e7b2cbab (diff)
downloadalembic-fd2a172df623650145d99bbe96b3f35bb3dd3ba3.tar.gz
- amending d81619b50b9df7ff4458:
Revision files are now written out using the ``'wb'`` modifier to ``open()``, since Mako reads the templates with ``'rb'``, thus preventing CRs from being doubled up as has been observed on windows. The encoding of the output now defaults to 'utf-8', which can be configured using a newly added config file parameter ``output_encoding``. fixes #234
Diffstat (limited to 'alembic')
-rw-r--r--alembic/script.py7
-rw-r--r--alembic/templates/generic/alembic.ini.mako4
-rw-r--r--alembic/templates/multidb/alembic.ini.mako4
-rw-r--r--alembic/templates/pylons/alembic.ini.mako4
-rw-r--r--alembic/util.py5
5 files changed, 20 insertions, 4 deletions
diff --git a/alembic/script.py b/alembic/script.py
index 6950979..9d33671 100644
--- a/alembic/script.py
+++ b/alembic/script.py
@@ -36,12 +36,13 @@ class ScriptDirectory(object):
def __init__(self, dir, file_template=_default_file_template,
truncate_slug_length=40,
- sourceless=False):
+ sourceless=False, output_encoding="utf-8"):
self.dir = dir
self.versions = os.path.join(self.dir, 'versions')
self.file_template = file_template
self.truncate_slug_length = truncate_slug_length or 40
self.sourceless = sourceless
+ self.output_encoding = output_encoding
if not os.access(dir, os.F_OK):
raise util.CommandError("Path doesn't exist: %r. Please use "
@@ -70,7 +71,8 @@ class ScriptDirectory(object):
'file_template',
_default_file_template),
truncate_slug_length=truncate_slug_length,
- sourceless=config.get_main_option("sourceless") == "true"
+ sourceless=config.get_main_option("sourceless") == "true",
+ output_encoding=config.get_main_option("output_encoding", "utf-8")
)
def walk_revisions(self, base="base", head="head"):
@@ -319,6 +321,7 @@ class ScriptDirectory(object):
util.template_to_file,
src,
dest,
+ self.output_encoding,
**kw
)
diff --git a/alembic/templates/generic/alembic.ini.mako b/alembic/templates/generic/alembic.ini.mako
index a738a24..90037d7 100644
--- a/alembic/templates/generic/alembic.ini.mako
+++ b/alembic/templates/generic/alembic.ini.mako
@@ -20,6 +20,10 @@ script_location = ${script_location}
# versions/ directory
# sourceless = false
+# the output encoding used when revision files
+# are written from script.py.mako
+# output_encoding = utf-8
+
sqlalchemy.url = driver://user:pass@localhost/dbname
diff --git a/alembic/templates/multidb/alembic.ini.mako b/alembic/templates/multidb/alembic.ini.mako
index 132b246..ced3558 100644
--- a/alembic/templates/multidb/alembic.ini.mako
+++ b/alembic/templates/multidb/alembic.ini.mako
@@ -20,6 +20,10 @@ script_location = ${script_location}
# versions/ directory
# sourceless = false
+# the output encoding used when revision files
+# are written from script.py.mako
+# output_encoding = utf-8
+
databases = engine1, engine2
[engine1]
diff --git a/alembic/templates/pylons/alembic.ini.mako b/alembic/templates/pylons/alembic.ini.mako
index 771c027..6a5f206 100644
--- a/alembic/templates/pylons/alembic.ini.mako
+++ b/alembic/templates/pylons/alembic.ini.mako
@@ -20,6 +20,10 @@ script_location = ${script_location}
# versions/ directory
# sourceless = false
+# the output encoding used when revision files
+# are written from script.py.mako
+# output_encoding = utf-8
+
pylons_config_file = ./development.ini
# that's it ! \ No newline at end of file
diff --git a/alembic/util.py b/alembic/util.py
index 9d48ffb..d261d09 100644
--- a/alembic/util.py
+++ b/alembic/util.py
@@ -57,10 +57,11 @@ except (ImportError, IOError):
TERMWIDTH = None
-def template_to_file(template_file, dest, **kw):
+def template_to_file(template_file, dest, output_encoding, **kw):
with open(dest, 'wb') as f:
+ template = Template(filename=template_file)
f.write(
- Template(filename=template_file).render(**kw)
+ template.render_unicode(**kw).encode(output_encoding)
)