snowpark-checkpoints-configuration 0.2.0rc1__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.
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/.gitignore +4 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/LICENSE +0 -25
- snowpark_checkpoints_configuration-0.3.0/PKG-INFO +63 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/README.md +2 -6
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/pyproject.toml +19 -10
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/__init__.py +32 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/__version__.py +16 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/checkpoint_metadata.py +76 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/checkpoint_name_utils.py +53 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/__init__.py +26 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_default_strategy.py +34 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_env_strategy.py +62 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/io_utils/io_file_manager.py +57 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/model/checkpoints.py +154 -0
- snowpark_checkpoints_configuration-0.3.0/src/snowflake/snowpark_checkpoints_configuration/singleton.py +23 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/test/.coveragerc +1 -0
- snowpark_checkpoints_configuration-0.3.0/test/unit/io_utils/test_default_strategy.py +126 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/test_checkpoint_metadata.py +38 -13
- snowpark_checkpoints_configuration-0.3.0/test/unit/test_checkpoint_name_utils.py +105 -0
- snowpark_checkpoints_configuration-0.3.0/test/unit/test_checkpoints.py +127 -0
- snowpark_checkpoints_configuration-0.3.0/test/unit/test_logger.py +128 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/valid_checkpoint/checkpoints.json +2 -2
- snowpark_checkpoints_configuration-0.2.0rc1/PKG-INFO +0 -267
- snowpark_checkpoints_configuration-0.2.0rc1/test/unit/test_checkpoints.py +0 -74
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/test/unit/invalid_checkpoint/checkpoints.json +0 -0
{snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/LICENSE
RENAMED
@@ -175,28 +175,3 @@
|
|
175
175
|
of your accepting any such warranty or additional liability.
|
176
176
|
|
177
177
|
END OF TERMS AND CONDITIONS
|
178
|
-
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
180
|
-
|
181
|
-
To apply the Apache License to your work, attach the following
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
-
replaced with your own identifying information. (Don't include
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
185
|
-
comment syntax for the file format. We also recommend that a
|
186
|
-
file or class name and description of purpose be included on the
|
187
|
-
same "printed page" as the copyright notice for easier
|
188
|
-
identification within third-party archives.
|
189
|
-
|
190
|
-
Copyright 2025 Snowflake
|
191
|
-
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
-
you may not use this file except in compliance with the License.
|
194
|
-
You may obtain a copy of the License at
|
195
|
-
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
-
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
-
See the License for the specific language governing permissions and
|
202
|
-
limitations under the License.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: snowpark-checkpoints-configuration
|
3
|
+
Version: 0.3.0
|
4
|
+
Summary: Migration tools for Snowpark
|
5
|
+
Project-URL: Bug Tracker, https://github.com/snowflakedb/snowpark-checkpoints/issues
|
6
|
+
Project-URL: Source code, https://github.com/snowflakedb/snowpark-checkpoints/
|
7
|
+
Author-email: "Snowflake, Inc." <snowflake-python-libraries-dl@snowflake.com>
|
8
|
+
License: Apache License, Version 2.0
|
9
|
+
License-File: LICENSE
|
10
|
+
Keywords: Snowflake,Snowpark,analytics,cloud,database,db
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
12
|
+
Classifier: Environment :: Console
|
13
|
+
Classifier: Environment :: Other Environment
|
14
|
+
Classifier: Intended Audience :: Developers
|
15
|
+
Classifier: Intended Audience :: Education
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
17
|
+
Classifier: Intended Audience :: System Administrators
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
19
|
+
Classifier: Operating System :: OS Independent
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
21
|
+
Classifier: Programming Language :: SQL
|
22
|
+
Classifier: Topic :: Database
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
24
|
+
Classifier: Topic :: Software Development
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
28
|
+
Requires-Python: <3.12,>=3.9
|
29
|
+
Requires-Dist: pydantic>=1.8.2
|
30
|
+
Requires-Dist: snowflake-snowpark-python>=1.23.0
|
31
|
+
Provides-Extra: development
|
32
|
+
Requires-Dist: certifi==2025.1.31; extra == 'development'
|
33
|
+
Requires-Dist: coverage>=7.6.7; extra == 'development'
|
34
|
+
Requires-Dist: hatchling==1.25.0; extra == 'development'
|
35
|
+
Requires-Dist: pre-commit>=4.0.1; extra == 'development'
|
36
|
+
Requires-Dist: pyarrow>=18.0.0; extra == 'development'
|
37
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == 'development'
|
38
|
+
Requires-Dist: pytest>=8.3.3; extra == 'development'
|
39
|
+
Requires-Dist: setuptools>=70.0.0; extra == 'development'
|
40
|
+
Requires-Dist: twine==5.1.1; extra == 'development'
|
41
|
+
Description-Content-Type: text/markdown
|
42
|
+
|
43
|
+
# snowpark-checkpoints-configuration
|
44
|
+
|
45
|
+
---
|
46
|
+
##### This package is on Public Preview.
|
47
|
+
---
|
48
|
+
**snowpark-checkpoints-configuration** is a module for loading `checkpoint.json` and provides a model.
|
49
|
+
This module will work automatically with *snowpark-checkpoints-collector* and *snowpark-checkpoints-validators*. This will try to read the configuration file from the current working directory.
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
To explicit load a file, you can import `CheckpointMetadata` and create an instance as shown below:
|
54
|
+
|
55
|
+
```python
|
56
|
+
from snowflake.snowpark_checkpoints_configuration import CheckpointMetadata
|
57
|
+
|
58
|
+
my_checkpoint_metadata = CheckpointMetadata("path/to/checkpoint.json")
|
59
|
+
|
60
|
+
checkpoint_model = my_checkpoint_metadata.get_checkpoint("my_checkpoint_name")
|
61
|
+
...
|
62
|
+
```
|
63
|
+
------
|
{snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.3.0}/README.md
RENAMED
@@ -1,12 +1,8 @@
|
|
1
1
|
# snowpark-checkpoints-configuration
|
2
2
|
|
3
3
|
---
|
4
|
-
|
5
|
-
|
6
|
-
This package is on Private Preview.
|
7
|
-
|
4
|
+
##### This package is on Public Preview.
|
8
5
|
---
|
9
|
-
|
10
6
|
**snowpark-checkpoints-configuration** is a module for loading `checkpoint.json` and provides a model.
|
11
7
|
This module will work automatically with *snowpark-checkpoints-collector* and *snowpark-checkpoints-validators*. This will try to read the configuration file from the current working directory.
|
12
8
|
|
@@ -19,7 +15,7 @@ from snowflake.snowpark_checkpoints_configuration import CheckpointMetadata
|
|
19
15
|
|
20
16
|
my_checkpoint_metadata = CheckpointMetadata("path/to/checkpoint.json")
|
21
17
|
|
22
|
-
checkpoint_model = my_checkpoint_metadata.
|
18
|
+
checkpoint_model = my_checkpoint_metadata.get_checkpoint("my_checkpoint_name")
|
23
19
|
...
|
24
20
|
```
|
25
21
|
------
|
@@ -3,7 +3,6 @@ build-backend = "hatchling.build"
|
|
3
3
|
requires = ["hatchling"]
|
4
4
|
|
5
5
|
[project]
|
6
|
-
authors = [{name = "Snowflake Inc."}]
|
7
6
|
classifiers = [
|
8
7
|
"Development Status :: 4 - Beta",
|
9
8
|
"Environment :: Console",
|
@@ -26,10 +25,14 @@ classifiers = [
|
|
26
25
|
|
27
26
|
dependencies = [
|
28
27
|
"pydantic>=1.8.2",
|
29
|
-
"snowflake-snowpark-python",
|
28
|
+
"snowflake-snowpark-python>=1.23.0",
|
30
29
|
]
|
31
30
|
|
31
|
+
authors = [
|
32
|
+
{name = "Snowflake, Inc.", email = "snowflake-python-libraries-dl@snowflake.com"},
|
33
|
+
]
|
32
34
|
description = "Migration tools for Snowpark"
|
35
|
+
dynamic = ['version']
|
33
36
|
keywords = [
|
34
37
|
'Snowflake',
|
35
38
|
'analytics',
|
@@ -38,12 +41,10 @@ keywords = [
|
|
38
41
|
'db',
|
39
42
|
'Snowpark',
|
40
43
|
]
|
41
|
-
license = {
|
44
|
+
license = {text = "Apache License, Version 2.0"}
|
42
45
|
name = "snowpark-checkpoints-configuration"
|
43
46
|
readme = "README.md"
|
44
|
-
requires-python =
|
45
|
-
dynamic = ['version']
|
46
|
-
|
47
|
+
requires-python = '>=3.9,<3.12'
|
47
48
|
|
48
49
|
[project.optional-dependencies]
|
49
50
|
development = [
|
@@ -55,6 +56,7 @@ development = [
|
|
55
56
|
"pre-commit>=4.0.1",
|
56
57
|
"setuptools>=70.0.0",
|
57
58
|
"pyarrow>=18.0.0",
|
59
|
+
"certifi==2025.1.31",
|
58
60
|
]
|
59
61
|
|
60
62
|
[project.urls]
|
@@ -62,7 +64,7 @@ development = [
|
|
62
64
|
"Source code" = "https://github.com/snowflakedb/snowpark-checkpoints/"
|
63
65
|
|
64
66
|
[tool.hatch.version]
|
65
|
-
path = "__version__.py"
|
67
|
+
path = "src/snowflake/snowpark_checkpoints_configuration/__version__.py"
|
66
68
|
pattern = '^__version__ = "(?P<version>.*)"'
|
67
69
|
source = "regex"
|
68
70
|
|
@@ -74,15 +76,22 @@ where = ["src/"]
|
|
74
76
|
dev-mode-dirs = ['src']
|
75
77
|
directory = 'snowpark-checkpoints-configuration'
|
76
78
|
|
79
|
+
[[tool.hatch.sources]]
|
80
|
+
dir = "src/snowflake/snowpark_checkpoints_configuration"
|
81
|
+
name = "snowpark-checkpoints-configuration"
|
82
|
+
type = "package"
|
83
|
+
|
77
84
|
[tool.hatch.build.targets.wheel]
|
78
85
|
directory = "dist"
|
79
|
-
packages = [
|
86
|
+
packages = [
|
87
|
+
"src/snowflake",
|
88
|
+
]
|
80
89
|
|
81
90
|
[tool.hatch.build.targets.sdist]
|
82
91
|
directory = "dist"
|
83
92
|
exclude = ["/.github", "/.idea"]
|
84
93
|
include = [
|
85
|
-
'
|
94
|
+
'src/**',
|
86
95
|
'README.md',
|
87
96
|
'LICENSE',
|
88
97
|
'test/',
|
@@ -116,7 +125,7 @@ check = [
|
|
116
125
|
|
117
126
|
[tool.hatch.envs.test.scripts]
|
118
127
|
check = [
|
119
|
-
'pytest -
|
128
|
+
'pytest -vvv --junitxml=test/outcome/test-results.xml --cov=. --cov-branch --cov-config=test/.coveragerc --cov-report=xml:test/outcome/coverage-{matrix:python:{env:PYTHON_VERSION:unset}}.xml {args:test} --cov-report=term --cov-report=html:test/outcome/coverage-{matrix:python:{env:PYTHON_VERSION:unset}}.html --cov-report=json:test/outcome/coverage-{matrix:python:{env:PYTHON_VERSION:unset}}.json',
|
120
129
|
]
|
121
130
|
|
122
131
|
coverage = [
|
@@ -0,0 +1,32 @@
|
|
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 logging
|
17
|
+
|
18
|
+
|
19
|
+
# Add a NullHandler to prevent logging messages from being output to
|
20
|
+
# sys.stderr if no logging configuration is provided.
|
21
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
22
|
+
|
23
|
+
# ruff: noqa: E402
|
24
|
+
|
25
|
+
from snowflake.snowpark_checkpoints_configuration.checkpoint_metadata import (
|
26
|
+
CheckpointMetadata,
|
27
|
+
)
|
28
|
+
|
29
|
+
|
30
|
+
__all__ = [
|
31
|
+
"CheckpointMetadata",
|
32
|
+
]
|
@@ -0,0 +1,16 @@
|
|
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
|
+
__version__ = "0.3.0"
|
@@ -0,0 +1,76 @@
|
|
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 logging
|
17
|
+
import os
|
18
|
+
|
19
|
+
from typing import Optional
|
20
|
+
|
21
|
+
from snowflake.snowpark_checkpoints_configuration.io_utils.io_file_manager import (
|
22
|
+
get_io_file_manager,
|
23
|
+
)
|
24
|
+
from snowflake.snowpark_checkpoints_configuration.model.checkpoints import (
|
25
|
+
Checkpoint,
|
26
|
+
Checkpoints,
|
27
|
+
)
|
28
|
+
from snowflake.snowpark_checkpoints_configuration.singleton import Singleton
|
29
|
+
|
30
|
+
|
31
|
+
LOGGER = logging.getLogger(__name__)
|
32
|
+
|
33
|
+
|
34
|
+
class CheckpointMetadata(metaclass=Singleton):
|
35
|
+
|
36
|
+
"""CheckpointMetadata class.
|
37
|
+
|
38
|
+
This is a singleton class that reads the checkpoints.json file
|
39
|
+
and provides an interface to get the checkpoint configuration.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
metaclass (Singleton, optional): Defaults to Singleton.
|
43
|
+
|
44
|
+
"""
|
45
|
+
|
46
|
+
def __init__(self, path: Optional[str] = None):
|
47
|
+
self.checkpoint_model: Checkpoints = Checkpoints(type="", pipelines=[])
|
48
|
+
directory = path if path is not None else get_io_file_manager().getcwd()
|
49
|
+
checkpoints_file = os.path.join(directory, "checkpoints.json")
|
50
|
+
if get_io_file_manager().file_exists(checkpoints_file):
|
51
|
+
LOGGER.info("Reading checkpoints file: '%s'", checkpoints_file)
|
52
|
+
try:
|
53
|
+
checkpoint_json = get_io_file_manager().read(checkpoints_file)
|
54
|
+
self.checkpoint_model = Checkpoints.model_validate_json(checkpoint_json)
|
55
|
+
LOGGER.info(
|
56
|
+
"Successfully read and validated checkpoints file: '%s'",
|
57
|
+
checkpoints_file,
|
58
|
+
)
|
59
|
+
except Exception as e:
|
60
|
+
error_msg = f"An error occurred while reading the checkpoints file: '{checkpoints_file}'"
|
61
|
+
LOGGER.exception(error_msg)
|
62
|
+
raise Exception(f"{error_msg} \n {e}") from None
|
63
|
+
else:
|
64
|
+
LOGGER.warning("Checkpoints file not found: '%s'", checkpoints_file)
|
65
|
+
|
66
|
+
def get_checkpoint(self, checkpoint_name: str) -> Checkpoint:
|
67
|
+
"""Get a checkpoint by its name.
|
68
|
+
|
69
|
+
Args:
|
70
|
+
checkpoint_name (str): checkpoint name
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
Checkpoint: Checkpoint configuration instance
|
74
|
+
|
75
|
+
"""
|
76
|
+
return self.checkpoint_model.get_check_point(checkpoint_name=checkpoint_name)
|
@@ -0,0 +1,53 @@
|
|
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 re as regx
|
17
|
+
|
18
|
+
|
19
|
+
CHECKPOINT_NAME_REGEX_PATTERN = r"[a-zA-Z_][a-zA-Z0-9_$]+"
|
20
|
+
TRANSLATION_TABLE = str.maketrans({" ": "_", "-": "_"})
|
21
|
+
|
22
|
+
|
23
|
+
def normalize_checkpoint_name(checkpoint_name: str) -> str:
|
24
|
+
"""Normalize the provided checkpoint name by replacing: the whitespace and hyphen tokens by underscore token.
|
25
|
+
|
26
|
+
Args:
|
27
|
+
checkpoint_name (str): The checkpoint name to normalize.
|
28
|
+
|
29
|
+
Returns:
|
30
|
+
str: the checkpoint name normalized.
|
31
|
+
|
32
|
+
"""
|
33
|
+
normalized_checkpoint_name = checkpoint_name.translate(TRANSLATION_TABLE)
|
34
|
+
return normalized_checkpoint_name
|
35
|
+
|
36
|
+
|
37
|
+
def is_valid_checkpoint_name(checkpoint_name: str) -> bool:
|
38
|
+
"""Check if the provided checkpoint name is valid.
|
39
|
+
|
40
|
+
A valid checkpoint name must:
|
41
|
+
- Start with a letter (a-z, A-Z) or an underscore (_)
|
42
|
+
- Be followed by any combination of letters, digits (0-9), underscores (_), and dollar signs ($).
|
43
|
+
|
44
|
+
Args:
|
45
|
+
checkpoint_name (str): The checkpoint name to validate.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
bool: True if the checkpoint name is valid; otherwise, False.
|
49
|
+
|
50
|
+
"""
|
51
|
+
matched = regx.fullmatch(CHECKPOINT_NAME_REGEX_PATTERN, checkpoint_name)
|
52
|
+
is_valid = bool(matched)
|
53
|
+
return is_valid
|
@@ -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()
|