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 "
'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"):
util.template_to_file,
src,
dest,
+ self.output_encoding,
**kw
)
# 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
# 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]
# 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
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)
)
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.
+ 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``.
.. change::
:tags: bug, operations
# 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
# Logging configuration
.. versionadded:: 0.6.4
+* ``output_encoding`` - the encoding to use when Alembic writes the
+ ``script.py.mako`` file into a new migration file. Defaults to ``'utf-8'``.
+
+ .. versionadded:: 0.7.0
+
* ``[loggers]``, ``[handlers]``, ``[formatters]``, ``[logger_*]``, ``[handler_*]``,
``[formatter_*]`` - these sections are all part of Python's standard logging configuration,
the mechanics of which are documented at `Configuration File Format <http://docs.python.org/library/logging.config.html#configuration-file-format>`_.
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
class ConfigTest(TestBase):
)
-class OutputEncodingTest(TestBase):
+class StdoutOutputEncodingTest(TestBase):
def test_plain(self):
stdout = Mock(encoding='latin-1')
stdout.mock_calls,
[call.write('m?il x y'), call.write('\n')]
)
+
+
+class TemplateOutputEncodingTest(TestBase):
+ def setUp(self):
+ staging_env()
+ self.cfg = _no_sql_testing_config()
+
+ def tearDown(self):
+ clear_staging_env()
+
+ def test_default(self):
+ script = ScriptDirectory.from_config(self.cfg)
+ eq_(script.output_encoding, 'utf-8')
+
+ def test_setting(self):
+ self.cfg.set_main_option('output_encoding', 'latin-1')
+ script = ScriptDirectory.from_config(self.cfg)
+ eq_(script.output_encoding, 'latin-1')