snowpark-checkpoints-configuration 0.2.0rc1__tar.gz → 0.2.1__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.2.1}/.gitignore +4 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/LICENSE +0 -25
- snowpark_checkpoints_configuration-0.2.1/PKG-INFO +62 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/README.md +2 -6
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/pyproject.toml +18 -10
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/__init__.py +32 -0
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/__version__.py +16 -0
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/checkpoint_metadata.py +76 -0
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/checkpoint_name_utils.py +53 -0
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/model/checkpoints.py +154 -0
- snowpark_checkpoints_configuration-0.2.1/src/snowflake/snowpark_checkpoints_configuration/singleton.py +23 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/test/.coveragerc +1 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/test/unit/test_checkpoint_metadata.py +38 -13
- snowpark_checkpoints_configuration-0.2.1/test/unit/test_checkpoint_name_utils.py +105 -0
- snowpark_checkpoints_configuration-0.2.1/test/unit/test_checkpoints.py +127 -0
- snowpark_checkpoints_configuration-0.2.1/test/unit/test_logger.py +128 -0
- {snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/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.2.1}/test/unit/invalid_checkpoint/checkpoints.json +0 -0
{snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/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,62 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: snowpark-checkpoints-configuration
|
3
|
+
Version: 0.2.1
|
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: coverage>=7.6.7; extra == 'development'
|
33
|
+
Requires-Dist: hatchling==1.25.0; extra == 'development'
|
34
|
+
Requires-Dist: pre-commit>=4.0.1; extra == 'development'
|
35
|
+
Requires-Dist: pyarrow>=18.0.0; extra == 'development'
|
36
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == 'development'
|
37
|
+
Requires-Dist: pytest>=8.3.3; extra == 'development'
|
38
|
+
Requires-Dist: setuptools>=70.0.0; extra == 'development'
|
39
|
+
Requires-Dist: twine==5.1.1; extra == 'development'
|
40
|
+
Description-Content-Type: text/markdown
|
41
|
+
|
42
|
+
# snowpark-checkpoints-configuration
|
43
|
+
|
44
|
+
---
|
45
|
+
##### This package is on Public Preview.
|
46
|
+
---
|
47
|
+
**snowpark-checkpoints-configuration** is a module for loading `checkpoint.json` and provides a model.
|
48
|
+
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.
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
To explicit load a file, you can import `CheckpointMetadata` and create an instance as shown below:
|
53
|
+
|
54
|
+
```python
|
55
|
+
from snowflake.snowpark_checkpoints_configuration import CheckpointMetadata
|
56
|
+
|
57
|
+
my_checkpoint_metadata = CheckpointMetadata("path/to/checkpoint.json")
|
58
|
+
|
59
|
+
checkpoint_model = my_checkpoint_metadata.get_checkpoint("my_checkpoint_name")
|
60
|
+
...
|
61
|
+
```
|
62
|
+
------
|
{snowpark_checkpoints_configuration-0.2.0rc1 → snowpark_checkpoints_configuration-0.2.1}/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 = [
|
@@ -62,7 +63,7 @@ development = [
|
|
62
63
|
"Source code" = "https://github.com/snowflakedb/snowpark-checkpoints/"
|
63
64
|
|
64
65
|
[tool.hatch.version]
|
65
|
-
path = "__version__.py"
|
66
|
+
path = "src/snowflake/snowpark_checkpoints_configuration/__version__.py"
|
66
67
|
pattern = '^__version__ = "(?P<version>.*)"'
|
67
68
|
source = "regex"
|
68
69
|
|
@@ -74,15 +75,22 @@ where = ["src/"]
|
|
74
75
|
dev-mode-dirs = ['src']
|
75
76
|
directory = 'snowpark-checkpoints-configuration'
|
76
77
|
|
78
|
+
[[tool.hatch.sources]]
|
79
|
+
dir = "src/snowflake/snowpark_checkpoints_configuration"
|
80
|
+
name = "snowpark-checkpoints-configuration"
|
81
|
+
type = "package"
|
82
|
+
|
77
83
|
[tool.hatch.build.targets.wheel]
|
78
84
|
directory = "dist"
|
79
|
-
packages = [
|
85
|
+
packages = [
|
86
|
+
"src/snowflake",
|
87
|
+
]
|
80
88
|
|
81
89
|
[tool.hatch.build.targets.sdist]
|
82
90
|
directory = "dist"
|
83
91
|
exclude = ["/.github", "/.idea"]
|
84
92
|
include = [
|
85
|
-
'
|
93
|
+
'src/**',
|
86
94
|
'README.md',
|
87
95
|
'LICENSE',
|
88
96
|
'test/',
|
@@ -116,7 +124,7 @@ check = [
|
|
116
124
|
|
117
125
|
[tool.hatch.envs.test.scripts]
|
118
126
|
check = [
|
119
|
-
'pytest -
|
127
|
+
'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
128
|
]
|
121
129
|
|
122
130
|
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.2.1"
|
@@ -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.model.checkpoints import (
|
22
|
+
Checkpoint,
|
23
|
+
Checkpoints,
|
24
|
+
)
|
25
|
+
from snowflake.snowpark_checkpoints_configuration.singleton import Singleton
|
26
|
+
|
27
|
+
|
28
|
+
LOGGER = logging.getLogger(__name__)
|
29
|
+
|
30
|
+
|
31
|
+
class CheckpointMetadata(metaclass=Singleton):
|
32
|
+
|
33
|
+
"""CheckpointMetadata class.
|
34
|
+
|
35
|
+
This is a singleton class that reads the checkpoints.json file
|
36
|
+
and provides an interface to get the checkpoint configuration.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
metaclass (Singleton, optional): Defaults to Singleton.
|
40
|
+
|
41
|
+
"""
|
42
|
+
|
43
|
+
def __init__(self, path: Optional[str] = None):
|
44
|
+
self.checkpoint_model: Checkpoints = Checkpoints(type="", pipelines=[])
|
45
|
+
directory = path if path is not None else os.getcwd()
|
46
|
+
checkpoints_file = os.path.join(directory, "checkpoints.json")
|
47
|
+
if os.path.exists(checkpoints_file):
|
48
|
+
LOGGER.info("Reading checkpoints file: '%s'", checkpoints_file)
|
49
|
+
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
|
+
)
|
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,154 @@
|
|
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
|
+
from typing import Optional
|
19
|
+
|
20
|
+
from pydantic import BaseModel, ConfigDict, field_validator
|
21
|
+
from pydantic.alias_generators import to_camel
|
22
|
+
|
23
|
+
from snowflake.snowpark_checkpoints_configuration import checkpoint_name_utils
|
24
|
+
|
25
|
+
|
26
|
+
LOGGER = logging.getLogger(__name__)
|
27
|
+
|
28
|
+
|
29
|
+
class Checkpoint(BaseModel):
|
30
|
+
|
31
|
+
"""Checkpoint model.
|
32
|
+
|
33
|
+
Args:
|
34
|
+
pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
|
35
|
+
|
36
|
+
"""
|
37
|
+
|
38
|
+
name: str
|
39
|
+
mode: int = 1
|
40
|
+
function: Optional[str] = None
|
41
|
+
df: Optional[str] = None
|
42
|
+
sample: Optional[float] = None
|
43
|
+
file: Optional[str] = None
|
44
|
+
location: int = -1
|
45
|
+
enabled: bool = True
|
46
|
+
|
47
|
+
@field_validator("name", mode="before")
|
48
|
+
@classmethod
|
49
|
+
def normalize(cls, name: str) -> str:
|
50
|
+
LOGGER.debug("Normalizing checkpoint name: '%s'", name)
|
51
|
+
normalized_name = checkpoint_name_utils.normalize_checkpoint_name(name)
|
52
|
+
LOGGER.debug("Checkpoint name was normalized to: '%s'", normalized_name)
|
53
|
+
is_valid_checkpoint_name = checkpoint_name_utils.is_valid_checkpoint_name(
|
54
|
+
normalized_name
|
55
|
+
)
|
56
|
+
if not is_valid_checkpoint_name:
|
57
|
+
error_msg = (
|
58
|
+
f"Invalid checkpoint name: {name} in checkpoints.json file. "
|
59
|
+
f"Checkpoint names must only contain alphanumeric characters, underscores and dollar signs."
|
60
|
+
)
|
61
|
+
LOGGER.error(error_msg)
|
62
|
+
raise Exception(error_msg)
|
63
|
+
|
64
|
+
return normalized_name
|
65
|
+
|
66
|
+
|
67
|
+
class Pipeline(BaseModel):
|
68
|
+
|
69
|
+
"""Pipeline model.
|
70
|
+
|
71
|
+
Args:
|
72
|
+
pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
|
73
|
+
|
74
|
+
"""
|
75
|
+
|
76
|
+
model_config = ConfigDict(
|
77
|
+
alias_generator=to_camel,
|
78
|
+
populate_by_name=True,
|
79
|
+
from_attributes=True,
|
80
|
+
)
|
81
|
+
|
82
|
+
entry_point: str
|
83
|
+
checkpoints: list[Checkpoint]
|
84
|
+
|
85
|
+
|
86
|
+
class Checkpoints(BaseModel):
|
87
|
+
|
88
|
+
"""Checkpoints model.
|
89
|
+
|
90
|
+
Args:
|
91
|
+
pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
|
92
|
+
|
93
|
+
Returns:
|
94
|
+
Checkpoints: An instance of the Checkpoints class
|
95
|
+
|
96
|
+
"""
|
97
|
+
|
98
|
+
type: str
|
99
|
+
pipelines: list[Pipeline]
|
100
|
+
|
101
|
+
# this dictionary holds the unpacked checkpoints from the different pipelines.
|
102
|
+
_checkpoints = {}
|
103
|
+
|
104
|
+
def _build_checkpoints_dict(self):
|
105
|
+
LOGGER.debug("Building checkpoints dictionary from pipelines.")
|
106
|
+
for pipeline in self.pipelines:
|
107
|
+
LOGGER.debug("Processing pipeline: '%s'", pipeline.entry_point)
|
108
|
+
for checkpoint in pipeline.checkpoints:
|
109
|
+
LOGGER.debug("Adding checkpoint: %s", checkpoint)
|
110
|
+
self._checkpoints[checkpoint.name] = checkpoint
|
111
|
+
|
112
|
+
def get_check_point(self, checkpoint_name: str) -> Checkpoint:
|
113
|
+
"""Get a checkpoint by its name.
|
114
|
+
|
115
|
+
Args:
|
116
|
+
checkpoint_name (str): The name of the checkpoint.
|
117
|
+
|
118
|
+
Returns:
|
119
|
+
Checkpoint: The checkpoint object if found, otherwise a new Checkpoint object
|
120
|
+
with the name set to the checkpoint_id.
|
121
|
+
|
122
|
+
"""
|
123
|
+
LOGGER.info("Fetching checkpoint: '%s'", checkpoint_name)
|
124
|
+
if not self._checkpoints:
|
125
|
+
LOGGER.debug("Checkpoints dictionary is empty, building it...")
|
126
|
+
self._build_checkpoints_dict()
|
127
|
+
|
128
|
+
checkpoint = self._checkpoints.get(checkpoint_name)
|
129
|
+
if len(self._checkpoints) == 0:
|
130
|
+
LOGGER.info(
|
131
|
+
"No checkpoints found, creating a new enabled checkpoint with name: '%s'",
|
132
|
+
checkpoint_name,
|
133
|
+
)
|
134
|
+
checkpoint = Checkpoint(name=checkpoint_name, enabled=True)
|
135
|
+
elif checkpoint is None:
|
136
|
+
LOGGER.info(
|
137
|
+
"Checkpoint not found, creating a new disabled checkpoint with name: '%s'",
|
138
|
+
checkpoint_name,
|
139
|
+
)
|
140
|
+
checkpoint = Checkpoint(name=checkpoint_name, enabled=False)
|
141
|
+
|
142
|
+
LOGGER.debug("Returning checkpoint: %s", checkpoint)
|
143
|
+
return checkpoint
|
144
|
+
|
145
|
+
def add_checkpoint(self, checkpoint: Checkpoint) -> None:
|
146
|
+
"""Add a checkpoint to the checkpoints' dictionary.
|
147
|
+
|
148
|
+
Args:
|
149
|
+
checkpoint (Checkpoint): The checkpoint object to add
|
150
|
+
|
151
|
+
"""
|
152
|
+
LOGGER.debug("Adding checkpoint: %s", checkpoint)
|
153
|
+
self._checkpoints[checkpoint.name] = checkpoint
|
154
|
+
LOGGER.info("Checkpoint '%s' added successfully.", checkpoint.name)
|
@@ -0,0 +1,23 @@
|
|
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
|
+
|
17
|
+
class Singleton(type):
|
18
|
+
_instances = {}
|
19
|
+
|
20
|
+
def __call__(cls, *args, **kwargs):
|
21
|
+
if cls not in cls._instances:
|
22
|
+
cls._instances[cls] = super().__call__(*args, **kwargs)
|
23
|
+
return cls._instances[cls]
|