"""
- def __init__(self, dir, file_template=_default_file_template):
+ def __init__(self, dir, file_template=_default_file_template,
+ truncate_slug_length=40):
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
if not os.access(dir, os.F_OK):
raise util.CommandError("Path doesn't exist: %r. Please use "
if script_location is None:
raise util.CommandError("No 'script_location' key "
"found in configuration.")
+ truncate_slug_length = config.get_main_option("truncate_slug_length")
+ if truncate_slug_length is not None:
+ truncate_slug_length = int(truncate_slug_length)
return ScriptDirectory(
util.coerce_resource_to_filename(script_location),
file_template=config.get_main_option(
'file_template',
- _default_file_template)
+ _default_file_template),
+ truncate_slug_length=truncate_slug_length
)
def walk_revisions(self, base="base", head="head"):
def _rev_path(self, rev_id, message, create_date):
slug = "_".join(_slug_re.findall(message or "")).lower()
- if len(slug) > 60:
- slug = slug[:60].rsplit('_', 1)[0] + '_'
+ if len(slug) > self.truncate_slug_length:
+ slug = slug[:self.truncate_slug_length].rsplit('_', 1)[0] + '_'
filename = "%s.py" % (
self.file_template % {
'rev': rev_id,
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
+# max length of characters to apply to the
+# "slug" field
+#truncate_slug_length = 40
+
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
:tags: feature
:pullreq: bitbucket:12
- Expanded the size of the filenames generated by "revision" to 60 characters,
- and also split on the word rather than the character; courtesy
- Frozenball.
+ Expanded the size of the "slug" generated by "revision" to 40
+ characters, which is also configurable by new field
+ ``truncate_slug_length``; and also split on the word rather than the
+ character; courtesy Frozenball.
.. change::
:tags: bug
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
+ # max length of characters to apply to the
+ # "slug" field
+ #truncate_slug_length = 40
+
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
.. versionadded:: 0.3.6 - added date parameters to ``file_template``.
+* ``truncate_slug_length`` - defaults to 40, the max number of characters
+ to include in the "slug" field.
+
+ .. versionadded:: 0.6.1 - added ``truncate_slug_length`` configuration
+
* ``sqlalchemy.url`` - A URL to connect to the database via SQLAlchemy. This key is in fact
only referenced within the ``env.py`` file that is specific to the "generic" configuration;
a file that can be customized by the developer. A multiple
"I'd like it to\nhave\nnewlines")
assert os.access(
os.path.join(env.dir, 'versions',
- '%s_this_is_a_really_long_name_with_lots_of_'
- 'characters_and_also_.py' % rid), os.F_OK)
+ '%s_this_is_a_really_long_name_with_lots_of_.py' % rid),
+ os.F_OK)
+
+
+ def test_009_long_name_configurable(self):
+ env.truncate_slug_length = 60
+ rid = util.rev_id()
+ env.generate_revision(rid,
+ "this is a really long name with "
+ "lots of characters and also "
+ "I'd like it to\nhave\nnewlines")
+ assert os.access(
+ os.path.join(env.dir, 'versions',
+ '%s_this_is_a_really_long_name_with_lots_'
+ 'of_characters_and_also_.py' % rid),
+ os.F_OK)
@classmethod