Skip to content

Commit 0a774bc

Browse files
committed
Support installing EBCLI from source
This will be useful during testing specific commits/development versions of the package
1 parent d9e6d75 commit 0a774bc

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

scripts/ebcli_installer.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ def _exec_cmd(args):
198198
YELLOW_COLOR_CODE = 11
199199

200200

201+
class ArgumentError(Exception):
202+
pass
203+
204+
201205
class Step(object):
202206
"""
203207
Class labels an installation Step and is expected to be invoked as
@@ -318,9 +322,24 @@ def _announce_success(virtualenv_location):
318322

319323

320324
def _print_in_foreground(message, color_number):
325+
"""
326+
Function prints a given `message` on the terminal in the foreground. `color_number`
327+
is a number between and including 0 and 255. FOr a list of color codes see:
328+
329+
https://misc.flogisoft.com/bash/tip_colors_and_formatting#background1
330+
331+
On Windows, `color_number` is rejected, and hence not used. At present, PowerShell
332+
is able to recognize ANSI/VT100 escape sequences, however, CMD prompt is not.
333+
334+
:param message: a string to print in the foreground on the terminal
335+
:param color_number: an integer between and including 0 and 255 representing
336+
a color
337+
:return: None
338+
"""
321339
if sys.platform.startswith('win32'):
322340
print(message)
323341
else:
342+
# Courtesy https://misc.flogisoft.com/bash/tip_colors_and_formatting
324343
print(
325344
"\033[38;5;{color_number}m{message}\033[0m".format(
326345
color_number=color_number,
@@ -456,17 +475,23 @@ def _generate_ebcli_wrappers(virtualenv_location):
456475

457476

458477
@Step('Installing EBCLI')
459-
def _install_ebcli(quiet, version):
478+
def _install_ebcli(quiet, version, ebcli_source):
460479
"""
461480
Function installs the awsebcli presumably within the virtualenv,
462481
".ebcli-virtual-env", created and activated by this script apriori.
463482
If `version` is passed, the specific version of the EBCLI is installed.
483+
484+
The presence of `version` and `ebcli_source` will lead to an exception
485+
as they represent two different ways of installing the EBCLI.
486+
464487
:param quiet: whether to display the output of awsebcli installation to
465488
the terminal or not
466489
:param version: the specific version of awsebcli to install
467490
:return None
468491
"""
469-
if version:
492+
if ebcli_source:
493+
install_args = ['pip', 'install', '{}'.format(ebcli_source.strip())]
494+
elif version:
470495
install_args = ['pip', 'install', 'awsebcli=={}'.format(version.strip())]
471496
else:
472497
install_args = [
@@ -649,11 +674,24 @@ def _parse_arguments():
649674
action='store_true',
650675
help='enable quiet mode to display only minimal, necessary output'
651676
)
677+
parser.add_argument(
678+
'-s', '--ebcli-source',
679+
help='filesystem path to a Git repository of the EBCLI, or a .zip or .tar file of '
680+
'the EBCLI source code; useful when testing a development version of the EBCLI.'
681+
)
652682
parser.add_argument(
653683
'-v', '--version',
654684
help='version of EBCLI to install'
655685
)
656-
return parser.parse_args()
686+
687+
arguments = parser.parse_args()
688+
689+
if arguments.version and arguments.ebcli_source:
690+
raise ArgumentError(
691+
'"--version" and "--ebcli-source" cannot be used together '
692+
'because they represent two distinct sources of the EBCLI.'
693+
)
694+
return arguments
657695

658696

659697
def _pip_executable_found(quiet):
@@ -723,6 +761,10 @@ def _python_script_body(virtualenv_location):
723761
arguments_context.quiet
724762
)
725763
_activate_virtualenv(virtualenv_location)
726-
_install_ebcli(arguments_context.quiet, arguments_context.version)
764+
_install_ebcli(
765+
arguments_context.quiet,
766+
arguments_context.version,
767+
arguments_context.ebcli_source
768+
)
727769
_generate_ebcli_wrappers(virtualenv_location)
728770
_announce_success(virtualenv_location)

0 commit comments

Comments
 (0)