From 125a2db2f4b295018ea166dd29e9496c61278999 Mon Sep 17 00:00:00 2001 From: Patryk Czajka Date: Thu, 8 Aug 2024 19:38:50 +0200 Subject: [PATCH] Fix default config location resolution on Windows OS (#2017) --- DESCRIPTION.md | 1 + src/snowflake/connector/sf_dirs.py | 8 ++++---- test/unit/test_configmanager.py | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 62850adff..9b230215d 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne - v3.12.1(TBD) - Fixed a bug that session token is logged when renewing session. + - Use `pathlib` instead of `os` for default config file location resolution. - Fixed a bug that disabling client telemetry does not work. - v3.12.0(July 24,2024) diff --git a/src/snowflake/connector/sf_dirs.py b/src/snowflake/connector/sf_dirs.py index a3214cebf..09164affb 100644 --- a/src/snowflake/connector/sf_dirs.py +++ b/src/snowflake/connector/sf_dirs.py @@ -31,12 +31,12 @@ def _resolve_platform_dirs() -> PlatformDirsProto: "appname": "snowflake", "appauthor": False, } - snowflake_home = os.path.expanduser( + snowflake_home = pathlib.Path( os.environ.get("SNOWFLAKE_HOME", "~/.snowflake/"), - ) - if os.path.exists(snowflake_home): + ).expanduser() + if snowflake_home.exists(): return SFPlatformDirs( - snowflake_home, + str(snowflake_home), **platformdir_kwargs, ) else: diff --git a/test/unit/test_configmanager.py b/test/unit/test_configmanager.py index 682fe2247..f6e4f4cb3 100644 --- a/test/unit/test_configmanager.py +++ b/test/unit/test_configmanager.py @@ -522,9 +522,11 @@ def test_sf_dirs(tmp_path, version): def test_config_file_resolution_sfdirs_default(): - default_loc = os.path.expanduser("~/.snowflake") - existed_before = os.path.exists(default_loc) - os.makedirs(default_loc, exist_ok=True) + from pathlib import Path + + default_loc = Path("~/.snowflake").expanduser() + existed_before = default_loc.exists() + default_loc.mkdir(exist_ok=True) try: assert isinstance(_resolve_platform_dirs(), SFPlatformDirs) finally: