]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
The output of the ``alembic history`` command is now
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 26 Jun 2013 21:08:32 +0000 (17:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 26 Jun 2013 21:08:32 +0000 (17:08 -0400)
expanded to show information about each change on multiple
lines, including the full top message,
resembling the formatting of git log.

alembic/command.py
alembic/script.py
docs/build/changelog.rst
docs/build/front.rst
tests/test_command.py

index 898f4c995cbfb5a91df68ba20afeb11763341a37..095d041f5b219fd99e08da9d742ccfc862471734 100644 (file)
@@ -168,7 +168,7 @@ def history(config, rev_range=None):
                                 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):
index 637a749ee0b4000724499d94bf7acda1ba47065e..f0903266f0534edb767e8373e041a50027f83232 100644 (file)
@@ -2,7 +2,6 @@ import datetime
 import os
 import re
 import shutil
-
 from . import util
 
 _rev_file = re.compile(r'.*\.py$')
@@ -377,8 +376,18 @@ class Script(object):
     @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])
@@ -406,6 +415,24 @@ class Script(object):
         """
         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,
index ec5beba3f777a26f8a8410960e53d88a209f4fc7..bc39aea28788cf20039967c87e6667a78273bd61 100644 (file)
@@ -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
index 26be21b02b20b86c286a03210e087376306e984f..3270f5ce32a7cd1d56b67f8f18a90667a5276ac1 100644 (file)
@@ -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.
 
index 36bcc663ac650089a82f4d1ec06f922556d0dc03..34f57856e19425b121173e85f57a073cb3635c6e 100644 (file)
@@ -4,6 +4,9 @@ from . import clear_staging_env, staging_env, \
     three_rev_fixture, eq_
 from alembic import command
 from io import StringIO
+from alembic.script import ScriptDirectory
+
+
 
 class StdoutCommandTest(unittest.TestCase):
 
@@ -18,74 +21,52 @@ class StdoutCommandTest(unittest.TestCase):
         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])