mixxorz / behave-django

Behave BDD integration for Django
https://pythonhosted.org/behave-django/
38 stars 5 forks source link

switch from optparse to argparse #24

Closed nikolas closed 8 years ago

nikolas commented 9 years ago

I noticed behave.py uses optparse.. I think we should switch to argparse as it's better supported.

From https://docs.python.org/2/library/optparse.html

Deprecated since version 2.7: The optparse module is deprecated and will not be developed further; development will continue with the argparse module.

I'll try to make a PR for this at some point, unless you get to it before I do.

bittner commented 9 years ago

@nikolas, just a few hints to get you started, if you don't mind:

try:
    from argparse import ArgumentParser  # New since Python 2.7
    parser = ArgumentParser()
except ImportError:
    from optparse import OptionParser  # Deprecated since Python 2.7
    parser = OptionParser()
    parser.add_argument = parser.add_option  # use add_argument in any case

parser.add_argument('foo', help='foo does bar and baz')

# ... and a similar try-except block for the actual parsing and evaluation
nikolas commented 9 years ago

@bittner thanks for the tips!

bittner commented 9 years ago

Another note: I just see, until Django 1.7 optparse's make_option is used for the option_list. The implementation of our management command pretty much depends on that. Django 1.8 makes the switch finally to argparse. I fear an implementation change on our side will probably have to follow their approach and may need to consider the Django version in use.

See Also

oiwn commented 8 years ago

This deprecation warning is a bit annoying. Any news?

bittner commented 8 years ago

This affects

Anything else?

What is the exact deprecation warning, and when does it occur? (I don't notice any with Python 3.4 and Django 1.8)

bittner commented 8 years ago

@mixxorz We should address this deprecation warning now that we're under the hood of the behave organization. As more and more developers start using Django 1.9 this issue becomes more visible.

bittner commented 8 years ago

Closing this issue in favor of issue 2 in behave/behave-django. Please follow-up there.