Skip to content

Commit 68b63f0

Browse files
authored
Merge pull request #2580 from aws/revert-2578-use-python-m-test
Revert "Use python -m to test CLI"
2 parents 1d1b50a + b44eea2 commit 68b63f0

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

awscli/argparser.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,12 @@ def _build(self, command_table, version_string, argument_table):
142142

143143
class ServiceArgParser(CLIArgParser):
144144

145-
def __init__(self, operations_table, service_name, prog=None):
145+
def __init__(self, operations_table, service_name):
146146
super(ServiceArgParser, self).__init__(
147147
formatter_class=argparse.RawTextHelpFormatter,
148148
add_help=False,
149149
conflict_handler='resolve',
150-
usage=USAGE,
151-
prog=prog)
150+
usage=USAGE)
152151
self._build(operations_table)
153152
self._service_name = service_name
154153

@@ -160,16 +159,15 @@ def _build(self, operations_table):
160159
class ArgTableArgParser(CLIArgParser):
161160
"""CLI arg parser based on an argument table."""
162161

163-
def __init__(self, argument_table, command_table=None, prog=None):
162+
def __init__(self, argument_table, command_table=None):
164163
# command_table is an optional subcommand_table. If it's passed
165164
# in, then we'll update the argparse to parse a 'subcommand' argument
166165
# and populate the choices field with the command table keys.
167166
super(ArgTableArgParser, self).__init__(
168167
formatter_class=self.Formatter,
169168
add_help=False,
170169
usage=USAGE,
171-
conflict_handler='resolve',
172-
prog=prog)
170+
conflict_handler='resolve')
173171
if command_table is None:
174172
command_table = {}
175173
self._build(argument_table, command_table)

awscli/clidriver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ def _create_parser(self):
376376
# Also add a 'help' command.
377377
command_table['help'] = self.create_help_command()
378378
return ServiceArgParser(
379-
operations_table=command_table, service_name=self._name,
380-
prog="aws")
379+
operations_table=command_table, service_name=self._name)
381380

382381

383382
class ServiceOperation(object):
@@ -585,7 +584,7 @@ def _emit_first_non_none_response(self, name, **kwargs):
585584
name, **kwargs)
586585

587586
def _create_operation_parser(self, arg_table):
588-
parser = ArgTableArgParser(arg_table, prog="aws")
587+
parser = ArgTableArgParser(arg_table)
589588
return parser
590589

591590

awscli/customizations/commands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ def __call__(self, args, parsed_globals):
135135
".".join(self.lineage_names)
136136
self._session.emit(event, argument_table=self._arg_table, args=args,
137137
session=self._session)
138-
parser = ArgTableArgParser(self.arg_table, self.subcommand_table,
139-
prog="aws")
138+
parser = ArgTableArgParser(self.arg_table, self.subcommand_table)
140139
parsed_args, remaining = parser.parse_known_args(args)
141140

142141
# Unpack arguments

awscli/help.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ def related_items(self):
258258

259259
def __call__(self, args, parsed_globals):
260260
if args:
261-
subcommand_parser = ArgTableArgParser({}, self.subcommand_table,
262-
prog="aws")
261+
subcommand_parser = ArgTableArgParser({}, self.subcommand_table)
263262
parsed, remaining = subcommand_parser.parse_known_args(args)
264263
if getattr(parsed, 'subcommand', None) is not None:
265264
return self.subcommand_table[parsed.subcommand](remaining,

awscli/testutils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import sys
2424
import copy
2525
import shutil
26+
import time
2627
import json
2728
import logging
2829
import tempfile
2930
import platform
3031
import contextlib
32+
import string
3133
import binascii
3234
from pprint import pformat
3335
from subprocess import Popen, PIPE
@@ -118,6 +120,37 @@ def create_clidriver():
118120
return driver
119121

120122

123+
def get_aws_cmd():
124+
global AWS_CMD
125+
import awscli
126+
if AWS_CMD is None:
127+
# Try <repo>/bin/aws
128+
repo_root = os.path.dirname(os.path.abspath(awscli.__file__))
129+
aws_cmd = os.path.join(repo_root, 'bin', 'aws')
130+
if not os.path.isfile(aws_cmd):
131+
aws_cmd = _search_path_for_cmd('aws')
132+
if aws_cmd is None:
133+
raise ValueError('Could not find "aws" executable. Either '
134+
'make sure it is on your PATH, or you can '
135+
'explicitly set this value using '
136+
'"set_aws_cmd()"')
137+
AWS_CMD = aws_cmd
138+
return AWS_CMD
139+
140+
141+
def _search_path_for_cmd(cmd_name):
142+
for path in os.environ.get('PATH', '').split(os.pathsep):
143+
full_cmd_path = os.path.join(path, cmd_name)
144+
if os.path.isfile(full_cmd_path):
145+
return full_cmd_path
146+
return None
147+
148+
149+
def set_aws_cmd(aws_cmd):
150+
global AWS_CMD
151+
AWS_CMD = aws_cmd
152+
153+
121154
@contextlib.contextmanager
122155
def temporary_file(mode):
123156
"""This is a cross platform temporary file creation.
@@ -606,8 +639,11 @@ def aws(command, collect_memory=False, env_vars=None,
606639
"""
607640
if platform.system() == 'Windows':
608641
command = _escape_quotes(command)
609-
module = "awscli" if sys.version_info[:2] >= (2, 7) else "awscli.__main__"
610-
full_command = '%s -m %s %s' % (sys.executable, module, command)
642+
if 'AWS_TEST_COMMAND' in os.environ:
643+
aws_command = os.environ['AWS_TEST_COMMAND']
644+
else:
645+
aws_command = 'python %s' % get_aws_cmd()
646+
full_command = '%s %s' % (aws_command, command)
611647
stdout_encoding = get_stdout_encoding()
612648
if isinstance(full_command, six.text_type) and not six.PY3:
613649
full_command = full_command.encode(stdout_encoding)

0 commit comments

Comments
 (0)