From 7ca03e362c601034d2aa090b8221593b6cb41dfe Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Thu, 7 May 2020 17:12:42 -0700 Subject: [PATCH] updated naming; created folder for release notes --- README.md | 2 +- development_guide.md | 2 +- .../release-notes-odfe-sql-cli-1.7.0.0.md | 2 +- setup.py | 11 +++++------ {odfesql_cli => src}/__init__.py | 0 {odfesql_cli => src}/conf/__init__.py | 0 {odfesql_cli => src}/conf/clirc | 0 {odfesql_cli => src}/config.py | 4 ++-- {odfesql_cli => src}/esbuffer.py | 0 {odfesql_cli => src}/esconnection.py | 0 {odfesql_cli => src}/esliterals/__init__.py | 0 {odfesql_cli => src}/esliterals/esliterals.json | 0 {odfesql_cli => src}/esstyle.py | 0 {odfesql_cli => src}/formatter.py | 0 {odfesql_cli => src}/main.py | 0 {odfesql_cli => src}/odfesql_cli.py | 4 ++-- {odfesql_cli => src}/utils.py | 0 tests/conftest.py | 2 +- tests/test_config.py | 2 +- tests/test_esconnection.py | 8 ++++---- tests/test_formatter.py | 12 ++++++------ tests/test_main.py | 6 +++--- tests/test_odfesql_cli.py | 8 ++++---- tests/utils.py | 6 +++--- 24 files changed, 34 insertions(+), 35 deletions(-) rename opendistro-elasticsearch-sql-cli.release-notes.md => release-notes/release-notes-odfe-sql-cli-1.7.0.0.md (86%) rename {odfesql_cli => src}/__init__.py (100%) rename {odfesql_cli => src}/conf/__init__.py (100%) rename {odfesql_cli => src}/conf/clirc (100%) rename {odfesql_cli => src}/config.py (96%) rename {odfesql_cli => src}/esbuffer.py (100%) rename {odfesql_cli => src}/esconnection.py (100%) rename {odfesql_cli => src}/esliterals/__init__.py (100%) rename {odfesql_cli => src}/esliterals/esliterals.json (100%) rename {odfesql_cli => src}/esstyle.py (100%) rename {odfesql_cli => src}/formatter.py (100%) rename {odfesql_cli => src}/main.py (100%) rename {odfesql_cli => src}/odfesql_cli.py (98%) rename {odfesql_cli => src}/utils.py (100%) diff --git a/README.md b/README.md index bf37b2a..bd617e8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ endpoint such as AWS Elasticsearch. ## Configuration - A config file is automatically created at `~/.config/odfesql-cli/config` at first launch (for MacOS and Linux). -Check out [clirc](./odfesql_cli/conf/clirc) for details of all available configurations. +Check out [clirc](src/conf/clirc) for details of all available configurations. - It can be configured and will be auto-loaded next time. ## Features diff --git a/development_guide.md b/development_guide.md index 3b4488a..9e42259 100644 --- a/development_guide.md +++ b/development_guide.md @@ -33,7 +33,7 @@ any endpoint, it uses http://localhost:9200 by default. ### Workflow 1. Update version number - 1. Modify the version number in `_init_.py` under `odfesql_cli` package. It will be used by `setup.py` for release. + 1. Modify the version number in `_init_.py` under `src` package. It will be used by `setup.py` for release. 2. Create/Update `setup.py` (if needed) 1. For more details refer to https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py 3. Update README.md, Legal and copyright files(if needed) diff --git a/opendistro-elasticsearch-sql-cli.release-notes.md b/release-notes/release-notes-odfe-sql-cli-1.7.0.0.md similarity index 86% rename from opendistro-elasticsearch-sql-cli.release-notes.md rename to release-notes/release-notes-odfe-sql-cli-1.7.0.0.md index 0b2cec6..7656fd3 100644 --- a/opendistro-elasticsearch-sql-cli.release-notes.md +++ b/release-notes/release-notes-odfe-sql-cli-1.7.0.0.md @@ -2,7 +2,7 @@ ### New Features -This is the first official release of Open Distro Elasticsearch SQL CLI +This is the first official release of Open Distro for Elasticsearch SQL CLI ODFE SQL CLI is a stand alone Python application and can be launched by a wake word `odfesql`. It serves as a support only for [Open Distro SQL plugin for Elasticsearch](https://opendistro.github.io/for-elasticsearch-docs/docs/sql/). User must have ODFE SQL diff --git a/setup.py b/setup.py index 1989924..4998cc3 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ _version_re = re.compile(r"__version__\s+=\s+(.*)") -with open("odfesql_cli/__init__.py", "rb") as f: +with open("src/__init__.py", "rb") as f: version = str( ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)) ) @@ -42,24 +42,23 @@ setup( name="odfesql", - author="Zhongnan", - author_email="zhongnan.su@outlook.com", + author="Zhongnan Su", + author_email="szhongna@amazon.com", version=version, license="Apache 2.0", url="https://opendistro.github.io/for-elasticsearch-docs/", packages=find_packages(), - package_data={"odfesql_cli": ["conf/clirc", "esliterals/esliterals.json"]}, + package_data={"src": ["conf/clirc", "esliterals/esliterals.json"]}, description=description, long_description=long_description, long_description_content_type="text/markdown", install_requires=install_requirements, - entry_points={"console_scripts": ["odfesql=odfesql_cli.main:cli"]}, + entry_points={"console_scripts": ["odfesql=src.main:cli"]}, classifiers=[ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: Unix", "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", diff --git a/odfesql_cli/__init__.py b/src/__init__.py similarity index 100% rename from odfesql_cli/__init__.py rename to src/__init__.py diff --git a/odfesql_cli/conf/__init__.py b/src/conf/__init__.py similarity index 100% rename from odfesql_cli/conf/__init__.py rename to src/conf/__init__.py diff --git a/odfesql_cli/conf/clirc b/src/conf/clirc similarity index 100% rename from odfesql_cli/conf/clirc rename to src/conf/clirc diff --git a/odfesql_cli/config.py b/src/config.py similarity index 96% rename from odfesql_cli/config.py rename to src/config.py index a68087c..0ee015c 100644 --- a/odfesql_cli/config.py +++ b/src/config.py @@ -68,12 +68,12 @@ def _write_default_config(source, destination, overwrite=False): # https://stackoverflow.com/questions/40193112/python-setuptools-distribute-configuration-files-to-os-specific-directories def get_config(clirc_file=None): """ - Get config for odfesql_cli. + Get config for odfesql cli. This config comes from either existing config in the OS, or create a config file in the OS, and write default config including in the package to it. """ - from odfesql_cli.conf import __file__ as package_root + from src.conf import __file__ as package_root package_root = os.path.dirname(package_root) diff --git a/odfesql_cli/esbuffer.py b/src/esbuffer.py similarity index 100% rename from odfesql_cli/esbuffer.py rename to src/esbuffer.py diff --git a/odfesql_cli/esconnection.py b/src/esconnection.py similarity index 100% rename from odfesql_cli/esconnection.py rename to src/esconnection.py diff --git a/odfesql_cli/esliterals/__init__.py b/src/esliterals/__init__.py similarity index 100% rename from odfesql_cli/esliterals/__init__.py rename to src/esliterals/__init__.py diff --git a/odfesql_cli/esliterals/esliterals.json b/src/esliterals/esliterals.json similarity index 100% rename from odfesql_cli/esliterals/esliterals.json rename to src/esliterals/esliterals.json diff --git a/odfesql_cli/esstyle.py b/src/esstyle.py similarity index 100% rename from odfesql_cli/esstyle.py rename to src/esstyle.py diff --git a/odfesql_cli/formatter.py b/src/formatter.py similarity index 100% rename from odfesql_cli/formatter.py rename to src/formatter.py diff --git a/odfesql_cli/main.py b/src/main.py similarity index 100% rename from odfesql_cli/main.py rename to src/main.py diff --git a/odfesql_cli/odfesql_cli.py b/src/odfesql_cli.py similarity index 98% rename from odfesql_cli/odfesql_cli.py rename to src/odfesql_cli.py index 90299cf..6818956 100644 --- a/odfesql_cli/odfesql_cli.py +++ b/src/odfesql_cli.py @@ -63,7 +63,7 @@ def __init__(self, clirc_file=None, always_use_pager=False, use_aws_authenticati self.table_format = config["main"]["table_format"] self.multiline_continuation_char = config["main"]["multiline_continuation_char"] self.multi_line = config["main"].as_bool("multi_line") - self.multiline_mode = config["main"].get("multi_line_mode", "odfesql_cli") + self.multiline_mode = config["main"].get("multi_line_mode", "src") self.null_string = config["main"].get("null_string", "null") self.style_output = style_factory_output(self.syntax_style, self.cli_style) @@ -174,7 +174,7 @@ def _get_literals(self): :return: a dict that is parsed from esliterals.json """ - from odfesql_cli.esliterals import __file__ as package_root + from src.esliterals import __file__ as package_root package_root = os.path.dirname(package_root) diff --git a/odfesql_cli/utils.py b/src/utils.py similarity index 100% rename from odfesql_cli/utils.py rename to src/utils.py diff --git a/tests/conftest.py b/tests/conftest.py index d66f914..1613a60 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,7 +34,7 @@ def connection(): @pytest.fixture(scope="function") def default_config_location(): - from odfesql_cli.conf import __file__ as package_root + from src.conf import __file__ as package_root package_root = os.path.dirname(package_root) default_config = os.path.join(package_root, "clirc") diff --git a/tests/test_config.py b/tests/test_config.py index b2578c0..116703e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -16,7 +16,7 @@ import stat import pytest -from odfesql_cli.config import ensure_dir_exists +from src.config import ensure_dir_exists class TestConfig: diff --git a/tests/test_esconnection.py b/tests/test_esconnection.py index 3709547..165dfa1 100644 --- a/tests/test_esconnection.py +++ b/tests/test_esconnection.py @@ -20,7 +20,7 @@ from elasticsearch import Elasticsearch, RequestsHttpConnection from utils import estest, load_data, run, TEST_INDEX_NAME -from odfesql_cli.esconnection import ESConnection +from src.esconnection import ESConnection INVALID_ENDPOINT = "http://invalid:9200" OPEN_DISTRO_ENDPOINT = "https://opedistro:9200" @@ -59,7 +59,7 @@ def test_query_nonexistent_index(self, connection): "type": "IndexNotFoundException", } - with mock.patch("odfesql_cli.esconnection.click.secho") as mock_secho: + with mock.patch("src.esconnection.click.secho") as mock_secho: run(connection, "select * from non-existed") mock_secho.assert_called_with(message=str(expected), fg="red") @@ -68,7 +68,7 @@ def test_connection_fail(self): test_executor = ESConnection(endpoint=INVALID_ENDPOINT) err_message = "Can not connect to endpoint %s" % INVALID_ENDPOINT - with mock.patch("sys.exit") as mock_sys_exit, mock.patch("odfesql_cli.esconnection.click.secho") as mock_secho: + with mock.patch("sys.exit") as mock_sys_exit, mock.patch("src.esconnection.click.secho") as mock_secho: test_executor.set_connection() mock_sys_exit.assert_called() @@ -83,7 +83,7 @@ def side_effect_set_connection(is_reconnected): else: return ConnectionError() - with mock.patch("odfesql_cli.esconnection.click.secho") as mock_secho, mock.patch.object( + with mock.patch("src.esconnection.click.secho") as mock_secho, mock.patch.object( test_esexecutor, "set_connection" ) as mock_set_connection: # Assume reconnection success diff --git a/tests/test_formatter.py b/tests/test_formatter.py index 55daa23..95fcde8 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -18,17 +18,17 @@ import pytest from collections import namedtuple -from odfesql_cli.odfesql_cli import OdfeSqlCli, COLOR_CODE_REGEX -from odfesql_cli.formatter import Formatter -from odfesql_cli.utils import OutputSettings +from src.odfesql_cli import OdfeSqlCli, COLOR_CODE_REGEX +from src.formatter import Formatter +from src.utils import OutputSettings class TestFormatter: @pytest.fixture def pset_pager_mocks(self): cli = OdfeSqlCli() - with mock.patch("odfesql_cli.main.click.echo") as mock_echo, mock.patch( - "odfesql_cli.main.click.echo_via_pager" + with mock.patch("src.main.click.echo") as mock_echo, mock.patch( + "src.main.click.echo_via_pager" ) as mock_echo_via_pager, mock.patch.object(cli, "prompt_app") as mock_app: yield cli, mock_echo, mock_echo_via_pager, mock_app @@ -120,7 +120,7 @@ def test_format_output_vertical(self): "age | 24", ] - with mock.patch("odfesql_cli.main.click.secho") as mock_secho, mock.patch("odfesql_cli.main.click.confirm") as mock_confirm: + with mock.patch("src.main.click.secho") as mock_secho, mock.patch("src.main.click.confirm") as mock_confirm: expanded_results = formatter.format_output(data) mock_secho.assert_called_with(message="Output longer than terminal width", fg="red") diff --git a/tests/test_main.py b/tests/test_main.py index 18d82e2..e41c6f8 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -18,8 +18,8 @@ from click.testing import CliRunner from utils import estest, load_data, run, get_connection, TEST_INDEX_NAME -from odfesql_cli.main import cli -from odfesql_cli.odfesql_cli import OdfeSqlCli +from src.main import cli +from src.odfesql_cli import OdfeSqlCli INVALID_ENDPOINT = "http://invalid:9200" ENDPOINT = "http://localhost:9200" @@ -44,7 +44,7 @@ def test_explain(self, connection): +-----+""" ) - with mock.patch("odfesql_cli.main.click.echo") as mock_echo, mock.patch("odfesql_cli.main.click.secho") as mock_secho: + with mock.patch("src.main.click.echo") as mock_echo, mock.patch("src.main.click.secho") as mock_secho: runner = CliRunner() # test -q -e diff --git a/tests/test_odfesql_cli.py b/tests/test_odfesql_cli.py index 8b52e48..50f8759 100644 --- a/tests/test_odfesql_cli.py +++ b/tests/test_odfesql_cli.py @@ -17,11 +17,11 @@ from prompt_toolkit.shortcuts import PromptSession from prompt_toolkit.input.defaults import create_pipe_input -from odfesql_cli.esbuffer import es_is_multiline +from src.esbuffer import es_is_multiline from utils import estest, load_data, TEST_INDEX_NAME, ENDPOINT -from odfesql_cli.odfesql_cli import OdfeSqlCli -from odfesql_cli.esconnection import ESConnection -from odfesql_cli.esstyle import style_factory +from src.odfesql_cli import OdfeSqlCli +from src.esconnection import ESConnection +from src.esstyle import style_factory AUTH = None QUERY_WITH_CTRL_D = "select * from %s;\r\x04\r" % TEST_INDEX_NAME diff --git a/tests/utils.py b/tests/utils.py index 79c6a16..2077eee 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -16,9 +16,9 @@ import pytest from elasticsearch import ConnectionError, helpers, ConnectionPool -from odfesql_cli.esconnection import ESConnection -from odfesql_cli.utils import OutputSettings -from odfesql_cli.formatter import Formatter +from src.esconnection import ESConnection +from src.utils import OutputSettings +from src.formatter import Formatter TEST_INDEX_NAME = "odfesql_cli_test" ENDPOINT = "http://localhost:9200"