python-to-yaml-dag-converter-mwaa-serverless 0.0.1rc1__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.
Files changed (51) hide show
  1. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/.gitignore +23 -0
  2. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/LICENSE +175 -0
  3. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/NOTICE +1 -0
  4. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/PKG-INFO +89 -0
  5. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/README.md +62 -0
  6. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/__init__.py +1 -0
  7. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/cleanup.py +128 -0
  8. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/cli.py +37 -0
  9. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/console_config.py +61 -0
  10. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/__init__.py +1 -0
  11. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/converter.py +56 -0
  12. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/default_args.py +17 -0
  13. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/dynamic_mapping.py +63 -0
  14. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/exceptions.py +18 -0
  15. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/operators/__init__.py +1 -0
  16. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/operators/python_decorator.py +79 -0
  17. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/schedule.py +22 -0
  18. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion/tasks.py +149 -0
  19. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/conversion_manager.py +160 -0
  20. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/dag_comparator.py +218 -0
  21. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/dagbag.py +29 -0
  22. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/py.typed +1 -0
  23. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/schema_parser.py +124 -0
  24. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/static_validator.py +84 -0
  25. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/taskflow_parser.py +42 -0
  26. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/validator_schema.yaml +1056 -0
  27. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/yaml_format.py +36 -0
  28. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/dag_converter/yaml_validator.py +79 -0
  29. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/pyproject.toml +105 -0
  30. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/__init__.py +0 -0
  31. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/operators/test_python_decorator.py +123 -0
  32. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/test_conversion_manager.py +340 -0
  33. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/test_converter.py +52 -0
  34. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/test_default_args.py +61 -0
  35. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/test_dynamic_mapping.py +127 -0
  36. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/conversion/test_tasks.py +256 -0
  37. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/aws_s3.py +114 -0
  38. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/dagfactory_test_dag.py +9 -0
  39. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/invalid_test_dag.yaml +4 -0
  40. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/multiple_dags_test.py +30 -0
  41. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/python_operator_test.py +29 -0
  42. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/simple_test_dag.py +8 -0
  43. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/samples/valid_test_dag.yaml +15 -0
  44. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_cli.py +173 -0
  45. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_dag_comparator.py +152 -0
  46. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_dagbag.py +118 -0
  47. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_schema_parser.py +237 -0
  48. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_static_validator.py +204 -0
  49. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_taskflow_parser.py +150 -0
  50. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_yaml_format.py +55 -0
  51. python_to_yaml_dag_converter_mwaa_serverless-0.0.1rc1/tests/unit/test_yaml_validator.py +135 -0
@@ -0,0 +1,23 @@
1
+ # Python-generated files
2
+ *__pycache__*
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Test
10
+ .coverage
11
+ .pytest_cache
12
+
13
+ # Ruff
14
+ .ruff_cache
15
+
16
+ # Virtual environments
17
+ .venv
18
+
19
+ # Python version
20
+ .python-version
21
+
22
+ # VSCode
23
+ .vscode
@@ -0,0 +1,175 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
@@ -0,0 +1 @@
1
+ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-to-yaml-dag-converter-mwaa-serverless
3
+ Version: 0.0.1rc1
4
+ Summary: CLI tool that converts Python airflow Dags to YAML Dags for use with dagfactory
5
+ Project-URL: Source, https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless
6
+ Project-URL: Repository, https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless.git
7
+ Project-URL: Issues, https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless/issues
8
+ Project-URL: Changelog, https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless/blob/main/README.md
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Framework :: Apache Airflow
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Requires-Python: >=3.11
19
+ Requires-Dist: apache-airflow-providers-amazon==9.10.0
20
+ Requires-Dist: apache-airflow-providers-cncf-kubernetes==10.6.1
21
+ Requires-Dist: apache-airflow==3.0.6
22
+ Requires-Dist: boto3>=1.37.3
23
+ Requires-Dist: dag-factory==1.0.0
24
+ Requires-Dist: fastapi[standard]<0.118
25
+ Requires-Dist: rich<15.0.0,>=13.7.1
26
+ Description-Content-Type: text/markdown
27
+
28
+ ## Python to Yaml Dag Converter for MWAA Serverless
29
+
30
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
31
+
32
+ Python to Yaml Dag Converter for MWAA Serverless is a command-line tool for converting [Apache Airflow®](https://airflow.apache.org) Dags written in Python to [dag-factory](https://github.com/astronomer/dag-factory) compatible Dags written in YAML.
33
+
34
+ ## Prerequisites
35
+
36
+ - Python 3.11+
37
+
38
+ ## Benefits
39
+ - Onboard existing Python Dags to declarative YAML
40
+ - Ensures compatibility with DagFactory 1.0
41
+ - Convert Python Dags to MWAA Serverless compatible YAML
42
+ - Upload converted YAML to S3
43
+
44
+ ## ⚡ Quick Start
45
+
46
+ ### **Step 1**: Install
47
+ ```
48
+ pip install python-to-yaml-dag-converter-mwaa-serverless
49
+ ```
50
+
51
+ ### **Step 2**: Use
52
+ ```
53
+ dag-converter convert <python-dag-file>
54
+ ```
55
+ Call with the `--help` flag for more options
56
+
57
+ ### **Step 3**: Review
58
+ Review the converted Dags in the `output_yaml` folder in the current directory
59
+
60
+ ## Options
61
+ * `--help` Show help message and exit
62
+ * `--output`: PATH Path to output converted YAML Dag(s) to [default: output_yaml]
63
+ * `--bucket`: TEXT S3 bucket to upload converted Dags to. Uses local AWS credentials
64
+ * `--validate/--no-validate`: Validate the output YAML using DagFactory
65
+ * `--debug/--no-debug` Enable logging DagBag objects to .initial_task_attributes before and after conversion
66
+
67
+ ## Limitations
68
+ * Only AWS operators and AWS provider packages are supported
69
+ * Behavior that is not supported in `dag-factory` will not be converted
70
+ * Dynamic task mapping conversion is not supported
71
+
72
+ ## Examples
73
+ * See supported [examples](https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless/blob/main/dev/integ_test/python_test_folder/supported)
74
+ * Try one out
75
+ ```
76
+ dag-converter convert airflow_s3.py
77
+ ```
78
+
79
+ ## Contributing and Bug Reporting
80
+
81
+ See [CONTRIBUTING](CONTRIBUTING.md#contributing-guidelines) for more information.
82
+
83
+ ## Security
84
+
85
+ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
86
+
87
+ ## License
88
+
89
+ This project is licensed under the Apache-2.0 License.
@@ -0,0 +1,62 @@
1
+ ## Python to Yaml Dag Converter for MWAA Serverless
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+
5
+ Python to Yaml Dag Converter for MWAA Serverless is a command-line tool for converting [Apache Airflow®](https://airflow.apache.org) Dags written in Python to [dag-factory](https://github.com/astronomer/dag-factory) compatible Dags written in YAML.
6
+
7
+ ## Prerequisites
8
+
9
+ - Python 3.11+
10
+
11
+ ## Benefits
12
+ - Onboard existing Python Dags to declarative YAML
13
+ - Ensures compatibility with DagFactory 1.0
14
+ - Convert Python Dags to MWAA Serverless compatible YAML
15
+ - Upload converted YAML to S3
16
+
17
+ ## ⚡ Quick Start
18
+
19
+ ### **Step 1**: Install
20
+ ```
21
+ pip install python-to-yaml-dag-converter-mwaa-serverless
22
+ ```
23
+
24
+ ### **Step 2**: Use
25
+ ```
26
+ dag-converter convert <python-dag-file>
27
+ ```
28
+ Call with the `--help` flag for more options
29
+
30
+ ### **Step 3**: Review
31
+ Review the converted Dags in the `output_yaml` folder in the current directory
32
+
33
+ ## Options
34
+ * `--help` Show help message and exit
35
+ * `--output`: PATH Path to output converted YAML Dag(s) to [default: output_yaml]
36
+ * `--bucket`: TEXT S3 bucket to upload converted Dags to. Uses local AWS credentials
37
+ * `--validate/--no-validate`: Validate the output YAML using DagFactory
38
+ * `--debug/--no-debug` Enable logging DagBag objects to .initial_task_attributes before and after conversion
39
+
40
+ ## Limitations
41
+ * Only AWS operators and AWS provider packages are supported
42
+ * Behavior that is not supported in `dag-factory` will not be converted
43
+ * Dynamic task mapping conversion is not supported
44
+
45
+ ## Examples
46
+ * See supported [examples](https://github.com/awslabs/python-to-yaml-dag-converter-mwaa-serverless/blob/main/dev/integ_test/python_test_folder/supported)
47
+ * Try one out
48
+ ```
49
+ dag-converter convert airflow_s3.py
50
+ ```
51
+
52
+ ## Contributing and Bug Reporting
53
+
54
+ See [CONTRIBUTING](CONTRIBUTING.md#contributing-guidelines) for more information.
55
+
56
+ ## Security
57
+
58
+ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
59
+
60
+ ## License
61
+
62
+ This project is licensed under the Apache-2.0 License.
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1rc1"
@@ -0,0 +1,128 @@
1
+ """Module for cleaning up data structures before serialization."""
2
+
3
+ from enum import Enum
4
+ import re
5
+ from datetime import date, datetime, time, timedelta
6
+ from typing import Any
7
+
8
+ from airflow.sdk.definitions.param import ParamsDict
9
+ from airflow.sdk.definitions.xcom_arg import PlainXComArg
10
+
11
+
12
+ def get_cleanup_dag(obj: Any) -> Any:
13
+ """Recursively clean data structure of non-serializable objects.
14
+
15
+ Args:
16
+ obj: Any Python object to clean up
17
+
18
+ Returns:
19
+ Cleaned up version of the object suitable for YAML serialization
20
+
21
+ The function handles:
22
+ - Encoded values with __var and __type
23
+ - Basic Python containers (dict, list, tuple, set)
24
+ - Custom objects (converted to Dag factory YAML object format)
25
+ - Enums (converted to Dag factory YAML object format)
26
+ - Date/time objects (converted to custom Python object)
27
+ - None values
28
+ - Nested structures
29
+ """
30
+ if obj is None:
31
+ return None
32
+
33
+ if isinstance(obj, str) and "xcom_pull" in obj:
34
+ pattern = r',\s*dag_id=[\'"][^\'"]*[\'"]'
35
+ print("xcom arg:" + str(obj))
36
+ return re.sub(pattern, "", obj)
37
+
38
+ if isinstance(obj, str):
39
+ return str(obj)
40
+
41
+ if is_primitive(obj):
42
+ return obj
43
+
44
+ if isinstance(obj, PlainXComArg):
45
+ pattern = r',\s*dag_id=[\'"][^\'"]*[\'"]'
46
+ # Remove the dag_id parameter
47
+ print("plain xcom arg:" + str(obj))
48
+ return re.sub(pattern, "", str(obj))
49
+
50
+ if isinstance(obj, ParamsDict):
51
+ return obj.dump()
52
+
53
+ if isinstance(obj, Enum):
54
+ return {
55
+ "__type__": obj.__module__ + "." + obj.__class__.__name__,
56
+ "__args__": [obj.value]
57
+ }
58
+
59
+ if isinstance(obj, dict):
60
+ # Handle encoded values
61
+ if "__var" in obj and "__type" in obj:
62
+ # Special handling for None
63
+ if obj["__var"] is None:
64
+ return None
65
+ return get_cleanup_dag(obj["__var"])
66
+
67
+ # Regular dictionary
68
+ return {k: get_cleanup_dag(v) for k, v in obj.items()}
69
+
70
+ if isinstance(obj, list | tuple | set):
71
+ return [get_cleanup_dag(item) for item in obj]
72
+
73
+ if isinstance(obj, datetime):
74
+ custom_object = {
75
+ "__type__": "datetime.datetime",
76
+ "year": obj.year,
77
+ "month": obj.month,
78
+ "day": obj.day,
79
+ "hour": obj.hour,
80
+ "minute": obj.minute,
81
+ "second": obj.second,
82
+ "microsecond": obj.microsecond
83
+ }
84
+ return { key: value for key, value in custom_object.items() if value }
85
+
86
+ if isinstance(obj, date):
87
+ return obj.isoformat()
88
+
89
+ if isinstance(obj, time):
90
+ return obj.strftime("%H:%M:%S")
91
+
92
+ if isinstance(obj, timedelta):
93
+ return {
94
+ "__type__": "datetime.timedelta",
95
+ "seconds": obj.total_seconds()
96
+ }
97
+
98
+ if callable(obj) and hasattr(obj, "__name__"):
99
+ function_name = obj.__name__
100
+
101
+ if hasattr(obj, "__module__"):
102
+ module_name = obj.__module__
103
+ # Clean up unusual prefixes and extract actual module name
104
+ if "unusual_prefix_" in module_name:
105
+ parts = module_name.split("_")
106
+ input_file_name = parts[3]
107
+ for i in range(4, len(parts)):
108
+ input_file_name += f"_{parts[i]}"
109
+ else:
110
+ input_file_name = module_name
111
+ else:
112
+ input_file_name = "unknown"
113
+
114
+ return f"{input_file_name}.{function_name}"
115
+
116
+ if hasattr(obj, "__dict__"): # Handle custom objects
117
+ return {
118
+ "__type__": obj.__module__ + "." + obj.__class__.__name__,
119
+ **get_cleanup_dag(obj.__dict__)
120
+ }
121
+
122
+ return str(obj)
123
+
124
+
125
+ def is_primitive(obj: Any) -> bool:
126
+ """Check if an object is NOT a primitive type."""
127
+ primitive_types = (int, float, bool, bytes, type(None))
128
+ return isinstance(obj, primitive_types)
@@ -0,0 +1,37 @@
1
+ from pathlib import Path
2
+ from typing import Annotated
3
+
4
+ import typer
5
+
6
+ app = typer.Typer()
7
+ app.command()
8
+
9
+
10
+ @app.callback()
11
+ def callback():
12
+ """
13
+ CLI tool for converting Python airflow Dags to YAML Dags for DagFactory
14
+ """
15
+
16
+
17
+ @app.command()
18
+ def convert(
19
+ input_path: Annotated[Path, typer.Argument(help="Path containing Python Dag(s) to convert")],
20
+ output: Annotated[Path, typer.Option(help="Path to output converted YAML Dag(s) to")] = Path("output_yaml/"),
21
+ bucket: Annotated[str, typer.Option(help="S3 bucket to upload converted Dags to. Uses local AWS credentials")] = "",
22
+ validate: Annotated[bool, typer.Option(help="Validate the output YAML using DagFactory")] = True,
23
+ debug: Annotated[bool, typer.Option(help="Enable logging DagBag objects to .initial_task_attributes before and after conversion")] = False,
24
+ ):
25
+ """
26
+ Loads Python Dags from input and converts them to YAML Dags.
27
+ """
28
+ from dag_converter.conversion_manager import ConversionManager
29
+
30
+ conversion_manager = ConversionManager(s3_bucket=bucket)
31
+ conversion_manager.start_conversion_process(
32
+ dag_file_path=input_path, output_dir=output, user_validate=validate, debug=debug
33
+ )
34
+
35
+
36
+ if __name__ == "__main__":
37
+ app()
@@ -0,0 +1,61 @@
1
+ from rich.console import Console
2
+ from rich.theme import Theme
3
+
4
+ # Define custom theme for different message types
5
+ custom_theme = Theme(
6
+ {
7
+ "info": "cyan",
8
+ "warning": "yellow",
9
+ "error": "bold red",
10
+ "success": "bold green",
11
+ "debug": "dim cyan",
12
+ "progress": "magenta",
13
+ }
14
+ )
15
+
16
+ # Global console instance
17
+ _console = Console(
18
+ theme=custom_theme,
19
+ )
20
+
21
+
22
+ def get_console() -> Console:
23
+ """
24
+ Get the global console instance.
25
+
26
+ Returns:
27
+ Console instance configured with custom theme
28
+ """
29
+
30
+ return _console
31
+
32
+
33
+ # Convenience functions for different log levels
34
+ def print_info(message: str, **kwargs) -> None:
35
+ """Print info message with cyan styling."""
36
+ get_console().print(message, style="info", **kwargs)
37
+
38
+
39
+ def print_warning(message: str, **kwargs) -> None:
40
+ """Print warning message with yellow styling."""
41
+ get_console().print(message, style="warning", **kwargs)
42
+
43
+
44
+ def print_error(message: str, **kwargs) -> None:
45
+ """Print error message with bold red styling."""
46
+ get_console().print(message, style="error", **kwargs)
47
+
48
+
49
+ def print_success(message: str, **kwargs) -> None:
50
+ """Print success message with bold green styling."""
51
+ get_console().print(message, style="success", **kwargs)
52
+
53
+
54
+ def print_debug(message: str, **kwargs) -> None:
55
+ """Print debug message with dim cyan styling."""
56
+ get_console().print(message, style="debug", **kwargs)
57
+
58
+
59
+ def print_progress(message: str, **kwargs) -> None:
60
+ """Print progress message with magenta styling."""
61
+ get_console().print(message, style="progress", **kwargs)
@@ -0,0 +1 @@
1
+ """Conversion module for dag_converter."""
@@ -0,0 +1,56 @@
1
+ from pathlib import Path
2
+
3
+ from airflow.models.dag import DAG
4
+
5
+ from dag_converter.conversion.default_args import convert_default_args
6
+ from dag_converter.conversion.schedule import convert_schedule
7
+ from dag_converter.conversion.tasks import convert_tasks
8
+ from dag_converter.schema_parser import ArgumentValidator
9
+ from dag_converter.taskflow_parser import TaskFlowAnalyzer
10
+
11
+
12
+ def get_converted_format(
13
+ taskflow_parser: TaskFlowAnalyzer, dag_object: DAG, dag_file_path: Path, validator: ArgumentValidator
14
+ ):
15
+ """Return the DagFactory-compatible format of the Dag in dictionary format"""
16
+ dag_id = getattr(dag_object, "_dag_id", None)
17
+ # Taskflow may store dag_id as internal parameter with leading '_'
18
+ if not dag_id:
19
+ dag_id = getattr(dag_object, "dag_id", None)
20
+
21
+ # Extract values from the Objects in the 'params' field
22
+ params_obj = getattr(dag_object, "params", None)
23
+ params_dict = {}
24
+ if params_obj and hasattr(params_obj, "items"):
25
+ for key, param in params_obj.items():
26
+ if hasattr(param, "value"):
27
+ params_dict[key] = param.value
28
+ else:
29
+ params_dict[key] = param
30
+
31
+ # Convert Dag information
32
+ converted_dag = {
33
+ dag_id: {
34
+ "dag_id": dag_id,
35
+ "params": params_dict,
36
+ "default_args": convert_default_args(getattr(dag_object, "default_args", {}), validator),
37
+ "schedule": convert_schedule(dag_object),
38
+ "tasks": {},
39
+ }
40
+ }
41
+
42
+ # Filter out extraneous Dag fields
43
+ for key in dir(dag_object):
44
+ value = getattr(dag_object, key, None)
45
+ # Only keep non-internal fields and valid fields
46
+ if key not in converted_dag[dag_id] and not key.startswith("_") and validator.validate_field("dag", key, value):
47
+ # Skip keywords that were not set by user
48
+ if value is None:
49
+ pass
50
+ else:
51
+ converted_dag[dag_id][key] = value
52
+
53
+ # Convert tasks
54
+ converted_dag[dag_id]["tasks"] = convert_tasks(taskflow_parser, dag_object, dag_file_path, validator)
55
+
56
+ return converted_dag
@@ -0,0 +1,17 @@
1
+ from typing import Any
2
+
3
+ from dag_converter.conversion.exceptions import InvalidDefaultArg
4
+ from dag_converter.schema_parser import ArgumentValidator
5
+
6
+
7
+ def convert_default_args(args: dict[str, Any], validator: ArgumentValidator) -> dict[str, Any]:
8
+ converted = {}
9
+
10
+ for key, value in args.items():
11
+ # Validate default args
12
+ if validator.validate_field("dag", "default_args", key):
13
+ converted[key] = value
14
+ else:
15
+ raise InvalidDefaultArg(f"Default Argument '{key}' is not supported")
16
+
17
+ return converted