Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the print staments in alembic.command #43

Closed
sqlalchemy-bot opened this issue Apr 25, 2012 · 7 comments
Closed

remove the print staments in alembic.command #43

sqlalchemy-bot opened this issue Apr 25, 2012 · 7 comments
Labels

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by miniwark NA (@miniwark)

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 :

#!python

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

@sqlalchemy-bot
Copy link
Author

Changes by miniwark NA (@miniwark):

  • edited description

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

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:

#!python

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.

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • removed labels: easy

@sqlalchemy-bot
Copy link
Author

miniwark NA (@miniwark) wrote:

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

#!python
ScriptDirectory.get_current_head()

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

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

OK, well I made an easy enough change in 9bff65f so that at least the redirection of "print" can be done easily via the Config object, which now accepts a "stdout" parameter.

But yes, to get the current version and such, you should still use the non-command API :).

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Author

miniwark NA (@miniwark) wrote:

Thanks for the good work !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant