snowpark-checkpoints-configuration 0.1.0rc3__py3-none-any.whl → 0.1.2__py3-none-any.whl

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.
@@ -0,0 +1,22 @@
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 snowflake.snowpark_checkpoints_configuration.checkpoint_metadata import (
17
+ CheckpointMetadata,
18
+ )
19
+
20
+ __all__ = [
21
+ "CheckpointMetadata",
22
+ ]
@@ -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.1.2"
@@ -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
+ import os
16
+
17
+ from snowflake.snowpark_checkpoints_configuration.model.checkpoints import (
18
+ Checkpoint,
19
+ Checkpoints,
20
+ )
21
+ from snowflake.snowpark_checkpoints_configuration.singleton import Singleton
22
+
23
+
24
+ class CheckpointMetadata(metaclass=Singleton):
25
+
26
+ """CheckpointMetadata class.
27
+
28
+ This is a singleton class that reads the checkpoints.json file
29
+ and provides an interface to get the checkpoint configuration.
30
+
31
+ Args:
32
+ metaclass (Singleton, optional): Defaults to Singleton.
33
+
34
+ """
35
+
36
+ def __init__(self, path: str = None):
37
+ directory = path if path is not None else os.getcwd()
38
+ self.checkpoint_model: Checkpoints = Checkpoints(type="", pipelines=[])
39
+ checkpoints_file = os.path.join(directory, "checkpoints.json")
40
+ if os.path.exists(checkpoints_file):
41
+ with open(checkpoints_file) as f:
42
+ try:
43
+ checkpoint_json = f.read()
44
+ self.checkpoint_model = Checkpoints.model_validate_json(
45
+ checkpoint_json
46
+ )
47
+ except Exception as e:
48
+ raise Exception(
49
+ f"Error reading checkpoints file: {checkpoints_file} \n {e}"
50
+ ) from None
51
+
52
+ def get_checkpoint(self, checkpoint_name: str) -> Checkpoint:
53
+ """Get a checkpoint by its name.
54
+
55
+ Args:
56
+ checkpoint_name (str): checkpoint name
57
+
58
+ Returns:
59
+ Checkpoint: Checkpoint configuration instance
60
+
61
+ """
62
+ 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) and underscores (_).
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,128 @@
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 pydantic import BaseModel, ConfigDict, field_validator
19
+ from pydantic.alias_generators import to_camel
20
+
21
+ from snowflake.snowpark_checkpoints_configuration import checkpoint_name_utils
22
+
23
+
24
+ class Checkpoint(BaseModel):
25
+
26
+ """Checkpoint model.
27
+
28
+ Args:
29
+ pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
30
+
31
+ """
32
+
33
+ name: str
34
+ mode: int = 1
35
+ function: Optional[str] = None
36
+ df: Optional[str] = None
37
+ sample: Optional[float] = None
38
+ file: Optional[str] = None
39
+ location: int = -1
40
+ enabled: bool = True
41
+
42
+ @field_validator("name", mode="before")
43
+ @classmethod
44
+ def normalize(cls, name: str) -> str:
45
+ normalized_name = checkpoint_name_utils.normalize_checkpoint_name(name)
46
+ is_valid_checkpoint_name = checkpoint_name_utils.is_valid_checkpoint_name(
47
+ normalized_name
48
+ )
49
+ if not is_valid_checkpoint_name:
50
+ raise Exception(
51
+ f"Invalid checkpoint name: {name} in checkpoints.json file. Checkpoint names must only contain "
52
+ f"alphanumeric characters and underscores."
53
+ )
54
+
55
+ return normalized_name
56
+
57
+
58
+ class Pipeline(BaseModel):
59
+
60
+ """Pipeline model.
61
+
62
+ Args:
63
+ pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
64
+
65
+ """
66
+
67
+ model_config = ConfigDict(
68
+ alias_generator=to_camel,
69
+ populate_by_name=True,
70
+ from_attributes=True,
71
+ )
72
+
73
+ entry_point: str
74
+ checkpoints: list[Checkpoint]
75
+
76
+
77
+ class Checkpoints(BaseModel):
78
+
79
+ """Checkpoints model.
80
+
81
+ Args:
82
+ pydantic.BaseModel (pydantic.BaseModel): pydantic BaseModel
83
+
84
+ Returns:
85
+ Checkpoints: An instance of the Checkpoints class
86
+
87
+ """
88
+
89
+ type: str
90
+ pipelines: list[Pipeline]
91
+
92
+ # this dictionary holds the unpacked checkpoints from the different pipelines.
93
+ _checkpoints = {}
94
+
95
+ def _build_checkpoints_dict(self):
96
+ for pipeline in self.pipelines:
97
+ for checkpoint in pipeline.checkpoints:
98
+ self._checkpoints[checkpoint.name] = checkpoint
99
+
100
+ def get_check_point(self, checkpoint_name: str) -> Checkpoint:
101
+ """Get a checkpoint by its name.
102
+
103
+ Args:
104
+ checkpoint_name (str): The name of the checkpoint.
105
+
106
+ Returns:
107
+ Checkpoint: The checkpoint object if found, otherwise a new Checkpoint object
108
+ with the name set to the checkpoint_id.
109
+
110
+ """
111
+ if not self._checkpoints:
112
+ self._build_checkpoints_dict()
113
+
114
+ checkpoint = self._checkpoints.get(checkpoint_name)
115
+ if len(self._checkpoints) == 0:
116
+ checkpoint = Checkpoint(name=checkpoint_name, enabled=True)
117
+ elif checkpoint is None:
118
+ checkpoint = Checkpoint(name=checkpoint_name, enabled=False)
119
+ return checkpoint
120
+
121
+ def add_checkpoint(self, checkpoint: Checkpoint) -> None:
122
+ """Add a checkpoint to the checkpoints' dictionary.
123
+
124
+ Args:.
125
+ checkpoint (Checkpoint): The checkpoint object to add
126
+
127
+ """
128
+ self._checkpoints[checkpoint.name] = checkpoint
@@ -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]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snowpark-checkpoints-configuration
3
- Version: 0.1.0rc3
3
+ Version: 0.1.2
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/
@@ -27,7 +27,7 @@ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
27
27
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
28
  Requires-Python: <3.12,>=3.9
29
29
  Requires-Dist: pydantic>=1.8.2
30
- Requires-Dist: snowflake-snowpark-python
30
+ Requires-Dist: snowflake-snowpark-python==1.26.0
31
31
  Provides-Extra: development
32
32
  Requires-Dist: coverage>=7.6.7; extra == 'development'
33
33
  Requires-Dist: hatchling==1.25.0; extra == 'development'
@@ -42,12 +42,8 @@ Description-Content-Type: text/markdown
42
42
  # snowpark-checkpoints-configuration
43
43
 
44
44
  ---
45
- **NOTE**
46
-
47
- This package is on Private Preview.
48
-
45
+ ##### This package is on Public Preview.
49
46
  ---
50
-
51
47
  **snowpark-checkpoints-configuration** is a module for loading `checkpoint.json` and provides a model.
52
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.
53
49
 
@@ -0,0 +1,10 @@
1
+ snowflake/snowpark_checkpoints_configuration/__init__.py,sha256=ILSUJf0losOC1vPMWITsK0zv5NjccBy8wlgQd5-YJlU,756
2
+ snowflake/snowpark_checkpoints_configuration/__version__.py,sha256=qNTBwMUtsLu0okWXwrUvl9AohG1pXd4kalMC8v10gHM,632
3
+ snowflake/snowpark_checkpoints_configuration/checkpoint_metadata.py,sha256=6V968CUQcYu0CnSHnJmP3Ccgmekfyfanh9JinH7UGOA,2207
4
+ snowflake/snowpark_checkpoints_configuration/checkpoint_name_utils.py,sha256=WExQaZ4oL4otDCtM8kyGbf0Gn_v1a-tzM5j1p0wVDVg,1767
5
+ snowflake/snowpark_checkpoints_configuration/singleton.py,sha256=7AgIHQBXVRvPBBCkmBplzkdrrm-xVWf_N8svzA2vF8E,836
6
+ snowflake/snowpark_checkpoints_configuration/model/checkpoints.py,sha256=5OJfAU3oyQZoffOD01Pr1aNlghSKqZ6L-JAhggC0T5Y,3688
7
+ snowpark_checkpoints_configuration-0.1.2.dist-info/METADATA,sha256=B0Mi9vZ_0cQQSkqIPO_RM-NVQ2bgsFZEgZh38UBBMOY,2724
8
+ snowpark_checkpoints_configuration-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ snowpark_checkpoints_configuration-0.1.2.dist-info/licenses/LICENSE,sha256=DVQuDIgE45qn836wDaWnYhSdxoLXgpRRKH4RuTjpRZQ,10174
10
+ snowpark_checkpoints_configuration-0.1.2.dist-info/RECORD,,
@@ -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.
@@ -1,4 +0,0 @@
1
- snowpark_checkpoints_configuration-0.1.0rc3.dist-info/METADATA,sha256=vV9CjHZ7EHjV7Kjuee0EhR8ndOXRo-KtlzJraH_LVNw,2726
2
- snowpark_checkpoints_configuration-0.1.0rc3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
3
- snowpark_checkpoints_configuration-0.1.0rc3.dist-info/licenses/LICENSE,sha256=pmjhbh6uVhV5MBXOlou_UZgFP7CYVQITkCCdvfcS5lY,11340
4
- snowpark_checkpoints_configuration-0.1.0rc3.dist-info/RECORD,,