1. Michael Bayer
  2. alembic
  3. Issues


Issue #43 resolved

remove the print staments in alembic.command

miniwark NA
created an issue

alembic.command use a few print commands to display command results. For example in current function.

If i try to use command.current in another script the version is always printed in the console.

Example script : {{{


from alembic.config import Config from alembic import command

alembic_cfg = Config('alembic.ini') version = command.current(alembic_cfg) if version: ... }}}

This will effectively get the requested version but also print the version with may not be wanted in another script.

suggestion : return a string instead instead of using print

Comments (6)

  1. Michael Bayer repo owner

    this is true that the informational commands are oriented towards being run in a console. If you want to get the current version, do this:

    from alembic.migration import MigrationContext
    connection = bind.connect()
    ctx = MigrationContext.configure(connection)
    db_head = ctx.get_current_revision()

    I don't know how alembic.command could itself be changed without pushing the print statements and message formatting somewhere else. The command-line version of the tasks have to be somewhere, and that's what the "command" package is for. And I definitely wouldn't want to promote the API usage as, " to get the current version, run comand.current(), get the return value as a string, then use a regexp to pull out the number from the middle of the message". command.current is just not oriented towards API usage.

    so perhaps the issue here is even promoting alembic.command as public.

  2. miniwark NA reporter

    I was just in need of the revision number, i see now than this can simply be done by using directly


    You then can probably close this one as "WontFix" bug.

  3. Log in to comment