valediction 1.0.0__py3-none-any.whl → 1.0.3__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.
valediction/exceptions.py CHANGED
@@ -1,22 +1,22 @@
1
- class DataDictionaryError(Exception):
2
- def __init__(self, message: str = "A DataDictionaryError has occurred"):
3
- super().__init__(message)
4
- self.message = message
5
-
6
-
7
- class DataDictionaryImportError(Exception):
8
- def __init__(self, message: str = "A DataDictionaryImportError has occurred"):
9
- super().__init__(message)
10
- self.message = message
11
-
12
-
13
- class DataDictionaryExportError(Exception):
14
- def __init__(self, message: str = "A DataDictionaryExportError has occurred"):
15
- super().__init__(message)
16
- self.message = message
17
-
18
-
19
- class DataIntegrityError(Exception):
20
- def __init__(self, message: str = "A DataIntegrityError has occurred"):
21
- super().__init__(message)
22
- self.message = message
1
+ class DataDictionaryError(Exception):
2
+ def __init__(self, message: str = "A DataDictionaryError has occurred"):
3
+ super().__init__(message)
4
+ self.message = message
5
+
6
+
7
+ class DataDictionaryImportError(Exception):
8
+ def __init__(self, message: str = "A DataDictionaryImportError has occurred"):
9
+ super().__init__(message)
10
+ self.message = message
11
+
12
+
13
+ class DataDictionaryExportError(Exception):
14
+ def __init__(self, message: str = "A DataDictionaryExportError has occurred"):
15
+ super().__init__(message)
16
+ self.message = message
17
+
18
+
19
+ class DataIntegrityError(Exception):
20
+ def __init__(self, message: str = "A DataIntegrityError has occurred"):
21
+ super().__init__(message)
22
+ self.message = message
valediction/integrity.py CHANGED
@@ -1,97 +1,97 @@
1
- import re
2
- from pathlib import Path
3
- from re import Pattern
4
-
5
- from valediction.data_types.data_types import DataType
6
- from valediction.support import list_as_bullets
7
-
8
- ROOT = Path(__file__).resolve().parent
9
- DIR_DICTIONARY = ROOT / "dictionary"
10
- TEMPLATE_DATA_DICTIONARY_PATH = (
11
- DIR_DICTIONARY / "template" / "Project - Data Dictionary.xltx"
12
- )
13
-
14
-
15
- class Config:
16
- def __init__(self):
17
- self.template_data_dictionary_path: Path = TEMPLATE_DATA_DICTIONARY_PATH
18
- self.max_table_name_length: int = 63
19
- self.max_column_name_length: int = 30
20
- self.max_primary_keys: int = 7
21
- self.invalid_name_pattern: str | Pattern = re.compile(r"[^A-Z0-9_]")
22
- self.null_values: list[str] = ["", "null", "none"]
23
- self.forbidden_characters: list[str] = []
24
- self.date_formats: dict[str, DataType] = {
25
- "%Y-%m-%d": DataType.DATE,
26
- "%Y/%m/%d": DataType.DATE,
27
- "%d/%m/%Y": DataType.DATE,
28
- "%d-%m-%Y": DataType.DATE,
29
- "%m/%d/%Y": DataType.DATE,
30
- "%m-%d-%Y": DataType.DATE,
31
- "%Y-%m-%d %H:%M:%S": DataType.DATETIME,
32
- "%Y-%m-%d %H:%M": DataType.DATETIME,
33
- "%d/%m/%Y %H:%M:%S": DataType.DATETIME,
34
- "%d/%m/%Y %H:%M": DataType.DATETIME,
35
- "%m/%d/%Y %H:%M:%S": DataType.DATETIME,
36
- "%Y-%m-%dT%H:%M:%S": DataType.DATETIME,
37
- "%Y-%m-%dT%H:%M:%S.%f": DataType.DATETIME,
38
- "%Y-%m-%dT%H:%M:%S%z": DataType.DATETIME,
39
- "%Y-%m-%dT%H:%M:%S.%f%z": DataType.DATETIME,
40
- "%Y-%m-%dT%H:%M:%SZ": DataType.DATETIME,
41
- "%Y-%m-%dT%H:%M:%S.%fZ": DataType.DATETIME,
42
- }
43
- self.enforce_no_null_columns: bool = True
44
- self.enforce_primary_keys: bool = True
45
-
46
- def __repr__(self):
47
- date_list = list_as_bullets(
48
- elements=[f"{k}: {v.name} " for k, v in self.date_formats.items()],
49
- bullet="\n - ",
50
- )
51
- return (
52
- f"Config(\n"
53
- f"Dictionary Settings:\n"
54
- f" - template_data_dictionary_path='{self.template_data_dictionary_path}'\n"
55
- f" - max_table_name_length={self.max_table_name_length}\n"
56
- f" - max_column_name_length={self.max_column_name_length}\n"
57
- f" - max_primary_keys={self.max_primary_keys}\n"
58
- f" - invalid_name_pattern={self.invalid_name_pattern}\n"
59
- f"Data Settings:\n"
60
- f" - default_null_values={self.null_values}\n"
61
- f" - forbidden_characters={self.forbidden_characters}\n"
62
- f" - date_formats=[{date_list}\n ]\n"
63
- ")"
64
- )
65
-
66
- # Context Wrapper With Reset
67
- def __enter__(self):
68
- global default_config
69
- default_config = self
70
- return self
71
-
72
- def __exit__(self, exc_type, exc_value, traceback):
73
- global default_config
74
- default_config = Config()
75
-
76
-
77
- default_config: Config = None
78
-
79
-
80
- def get_config() -> Config:
81
- """Gets the current `default_config` instance. Changing attributes will set them
82
- globally.
83
-
84
- Returns:
85
- Config: The current default configuration.
86
- """
87
- global default_config
88
- return default_config
89
-
90
-
91
- def reset_default_config() -> None:
92
- """Resets `default_config` settings globally to original defaults."""
93
- global default_config
94
- default_config = Config()
95
-
96
-
97
- reset_default_config()
1
+ import re
2
+ from pathlib import Path
3
+ from re import Pattern
4
+
5
+ from valediction.data_types.data_types import DataType
6
+ from valediction.support import list_as_bullets
7
+
8
+ ROOT = Path(__file__).resolve().parent
9
+ DIR_DICTIONARY = ROOT / "dictionary"
10
+ TEMPLATE_DATA_DICTIONARY_PATH = (
11
+ DIR_DICTIONARY / "template" / "PROJECT - Data Dictionary.xltx"
12
+ )
13
+
14
+
15
+ class Config:
16
+ def __init__(self):
17
+ self.template_data_dictionary_path: Path = TEMPLATE_DATA_DICTIONARY_PATH
18
+ self.max_table_name_length: int = 63
19
+ self.max_column_name_length: int = 30
20
+ self.max_primary_keys: int = 7
21
+ self.invalid_name_pattern: str | Pattern = re.compile(r"[^A-Z0-9_]")
22
+ self.null_values: list[str] = ["", "null", "none"]
23
+ self.forbidden_characters: list[str] = []
24
+ self.date_formats: dict[str, DataType] = {
25
+ "%Y-%m-%d": DataType.DATE,
26
+ "%Y/%m/%d": DataType.DATE,
27
+ "%d/%m/%Y": DataType.DATE,
28
+ "%d-%m-%Y": DataType.DATE,
29
+ "%m/%d/%Y": DataType.DATE,
30
+ "%m-%d-%Y": DataType.DATE,
31
+ "%Y-%m-%d %H:%M:%S": DataType.DATETIME,
32
+ "%Y-%m-%d %H:%M": DataType.DATETIME,
33
+ "%d/%m/%Y %H:%M:%S": DataType.DATETIME,
34
+ "%d/%m/%Y %H:%M": DataType.DATETIME,
35
+ "%m/%d/%Y %H:%M:%S": DataType.DATETIME,
36
+ "%Y-%m-%dT%H:%M:%S": DataType.DATETIME,
37
+ "%Y-%m-%dT%H:%M:%S.%f": DataType.DATETIME,
38
+ "%Y-%m-%dT%H:%M:%S%z": DataType.DATETIME,
39
+ "%Y-%m-%dT%H:%M:%S.%f%z": DataType.DATETIME,
40
+ "%Y-%m-%dT%H:%M:%SZ": DataType.DATETIME,
41
+ "%Y-%m-%dT%H:%M:%S.%fZ": DataType.DATETIME,
42
+ }
43
+ self.enforce_no_null_columns: bool = True
44
+ self.enforce_primary_keys: bool = True
45
+
46
+ def __repr__(self):
47
+ date_list = list_as_bullets(
48
+ elements=[f"{k}: {v.name} " for k, v in self.date_formats.items()],
49
+ bullet="\n - ",
50
+ )
51
+ return (
52
+ f"Config(\n"
53
+ f"Dictionary Settings:\n"
54
+ f" - template_data_dictionary_path='{self.template_data_dictionary_path}'\n"
55
+ f" - max_table_name_length={self.max_table_name_length}\n"
56
+ f" - max_column_name_length={self.max_column_name_length}\n"
57
+ f" - max_primary_keys={self.max_primary_keys}\n"
58
+ f" - invalid_name_pattern={self.invalid_name_pattern}\n"
59
+ f"Data Settings:\n"
60
+ f" - default_null_values={self.null_values}\n"
61
+ f" - forbidden_characters={self.forbidden_characters}\n"
62
+ f" - date_formats=[{date_list}\n ]\n"
63
+ ")"
64
+ )
65
+
66
+ # Context Wrapper With Reset
67
+ def __enter__(self):
68
+ global default_config
69
+ default_config = self
70
+ return self
71
+
72
+ def __exit__(self, exc_type, exc_value, traceback):
73
+ global default_config
74
+ default_config = Config()
75
+
76
+
77
+ default_config: Config = None
78
+
79
+
80
+ def get_config() -> Config:
81
+ """Gets the current `default_config` instance. Changing attributes will set them
82
+ globally.
83
+
84
+ Returns:
85
+ Config: The current default configuration.
86
+ """
87
+ global default_config
88
+ return default_config
89
+
90
+
91
+ def reset_default_config() -> None:
92
+ """Resets `default_config` settings globally to original defaults."""
93
+ global default_config
94
+ default_config = Config()
95
+
96
+
97
+ reset_default_config()