gluekit 1.0.1.dev1__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.
- gluekit/__init__.py +7 -0
- gluekit/app.py +0 -0
- gluekit/cli.py +64 -0
- gluekit/commands/__init__.py +1 -0
- gluekit/commands/add.py +455 -0
- gluekit/commands/build.py +816 -0
- gluekit/commands/checkout.py +114 -0
- gluekit/commands/clone.py +516 -0
- gluekit/commands/config_commands.py +180 -0
- gluekit/commands/constants.py +47 -0
- gluekit/commands/convert.py +336 -0
- gluekit/commands/edit.py +1104 -0
- gluekit/commands/helpers.py +1068 -0
- gluekit/commands/init.py +798 -0
- gluekit/commands/list.py +16 -0
- gluekit/commands/local_commands.py +680 -0
- gluekit/commands/pull.py +374 -0
- gluekit/commands/push.py +251 -0
- gluekit/commands/remove.py +161 -0
- gluekit/commands/run.py +126 -0
- gluekit/commands/status.py +97 -0
- gluekit/commands/sync.py +97 -0
- gluekit/commands/update.py +104 -0
- gluekit/job_mgmt/__init__.py +0 -0
- gluekit/job_mgmt/glue_jobs.py +1323 -0
- gluekit/job_mgmt/magics.py +122 -0
- gluekit/job_mgmt/resources/__init__.py +0 -0
- gluekit/job_mgmt/resources/glue_job_schema.json +40341 -0
- gluekit/job_mgmt/resources/magic_map.json +83 -0
- gluekit/job_mgmt/schema.py +165 -0
- gluekit/local/__init__.py +6 -0
- gluekit/local/awsglue/__init__.py +1 -0
- gluekit/local/awsglue/context.py +30 -0
- gluekit/local/awsglue/job.py +9 -0
- gluekit/local/awsglue/utils.py +17 -0
- gluekit/local/local.py +434 -0
- gluekit/local/local_fixtures.py +337 -0
- gluekit/local/pyspark/__init__.py +7 -0
- gluekit/local/pyspark/context.py +31 -0
- gluekit/local/pyspark/sql/__init__.py +6 -0
- gluekit/local/pyspark/sql/session.py +29 -0
- gluekit-1.0.1.dev1.dist-info/METADATA +1176 -0
- gluekit-1.0.1.dev1.dist-info/RECORD +46 -0
- gluekit-1.0.1.dev1.dist-info/WHEEL +5 -0
- gluekit-1.0.1.dev1.dist-info/entry_points.txt +2 -0
- gluekit-1.0.1.dev1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from .schema import load_magic_map
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def script_location_dir(script_location: str) -> str:
|
|
10
|
+
if script_location.endswith(".py"):
|
|
11
|
+
return f"{script_location.rsplit('/', 1)[0]}/"
|
|
12
|
+
if script_location.endswith("/"):
|
|
13
|
+
return script_location
|
|
14
|
+
return f"{script_location}/"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def stringify_magic_value(value: Any) -> str:
|
|
18
|
+
if value is None:
|
|
19
|
+
return ""
|
|
20
|
+
if isinstance(value, bool):
|
|
21
|
+
return "true" if value else "false"
|
|
22
|
+
if isinstance(value, (list, tuple, set)):
|
|
23
|
+
return ",".join(str(item) for item in value if str(item).strip())
|
|
24
|
+
return str(value)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def normalize_config_args(config: dict[str, Any]) -> dict[str, Any]:
|
|
28
|
+
normalized: dict[str, Any] = {}
|
|
29
|
+
for key, value in config.items():
|
|
30
|
+
if key == "script_location" or key.startswith("--"):
|
|
31
|
+
normalized[key] = value
|
|
32
|
+
|
|
33
|
+
for key, value in config.items():
|
|
34
|
+
if key == "script_location" or key.startswith("--"):
|
|
35
|
+
continue
|
|
36
|
+
normalized.setdefault(f"--{key}", value)
|
|
37
|
+
|
|
38
|
+
return normalized
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_config_cell_source(config: dict[str, Any]) -> list[str]:
|
|
42
|
+
config_json = json.dumps(normalize_config_args(config), indent=4)
|
|
43
|
+
lines = ["%%configure \n"]
|
|
44
|
+
lines.extend([f"{line}\n" for line in config_json.splitlines()])
|
|
45
|
+
return lines
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _get_nested_value(config_data: dict[str, Any], field_path: str) -> Any:
|
|
49
|
+
current: Any = config_data
|
|
50
|
+
for part in field_path.split("."):
|
|
51
|
+
if not isinstance(current, dict):
|
|
52
|
+
return None
|
|
53
|
+
current = current.get(part)
|
|
54
|
+
if current is None:
|
|
55
|
+
return None
|
|
56
|
+
return current
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _format_value(value: Any, formatter: str) -> str:
|
|
60
|
+
if formatter == "script_location_dir":
|
|
61
|
+
text = stringify_magic_value(value).strip()
|
|
62
|
+
return script_location_dir(text) if text else ""
|
|
63
|
+
return stringify_magic_value(value).strip()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def build_magic_cell_sources(config_data: dict[str, Any]) -> list[list[str]]:
|
|
67
|
+
if not config_data:
|
|
68
|
+
return []
|
|
69
|
+
|
|
70
|
+
magic_map = load_magic_map()
|
|
71
|
+
mappings = magic_map.get("mappings", [])
|
|
72
|
+
section_order = magic_map.get("section_order", [])
|
|
73
|
+
stop_session_magic = magic_map.get("stop_session_magic", "%stop_session")
|
|
74
|
+
|
|
75
|
+
sections: dict[str, list[str]] = {section: [] for section in section_order}
|
|
76
|
+
configure: dict[str, Any] = {}
|
|
77
|
+
default_arguments = dict(config_data.get("DefaultArguments", {}) or {})
|
|
78
|
+
|
|
79
|
+
for mapping in mappings:
|
|
80
|
+
field_path = mapping["field_path"]
|
|
81
|
+
if field_path.startswith("DefaultArguments."):
|
|
82
|
+
arg_key = field_path.split(".", 1)[1]
|
|
83
|
+
raw_value = default_arguments.pop(arg_key, None)
|
|
84
|
+
else:
|
|
85
|
+
raw_value = _get_nested_value(config_data, field_path)
|
|
86
|
+
|
|
87
|
+
formatted_value = _format_value(raw_value, mapping.get("format", "string"))
|
|
88
|
+
if not formatted_value:
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
emit = mapping.get("emit", "magic")
|
|
92
|
+
if emit == "magic":
|
|
93
|
+
section = mapping["section"]
|
|
94
|
+
sections.setdefault(section, []).append(
|
|
95
|
+
f"{mapping['magic']} {formatted_value}\n"
|
|
96
|
+
)
|
|
97
|
+
elif emit == "configure":
|
|
98
|
+
configure[mapping["configure_key"]] = formatted_value
|
|
99
|
+
|
|
100
|
+
configure.update(default_arguments)
|
|
101
|
+
|
|
102
|
+
sources: list[list[str]] = [[f"{stop_session_magic}\n"]]
|
|
103
|
+
for section in section_order:
|
|
104
|
+
if section == "configure":
|
|
105
|
+
continue
|
|
106
|
+
lines = sections.get(section, [])
|
|
107
|
+
if lines:
|
|
108
|
+
sources.append(lines)
|
|
109
|
+
|
|
110
|
+
if configure:
|
|
111
|
+
sources.append(build_config_cell_source(configure))
|
|
112
|
+
|
|
113
|
+
return sources
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
__all__ = [
|
|
117
|
+
"build_config_cell_source",
|
|
118
|
+
"build_magic_cell_sources",
|
|
119
|
+
"normalize_config_args",
|
|
120
|
+
"script_location_dir",
|
|
121
|
+
"stringify_magic_value",
|
|
122
|
+
]
|
|
File without changes
|