snowpark-checkpoints-configuration 0.2.1__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/PKG-INFO +2 -1
  2. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/pyproject.toml +1 -0
  3. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/__version__.py +1 -1
  4. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/checkpoint_metadata.py +7 -7
  5. snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/__init__.py +26 -0
  6. snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_default_strategy.py +34 -0
  7. snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_env_strategy.py +62 -0
  8. snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_file_manager.py +57 -0
  9. snowpark_checkpoints_configuration-0.3.0/test/unit/io_utils/test_default_strategy.py +126 -0
  10. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/.gitignore +0 -0
  11. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/LICENSE +0 -0
  12. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/README.md +0 -0
  13. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/__init__.py +0 -0
  14. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/checkpoint_name_utils.py +0 -0
  15. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/model/checkpoints.py +0 -0
  16. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/src/snowflake/snowpark_checkpoints_configuration/singleton.py +0 -0
  17. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/.coveragerc +0 -0
  18. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/invalid_checkpoint/checkpoints.json +0 -0
  19. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/test_checkpoint_metadata.py +0 -0
  20. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/test_checkpoint_name_utils.py +0 -0
  21. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/test_checkpoints.py +0 -0
  22. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/test_logger.py +0 -0
  23. {snowpark_checkpoints_configuration-0.2.1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/valid_checkpoint/checkpoints.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snowpark-checkpoints-configuration
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Migration tools for Snowpark
5
5
  Project-URL: Bug Tracker, https://github.com/snowflakedb/snowpark-checkpoints/issues
6
6
  Project-URL: Source code, https://github.com/snowflakedb/snowpark-checkpoints/
@@ -29,6 +29,7 @@ Requires-Python: <3.12,>=3.9
29
29
  Requires-Dist: pydantic>=1.8.2
30
30
  Requires-Dist: snowflake-snowpark-python>=1.23.0
31
31
  Provides-Extra: development
32
+ Requires-Dist: certifi==2025.1.31; extra == 'development'
32
33
  Requires-Dist: coverage>=7.6.7; extra == 'development'
33
34
  Requires-Dist: hatchling==1.25.0; extra == 'development'
34
35
  Requires-Dist: pre-commit>=4.0.1; extra == 'development'
@@ -56,6 +56,7 @@ development = [
56
56
  "pre-commit>=4.0.1",
57
57
  "setuptools>=70.0.0",
58
58
  "pyarrow>=18.0.0",
59
+ "certifi==2025.1.31",
59
60
  ]
60
61
 
61
62
  [project.urls]
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- __version__ = "0.2.1"
16
+ __version__ = "0.3.0"
@@ -18,6 +18,9 @@ import os
18
18
 
19
19
  from typing import Optional
20
20
 
21
+ from snowflake.snowpark_checkpoints_configuration.io_utils.io_file_manager import (
22
+ get_io_file_manager,
23
+ )
21
24
  from snowflake.snowpark_checkpoints_configuration.model.checkpoints import (
22
25
  Checkpoint,
23
26
  Checkpoints,
@@ -42,16 +45,13 @@ class CheckpointMetadata(metaclass=Singleton):
42
45
 
43
46
  def __init__(self, path: Optional[str] = None):
44
47
  self.checkpoint_model: Checkpoints = Checkpoints(type="", pipelines=[])
45
- directory = path if path is not None else os.getcwd()
48
+ directory = path if path is not None else get_io_file_manager().getcwd()
46
49
  checkpoints_file = os.path.join(directory, "checkpoints.json")
47
- if os.path.exists(checkpoints_file):
50
+ if get_io_file_manager().file_exists(checkpoints_file):
48
51
  LOGGER.info("Reading checkpoints file: '%s'", checkpoints_file)
49
52
  try:
50
- with open(checkpoints_file) as f:
51
- checkpoint_json = f.read()
52
- self.checkpoint_model = Checkpoints.model_validate_json(
53
- checkpoint_json
54
- )
53
+ checkpoint_json = get_io_file_manager().read(checkpoints_file)
54
+ self.checkpoint_model = Checkpoints.model_validate_json(checkpoint_json)
55
55
  LOGGER.info(
56
56
  "Successfully read and validated checkpoints file: '%s'",
57
57
  checkpoints_file,
@@ -0,0 +1,26 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ __all__ = ["EnvStrategy", "IOFileManager", "IODefaultStrategy"]
17
+
18
+ from snowflake.snowpark_checkpoints_configuration.io_utils.io_env_strategy import (
19
+ EnvStrategy,
20
+ )
21
+ from snowflake.snowpark_checkpoints_configuration.io_utils.io_default_strategy import (
22
+ IODefaultStrategy,
23
+ )
24
+ from snowflake.snowpark_checkpoints_configuration.io_utils.io_file_manager import (
25
+ IOFileManager,
26
+ )
@@ -0,0 +1,34 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import os
17
+
18
+ from typing import Optional
19
+
20
+ from snowflake.snowpark_checkpoints_configuration.io_utils import EnvStrategy
21
+
22
+
23
+ class IODefaultStrategy(EnvStrategy):
24
+ def file_exists(self, path: str) -> bool:
25
+ return os.path.isfile(path)
26
+
27
+ def read(
28
+ self, file_path: str, mode: str = "r", encoding: Optional[str] = None
29
+ ) -> str:
30
+ with open(file_path, mode=mode, encoding=encoding) as file:
31
+ return file.read()
32
+
33
+ def getcwd(self) -> str:
34
+ return os.getcwd()
@@ -0,0 +1,62 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from abc import ABC, abstractmethod
17
+ from typing import Optional
18
+
19
+
20
+ class EnvStrategy(ABC):
21
+
22
+ """An abstract base class that defines methods for file and directory operations.
23
+
24
+ Subclasses should implement these methods to provide environment-specific behavior.
25
+ """
26
+
27
+ @abstractmethod
28
+ def file_exists(self, path: str) -> bool:
29
+ """Check if a file exists.
30
+
31
+ Args:
32
+ path: The path to the file.
33
+
34
+ Returns:
35
+ bool: True if the file exists, False otherwise.
36
+
37
+ """
38
+
39
+ @abstractmethod
40
+ def read(
41
+ self, file_path: str, mode: str = "r", encoding: Optional[str] = None
42
+ ) -> str:
43
+ """Read content from a file.
44
+
45
+ Args:
46
+ file_path: The path to the file to read from.
47
+ mode: The mode in which to open the file.
48
+ encoding: The encoding to use for reading the file.
49
+
50
+ Returns:
51
+ str: The content of the file.
52
+
53
+ """
54
+
55
+ @abstractmethod
56
+ def getcwd(self) -> str:
57
+ """Get the current working directory.
58
+
59
+ Returns:
60
+ str: The current working directory.
61
+
62
+ """
@@ -0,0 +1,57 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from typing import Optional
17
+
18
+ from snowflake.snowpark_checkpoints_configuration.io_utils import (
19
+ EnvStrategy,
20
+ IODefaultStrategy,
21
+ )
22
+ from snowflake.snowpark_checkpoints_configuration.singleton import Singleton
23
+
24
+
25
+ class IOFileManager(metaclass=Singleton):
26
+ def __init__(self, strategy: Optional[EnvStrategy] = None):
27
+ self.strategy = strategy or IODefaultStrategy()
28
+
29
+ def file_exists(self, path: str) -> bool:
30
+ return self.strategy.file_exists(path)
31
+
32
+ def read(
33
+ self, file_path: str, mode: str = "r", encoding: Optional[str] = None
34
+ ) -> str:
35
+ return self.strategy.read(file_path, mode, encoding)
36
+
37
+ def getcwd(self) -> str:
38
+ return self.strategy.getcwd()
39
+
40
+ def set_strategy(self, strategy: EnvStrategy):
41
+ """Set the strategy for file and directory operations.
42
+
43
+ Args:
44
+ strategy (EnvStrategy): The strategy to use for file and directory operations.
45
+
46
+ """
47
+ self.strategy = strategy
48
+
49
+
50
+ def get_io_file_manager():
51
+ """Get the singleton instance of IOFileManager.
52
+
53
+ Returns:
54
+ IOFileManager: The singleton instance of IOFileManager.
55
+
56
+ """
57
+ return IOFileManager()
@@ -0,0 +1,126 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import os
17
+ import tempfile
18
+ from unittest.mock import patch
19
+ import pytest
20
+
21
+ from snowflake.snowpark_checkpoints_configuration.io_utils import IODefaultStrategy
22
+ from snowflake.snowpark_checkpoints_configuration.io_utils.io_file_manager import (
23
+ get_io_file_manager,
24
+ )
25
+ from snowflake.snowpark_checkpoints_configuration.singleton import Singleton
26
+
27
+
28
+ @pytest.fixture(scope="function")
29
+ def io_file_manager():
30
+ Singleton._instances = {}
31
+ return get_io_file_manager()
32
+
33
+
34
+ def test_default_file_exists(io_file_manager):
35
+ with tempfile.TemporaryDirectory(dir=os.getcwd()) as temp_dir:
36
+ # Arrange
37
+ path = os.path.join(temp_dir, "test_file.txt")
38
+ with open(path, "w") as f:
39
+ f.write("test")
40
+
41
+ # Act
42
+ result = io_file_manager.file_exists(path)
43
+
44
+ # Assert
45
+ assert result
46
+
47
+
48
+ def test_default_file_exists_fail(io_file_manager):
49
+ # Act
50
+ result_not_exists = io_file_manager.file_exists("")
51
+
52
+ # Assert
53
+ assert result_not_exists is False
54
+
55
+
56
+ def test_default_file_exists_fail_with_folder(io_file_manager):
57
+ with tempfile.TemporaryDirectory(dir=os.getcwd()) as temp_dir:
58
+ # Arrange
59
+ path = os.path.join(temp_dir, "temp_dir")
60
+ os.makedirs(path)
61
+
62
+ # Act
63
+ result_not_file = io_file_manager.file_exists(path)
64
+
65
+ # Assert
66
+ assert result_not_file is False
67
+
68
+
69
+ def test_default_read(io_file_manager):
70
+ with tempfile.TemporaryDirectory(dir=os.getcwd()) as temp_dir:
71
+ # Arrange
72
+ path = os.path.join(temp_dir, "test_file.txt")
73
+ content = "test"
74
+ with open(path, "w") as f:
75
+ f.write(content)
76
+
77
+ # Act
78
+ result = io_file_manager.read(path)
79
+
80
+ # Assert
81
+ assert result == content
82
+
83
+
84
+ def test_default_read_fail(io_file_manager):
85
+ with tempfile.TemporaryDirectory(dir=os.getcwd()) as temp_dir:
86
+ # Arrange
87
+ path = os.path.join(temp_dir, "test_file.txt")
88
+
89
+ # Act & Assert
90
+ with pytest.raises(FileNotFoundError):
91
+ io_file_manager.read(path)
92
+
93
+
94
+ def test_default_getcwd(io_file_manager):
95
+ with tempfile.TemporaryDirectory(dir=os.getcwd()):
96
+ # Act
97
+ result = io_file_manager.getcwd()
98
+
99
+ # Assert
100
+ assert isinstance(result, str)
101
+
102
+
103
+ def test_default_set_strategy(io_file_manager):
104
+ try:
105
+ # Arrange
106
+ with patch(
107
+ "snowflake.snowpark_checkpoints_configuration.io_utils.EnvStrategy"
108
+ ) as MockStrategy:
109
+ strategy = MockStrategy()
110
+
111
+ # Act
112
+ io_file_manager.set_strategy(strategy)
113
+
114
+ # Assert
115
+ assert io_file_manager.strategy == strategy
116
+ finally:
117
+ io_file_manager.set_strategy(IODefaultStrategy())
118
+
119
+
120
+ def test_default_get_io_file_manager_singleton():
121
+ # Act
122
+ result = get_io_file_manager()
123
+ result2 = get_io_file_manager()
124
+
125
+ # Assert
126
+ assert result == result2