Commit b8c64d35 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #951 from renstrom/replace-optparse-with-argparse

Replace optparse with argparse
parents c33ebf92 a062f834
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
on Linux. They no longer pass the socket type or protocol to on Linux. They no longer pass the socket type or protocol to
``getaddrinfo`` when ``connect`` is called. Reported in :issue:`944` ``getaddrinfo`` when ``connect`` is called. Reported in :issue:`944`
by Bernie Hackett. by Bernie Hackett.
- Replace ``optparse`` module with ``argparse``. See :issue:`947`.
1.2.1 (2017-01-12) 1.2.1 (2017-01-12)
================== ==================
......
...@@ -149,25 +149,19 @@ def all_functions(): ...@@ -149,25 +149,19 @@ def all_functions():
if __name__ == '__main__': if __name__ == '__main__':
USAGE = 'USAGE: python %s [--with-kwargs] [--eventlet-hub HUB] %s' % (sys.argv[0], '|'.join(all())) import argparse
if not sys.argv[1:]: parser = argparse.ArgumentParser()
sys.exit(USAGE) parser.add_argument('--with-kwargs', default=False, action='store_true')
import optparse parser.add_argument('--eventlet-hub')
parser = optparse.OptionParser() parser.add_argument('--ignore-import-errors', action='store_true')
parser.add_option('--with-kwargs', default=False, action='store_true') parser.add_argument('benchmark', choices=all() + ['all'])
parser.add_option('--eventlet-hub') options = parser.parse_args()
parser.add_option('--ignore-import-errors', action='store_true')
options, args = parser.parse_args()
if options.with_kwargs: if options.with_kwargs:
options.kwargs = {'foo': 1, 'bar': 'hello'} options.kwargs = {'foo': 1, 'bar': 'hello'}
else: else:
options.kwargs = {} options.kwargs = {}
if len(args) != 1: if options.benchmark == 'all':
sys.exit(USAGE)
if args[0] == 'all':
bench_all(options) bench_all(options)
else: else:
if args[0] not in all(): function = globals()['bench_' + options.benchmark]
sys.exit(USAGE)
function = globals()['bench_' + args[0]]
function(options) function(options)
...@@ -268,17 +268,17 @@ def print_list(lst): ...@@ -268,17 +268,17 @@ def print_list(lst):
def main(): def main():
# FIXME: transition to argparse import argparse
import optparse # pylint:disable=deprecated-module parser = argparse.ArgumentParser()
parser = optparse.OptionParser() parser.add_argument('--ignore')
parser.add_option('--ignore') parser.add_argument('--discover', action='store_true')
parser.add_option('--discover', action='store_true') parser.add_argument('--full', action='store_true')
parser.add_option('--full', action='store_true') parser.add_argument('--config')
parser.add_option('--config') parser.add_argument('--failfast', action='store_true')
parser.add_option('--failfast', action='store_true') parser.add_argument("--coverage", action="store_true")
parser.add_option("--coverage", action="store_true") parser.add_argument("--quiet", action="store_true")
parser.add_option("--quiet", action="store_true") parser.add_argument('tests', nargs='*')
options, args = parser.parse_args() options = parser.parse_args()
FAILING_TESTS = [] FAILING_TESTS = []
coverage = False coverage = False
if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"): if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"):
...@@ -297,7 +297,7 @@ def main(): ...@@ -297,7 +297,7 @@ def main():
config_data = f.read() config_data = f.read()
six.exec_(config_data, config) six.exec_(config_data, config)
FAILING_TESTS = config['FAILING_TESTS'] FAILING_TESTS = config['FAILING_TESTS']
tests = discover(args, options.ignore, coverage) tests = discover(options.tests, options.ignore, coverage)
if options.discover: if options.discover:
for cmd, options in tests: for cmd, options in tests:
print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv'))) print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv')))
......
...@@ -13,7 +13,7 @@ from __future__ import print_function ...@@ -13,7 +13,7 @@ from __future__ import print_function
import sys import sys
import os import os
import glob import glob
import optparse import argparse
from os.path import exists, join, abspath, basename from os.path import exists, join, abspath, basename
from pipes import quote from pipes import quote
...@@ -76,11 +76,10 @@ def _makedist(version=None, dest=None): ...@@ -76,11 +76,10 @@ def _makedist(version=None, dest=None):
def main(): def main():
parser = optparse.OptionParser() parser = argparse.ArgumentParser()
parser.add_option('--dest') parser.add_argument('--dest')
parser.add_option('--version') parser.add_argument('--version')
options, args = parser.parse_args() options = parser.parse_args()
assert not args, 'Expected no arguments'
return makedist(options.version, dest=options.dest) return makedist(options.version, dest=options.dest)
......
...@@ -9,7 +9,7 @@ from __future__ import print_function ...@@ -9,7 +9,7 @@ from __future__ import print_function
import sys import sys
import os import os
import re import re
from optparse import OptionParser from argparse import ArgumentParser
from distutils.version import LooseVersion from distutils.version import LooseVersion
...@@ -132,26 +132,25 @@ def write(filename, data): ...@@ -132,26 +132,25 @@ def write(filename, data):
def main(): def main():
global options global options
parser = OptionParser() parser = ArgumentParser()
parser.add_option('--version', default='dev') parser.add_argument('--version', default='dev')
parser.add_option('--dry-run', action='store_true') parser.add_argument('--dry-run', action='store_true')
options, args = parser.parse_args() parser.add_argument('filename')
assert len(args) == 1, 'One argument is expected, got %s' % len(args) options = parser.parse_args()
version = options.version version = options.version
if version.lower() == 'dev': if version.lower() == 'dev':
version = '' version = ''
if version and strict_version_re.match(version) is None: if version and strict_version_re.match(version) is None:
sys.stderr.write('WARNING: Not a strict version: %r (bdist_msi will fail)' % version) sys.stderr.write('WARNING: Not a strict version: %r (bdist_msi will fail)' % version)
filename = args[0] original_content, new_content = modify_version(options.filename, version)
original_content, new_content = modify_version(filename, version)
if options.dry_run: if options.dry_run:
tmpname = '/tmp/' + os.path.basename(filename) + '.set_version' tmpname = '/tmp/' + os.path.basename(options.filename) + '.set_version'
write(tmpname, new_content) write(tmpname, new_content)
if not os.system('diff -u %s %s' % (filename, tmpname)): if not os.system('diff -u %s %s' % (options.filename, tmpname)):
sys.exit('No differences applied') sys.exit('No differences applied')
else: else:
write(filename, new_content) write(options.filename, new_content)
print('Updated %s' % filename) print('Updated %s' % options.filename)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -4,7 +4,7 @@ Unix utilities must be installed on target machine for this to work: http://unxu ...@@ -4,7 +4,7 @@ Unix utilities must be installed on target machine for this to work: http://unxu
""" """
import sys import sys
import os import os
import optparse import argparse
def system(cmd, exit=True): def system(cmd, exit=True):
...@@ -16,13 +16,15 @@ def system(cmd, exit=True): ...@@ -16,13 +16,15 @@ def system(cmd, exit=True):
return retcode return retcode
parser = optparse.OptionParser() parser = argparse.ArgumentParser()
parser.add_option('--host') parser.add_argument('--host')
parser.add_option('--username', default='Administrator') parser.add_argument('--username', default='Administrator')
parser.add_option('--source') parser.add_argument('--source')
parser.add_option('--dist', action='store_true') parser.add_argument('--dist', action='store_true')
parser.add_option('--python', default='27') parser.add_argument('--python', default='27')
options, args = parser.parse_args() parser.add_argument('args', nargs='*')
options = parser.parse_args()
args = options.args
def prepare(): def prepare():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment