Skip to content

Commit

Permalink
The output of the alembic history command is now
Browse files Browse the repository at this point in the history
expanded to show information about each change on multiple
lines, including the full top message,
resembling the formatting of git log.
  • Loading branch information
zzzeek committed Jun 26, 2013
1 parent 8a9ab5e commit a381c8f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
2 changes: 1 addition & 1 deletion alembic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _display_history(config, script, base, head):
head=head or "head"):
if sc.is_head:
config.print_stdout("")
config.print_stdout(sc)
config.print_stdout(sc.log_entry)

def _display_history_w_current(config, script, base=None, head=None):
def _display_current_history(rev, context):
Expand Down
33 changes: 30 additions & 3 deletions alembic/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import re
import shutil

from . import util

_rev_file = re.compile(r'.*\.py$')
Expand Down Expand Up @@ -377,8 +376,18 @@ def __init__(self, module, rev_id, path):
@property
def doc(self):
"""Return the docstring given in the script."""
if self.module.__doc__:
return re.split(r"\n\n", self.module.__doc__)[0]

return re.split("\n\n", self.longdoc)[0]

@property
def longdoc(self):
"""Return the docstring given in the script."""

doc = self.module.__doc__
if doc:
return doc.strip()
else:
return ""

def add_nextrev(self, rev):
self.nextrev = self.nextrev.union([rev])
Expand Down Expand Up @@ -406,6 +415,24 @@ def is_branch_point(self):
"""
return len(self.nextrev) > 1

@property
def log_entry(self):
return \
"Rev: %s%s%s\n" \
"Parent: %s\n" \
"Path: %s\n" \
"\n%s\n" % (
self.revision,
" (head)" if self.is_head else "",
" (branchpoint)" if self.is_branch_point else "",
self.down_revision,
self.path,
"\n".join(
" %s" % para
for para in self.longdoc.splitlines()
)
)

def __str__(self):
return "%s -> %s%s%s, %s" % (
self.down_revision,
Expand Down
9 changes: 9 additions & 0 deletions docs/build/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Changelog

.. changelog::
:version: 0.6.0
:released:

.. change::
:tags: feature

The output of the ``alembic history`` command is now
expanded to show information about each change on multiple
lines, including the full top message,
resembling the formatting of git log.

.. change::
:tags: feature
Expand Down
2 changes: 1 addition & 1 deletion docs/build/front.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Dependencies
Alembic's install process will ensure that `SQLAlchemy <http://www.sqlalchemy.org>`_
is installed, in addition to other dependencies. Alembic will work with
SQLAlchemy as of version **0.7.3**. The latest version of SQLAlchemy within
the **0.7** or **0.8** series is strongly recommended.
the **0.7**, **0.8**, or more recent series is strongly recommended.

Alembic supports Python versions 2.6 and above.

Expand Down
49 changes: 15 additions & 34 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
three_rev_fixture, eq_
from alembic import command
from io import StringIO
from alembic.script import ScriptDirectory



class StdoutCommandTest(unittest.TestCase):

Expand All @@ -18,74 +21,52 @@ def teardown_class(cls):
clear_staging_env()

def _eq_cmd_output(self, buf, expected):
script = ScriptDirectory.from_config(self.cfg)

revs = {"reva": self.a, "revb": self.b, "revc": self.c}
eq_(
[s for s in buf.getvalue().split("\n") if s],
[exp % revs for exp in expected]
buf.getvalue().strip(),
"\n".join([script.get_revision(rev).log_entry for rev in expected]).strip()
)

def test_history_full(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg)
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
'%(reva)s -> %(revb)s, Rev B',
'None -> %(reva)s, Rev A'
])
self._eq_cmd_output(buf, [self.c, self.b, self.a])

def test_history_num_range(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "%s:%s" % (self.a, self.b))
self._eq_cmd_output(buf, [
'%(reva)s -> %(revb)s, Rev B',
])
self._eq_cmd_output(buf, [self.b])

def test_history_base_to_num(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, ":%s" % (self.b))
self._eq_cmd_output(buf, [
'%(reva)s -> %(revb)s, Rev B',
'None -> %(reva)s, Rev A'
])
self._eq_cmd_output(buf, [self.b, self.a])

def test_history_num_to_head(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "%s:" % (self.a))
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
'%(reva)s -> %(revb)s, Rev B',
])
self._eq_cmd_output(buf, [self.c, self.b])

def test_history_num_plus_relative(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "%s:+2" % (self.a))
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
'%(reva)s -> %(revb)s, Rev B',
])
self._eq_cmd_output(buf, [self.c, self.b])

def test_history_relative_to_num(self):
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "-2:%s" % (self.c))
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
'%(reva)s -> %(revb)s, Rev B',
])
self._eq_cmd_output(buf, [self.c, self.b])

def test_history_current_to_head_as_b(self):
command.stamp(self.cfg, self.b)
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "current:")
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
])
self._eq_cmd_output(buf, [self.c])

def test_history_current_to_head_as_base(self):
command.stamp(self.cfg, "base")
self.cfg.stdout = buf = StringIO()
command.history(self.cfg, "current:")
self._eq_cmd_output(buf, [
'%(revb)s -> %(revc)s (head), Rev C',
'%(reva)s -> %(revb)s, Rev B',
'None -> %(reva)s, Rev A'
])
self._eq_cmd_output(buf, [self.c, self.b, self.a])

0 comments on commit a381c8f

Please sign in to comment.