From 7f7db8d99d82333ad5e7a6aeea8b3f70192838a4 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Wed, 29 Aug 2018 11:21:24 +0200 Subject: [PATCH 1/3] Revert #21 to Fix CSV output for python 3 --- athena_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/athena_cli.py b/athena_cli.py index b9f1bca..5260c03 100755 --- a/athena_cli.py +++ b/athena_cli.py @@ -43,13 +43,13 @@ def execute(self, statement): if status == 'SUCCEEDED': results = self.athena.get_query_results(execution_id) - headers = [h['Name'].encode("utf-8") for h in results['ResultSet']['ResultSetMetadata']['ColumnInfo']] + headers = [h['Name'] for h in results['ResultSet']['ResultSetMetadata']['ColumnInfo']] if self.format in ['CSV', 'CSV_HEADER']: csv_writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL) if self.format == 'CSV_HEADER': csv_writer.writerow(headers) - csv_writer.writerows([[text.encode("utf-8") for text in row] for row in self.athena.yield_rows(results, headers)]) + csv_writer.writerows([row for row in self.athena.yield_rows(results, headers)]) elif self.format == 'TSV': print(tabulate([row for row in self.athena.yield_rows(results, headers)], tablefmt='tsv')) elif self.format == 'TSV_HEADER': From 56cbdc4c4c22e6d5e39a03ab5875d982c4850538 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Wed, 29 Aug 2018 12:05:18 +0200 Subject: [PATCH 2/3] Validate output format choices --- athena_cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/athena_cli.py b/athena_cli.py index b9f1bca..b61ad28 100755 --- a/athena_cli.py +++ b/athena_cli.py @@ -349,8 +349,9 @@ def main(): ) parser.add_argument( '--output-format', + choices=('ALIGNED', 'VERTICAL', 'CSV', 'TSV', 'CSV_HEADER', 'TSV_HEADER', 'NULL'), dest='format', - help='output format for batch mode [ALIGNED, VERTICAL, CSV, TSV, CSV_HEADER, TSV_HEADER, NULL]' + help='output format for batch mode' ) parser.add_argument( '--schema', From 142cf0ff06bbd01b75128fb92c5d06ed897190c5 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Fri, 10 May 2019 13:51:31 +0200 Subject: [PATCH 3/3] Update to use Python 3 and other fixes --- .travis.yml | 8 +++++--- NOTICE | 1 + README.md | 1 + athena_cli.py | 8 +------- pypi.md | 7 ------- requirements.txt | 6 +++--- setup.py | 9 +++++---- 7 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 pypi.md diff --git a/.travis.yml b/.travis.yml index 3fa8aab..a41b08d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,13 @@ language: python +cache: pip +dist: xenial python: - - "2.7" - - "3.4" - "3.5" + - "3.6" + - "3.7" install: - - "pip install ." - "pip install -r requirements.txt" + - "pip install ." script: nosetests diff --git a/NOTICE b/NOTICE index fd695d5..a8aee11 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,6 @@ Athena CLI Copyright 2017-2018 Guardian News & Media + Copyright 2019 Nick Satterly Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 876a732..47ba18a 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ License Athena CLI Copyright 2017-2018 Guardian News & Media + Copyright 2019 Nick Satterly Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/athena_cli.py b/athena_cli.py index 02a208d..d675771 100755 --- a/athena_cli.py +++ b/athena_cli.py @@ -64,12 +64,6 @@ def execute(self, statement): if status == 'FAILED': print(stats['QueryExecution']['Status']['StateChangeReason']) -try: - del cmd.Cmd.do_show # "show" is an Athena command -except AttributeError: - # "show" was removed from Cmd2 0.8.0 - pass - class AthenaShell(cmd.Cmd, object): @@ -179,7 +173,7 @@ def do_set(self, arg): super(AthenaShell, self).do_set(arg) def default(self, line): - self.execution_id = self.athena.start_query_execution(self.dbname, line.full_parsed_statement()) + self.execution_id = self.athena.start_query_execution(self.dbname, line.command_and_args) if not self.execution_id: return diff --git a/pypi.md b/pypi.md deleted file mode 100644 index f06fa2d..0000000 --- a/pypi.md +++ /dev/null @@ -1,7 +0,0 @@ -``` -$ python setup.py bdist_wheel --universal -$ twine upload dist/athena_cli-0.0.x-py2.py3-none-any.whl -``` -``` -$ python setup.py sdist bdist_wheel upload -``` diff --git a/requirements.txt b/requirements.txt index 2e3dba5..d132fce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -boto3 -cmd2 -tabulate>=0.8.1 +boto3==1.9.145 +cmd2==0.9.12 +tabulate==0.8.3 diff --git a/setup.py b/setup.py index 29334d9..2f77a76 100644 --- a/setup.py +++ b/setup.py @@ -7,17 +7,17 @@ name="athena-cli", version=version, description='Presto-like CLI for AWS Athena', - url='https://github.com/guardian/athena-cli', + url='https://github.com/satterly/athena-cli', license='Apache License 2.0', author='Nick Satterly', - author_email='nick.satterly@theguardian.com', + author_email='nick.satterly@gmail.com', packages=find_packages(), py_modules=[ 'athena_cli' ], install_requires=[ 'boto3', - 'cmd2', + 'cmd2>=0.9.0.1', 'tabulate>=0.8.1' ], include_package_data=True, @@ -30,5 +30,6 @@ keywords='aws athena presto cli', classifiers=[ 'Topic :: Utilities' - ] + ], + python_requires='>=3.5' )