From de472676a05817dd835a4c527b4d5fc163714796 Mon Sep 17 00:00:00 2001 From: "ZhengYu, Xu" Date: Wed, 17 Apr 2024 16:12:31 +0800 Subject: [PATCH] refactor: A more Pythonic way to set environment variables. Signed-off-by: ZhengYu, Xu --- connectorx-python/connectorx/__init__.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/connectorx-python/connectorx/__init__.py b/connectorx-python/connectorx/__init__.py index b58590e80..3792fb39c 100644 --- a/connectorx-python/connectorx/__init__.py +++ b/connectorx-python/connectorx/__init__.py @@ -27,12 +27,11 @@ not os.path.basename(os.path.abspath(os.path.join(dir_path, ".."))) == "connectorx-python" ): - if "J4RS_BASE_PATH" not in os.environ: - os.environ["J4RS_BASE_PATH"] = os.path.join(dir_path, "dependencies") -if "CX_REWRITER_PATH" not in os.environ: - os.environ["CX_REWRITER_PATH"] = os.path.join( - dir_path, "dependencies/federated-rewriter.jar" - ) + os.environ.setdefault("J4RS_BASE_PATH", os.path.join(dir_path, "dependencies")) + +os.environ.setdefault( + "CX_REWRITER_PATH", os.path.join(dir_path, "dependencies/federated-rewriter.jar") +) def rewrite_conn(conn: str, protocol: Optional[str] = None): @@ -208,7 +207,6 @@ def read_sql( query = query[0] query = remove_ending_semicolon(query) - if isinstance(conn, dict): assert partition_on is None and isinstance( query, str @@ -237,7 +235,6 @@ def read_sql( return df if isinstance(query, str): - query = remove_ending_semicolon(query) if partition_on is None: @@ -388,8 +385,8 @@ def reconstruct_pandas(df_infos: Dict[str, Any]): def remove_ending_semicolon(query: str) -> str: - if query[-1] == ';': - query= list(query) + if query[-1] == ";": + query = list(query) query.pop(-1) query = "".join(query) return query