Skip to content

Commit 46e1976

Browse files
SNOW-893112 updated platformdirs usage (#1737)
1 parent 91d31b8 commit 46e1976

File tree

4 files changed

+23
-111
lines changed

4 files changed

+23
-111
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1212

1313
- Fixed a bug where url port and path were ignore in private link oscp retry.
1414
- Added thread safety in telemetry when instantiating multiple connections concurrently.
15+
- Bumped platformdirs dependency from >=2.6.0,<3.9.0 to >=2.6.0,<4.0.0.0 and made necessary changes to allow this.
1516

1617
- v3.2.0(September 06,2023)
1718

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ install_requires =
6060
typing_extensions>=4.3,<5
6161
filelock>=3.5,<4
6262
sortedcontainers>=2.4.0
63-
platformdirs>=2.6.0,<3.9.0
63+
platformdirs>=2.6.0,<4.0.0
6464
tomlkit
6565
include_package_data = True
6666
package_dir =

src/snowflake/connector/sf_dirs.py

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
from __future__ import annotations
66

77
import os
8-
from typing import Literal
8+
import pathlib
9+
from functools import cached_property
10+
from typing import Protocol
911

10-
from platformdirs import PlatformDirs, PlatformDirsABC
12+
from platformdirs import PlatformDirs
1113

1214

13-
def _resolve_platform_dirs() -> PlatformDirsABC:
15+
class PlatformDirsProto(Protocol):
16+
@property
17+
def user_config_path(self) -> pathlib.Path:
18+
...
19+
20+
21+
def _resolve_platform_dirs() -> PlatformDirsProto:
1422
"""Decide on what PlatformDirs class to use.
1523
1624
In case a folder exists (which can be customized with the environmental
@@ -40,7 +48,7 @@ def _resolve_platform_dirs() -> PlatformDirsABC:
4048
return PlatformDirs(**platformdir_kwargs)
4149

4250

43-
class SFPlatformDirs(PlatformDirsABC):
51+
class SFPlatformDirs:
4452
"""Single folder platformdirs.
4553
4654
This class introduces a PlatformDir class where everything is placed into a
@@ -51,91 +59,11 @@ class SFPlatformDirs(PlatformDirsABC):
5159
def __init__(
5260
self,
5361
single_dir: str,
54-
appname: str | None = None,
55-
appauthor: str | None | Literal[False] = None,
56-
version: str | None = None,
57-
roaming: bool = False,
58-
multipath: bool = False,
59-
opinion: bool = True,
60-
ensure_exists: bool = False,
62+
**kwargs,
6163
) -> None:
62-
super().__init__(
63-
appname=appname,
64-
appauthor=appauthor,
65-
version=version,
66-
roaming=roaming,
67-
multipath=multipath,
68-
opinion=opinion,
69-
ensure_exists=ensure_exists,
70-
)
71-
self.single_dir = single_dir
64+
self.single_dir = pathlib.Path(single_dir)
7265

73-
@property
74-
def user_data_dir(self) -> str:
66+
@cached_property
67+
def user_config_path(self) -> str:
7568
"""data directory tied to to the user"""
7669
return self.single_dir
77-
78-
@property
79-
def site_data_dir(self) -> str:
80-
"""data directory shared by users"""
81-
return self.user_data_dir
82-
83-
@property
84-
def user_config_dir(self) -> str:
85-
"""config directory tied to the user"""
86-
return self.user_data_dir
87-
88-
@property
89-
def site_config_dir(self) -> str:
90-
"""config directory shared by the users"""
91-
return self.user_data_dir
92-
93-
@property
94-
def user_cache_dir(self) -> str:
95-
"""cache directory tied to the user"""
96-
return self.user_data_dir
97-
98-
@property
99-
def site_cache_dir(self) -> str:
100-
"""cache directory shared by users"""
101-
return self.user_data_dir
102-
103-
@property
104-
def user_state_dir(self) -> str:
105-
"""state directory tied to the user"""
106-
return self.user_data_dir
107-
108-
@property
109-
def user_log_dir(self) -> str:
110-
"""log directory tied to the user"""
111-
return self.user_data_dir
112-
113-
@property
114-
def user_documents_dir(self) -> str:
115-
"""documents directory tied to the user"""
116-
return self.user_data_dir
117-
118-
@property
119-
def user_runtime_dir(self) -> str:
120-
"""runtime directory tied to the user"""
121-
return self.user_data_dir
122-
123-
@property
124-
def user_music_dir(self) -> str:
125-
"""music directory tied to the user"""
126-
return self.user_data_dir
127-
128-
@property
129-
def user_pictures_dir(self) -> str:
130-
"""pictures directory tied to the user"""
131-
return self.user_data_dir
132-
133-
@property
134-
def user_videos_dir(self) -> str:
135-
"""videos directory tied to the user"""
136-
return self.user_data_dir
137-
138-
@property
139-
def user_downloads_dir(self) -> str:
140-
"""downloads directory tied to the user"""
141-
return self.user_data_dir

test/unit/test_configmanager.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -499,35 +499,18 @@ def test_error_missing_fp_retrieve():
499499

500500

501501
@pytest.mark.parametrize("version", (None, "1"))
502-
@pytest.mark.parametrize(
503-
"method",
504-
(
505-
"user_data_dir",
506-
"site_data_dir",
507-
"user_config_dir",
508-
"site_config_dir",
509-
"user_cache_dir",
510-
"user_state_dir",
511-
"user_log_dir",
512-
"user_documents_dir",
513-
"user_runtime_dir",
514-
"user_music_dir",
515-
"user_pictures_dir",
516-
"user_videos_dir",
517-
),
518-
)
519-
def test_sf_dirs(tmp_path, method, version):
502+
def test_sf_dirs(tmp_path, version):
520503
appname = random_string(5)
521-
assert getattr(
504+
assert (
522505
SFPlatformDirs(
523506
str(tmp_path),
524507
appname=appname,
525508
appauthor=False,
526509
version=version,
527510
ensure_exists=True,
528-
),
529-
method,
530-
) == str(tmp_path)
511+
).user_config_path
512+
== tmp_path
513+
)
531514

532515

533516
def test_config_file_resolution_sfdirs_default():

0 commit comments

Comments
 (0)