dsw-tdk 3.13.0__py3-none-any.whl → 4.27.0__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.
dsw/tdk/py.typed ADDED
File without changes
@@ -0,0 +1 @@
1
+ // TODO: fill text of your license ({{ template.license }})
@@ -1,13 +1,13 @@
1
- # {{ template.name }}
2
-
3
- {{ template.description }}
4
-
5
- ## Changelog
6
-
7
- ### {{ template.version }}
8
-
9
- - Initial version of {{ template.name }} template
10
-
11
- ## License
12
-
13
- This template is released under {{ template.license }}. Read the LICENSE file for details.
1
+ # {{ template.name }}
2
+
3
+ {{ template.description }}
4
+
5
+ ## Changelog
6
+
7
+ ### {{ template.version }}
8
+
9
+ - Initial version of {{ template.name }} template
10
+
11
+ ## License
12
+
13
+ This template is released under {{ template.license }}. Read the LICENSE file for details.
@@ -0,0 +1,3 @@
1
+ DSW_API_URL={{ api_url|default("http://localhost:3000") }}
2
+ DSW_API_KEY={{ api_key|default("") }}
3
+
@@ -1,14 +1,13 @@
1
- {%- raw -%}
2
- {# This is the template starter file generated by DSW TDK #}
3
- {%- set km = ctx.knowledgeModel -%}
4
- {%- set repliesMap = ctx.questionnaireReplies -%}
5
-
6
- {#
7
- ##
8
- ## TODO: Write the template
9
- ## SEE: https://jinja.palletsprojects.com/templates/
10
- ##
11
- ## ~~ Happy hacking! ~~
12
- ##
13
- #}
14
- {% endraw %}
1
+ {%- raw -%}
2
+ {# This is the template starter file generated by DSW TDK #}
3
+ {%- set dc = ctx|to_context_obj -%}
4
+
5
+ {#
6
+ ##
7
+ ## TODO: Write the template
8
+ ## SEE: https://jinja.palletsprojects.com/templates/
9
+ ##
10
+ ## ~~ Happy hacking! ~~
11
+ ##
12
+ #}
13
+ {% endraw %}
@@ -1,173 +1,198 @@
1
- import jinja2 # type: ignore
2
- import pathlib
3
- import uuid
4
-
5
- from typing import List, Set
6
-
7
- from dsw_tdk.consts import DEFAULT_ENCODING, DEFAULT_README
8
- from dsw_tdk.model import Template, TemplateFile, Format, Step, PackageFilter
9
- from dsw_tdk.validation import TemplateValidator, FormatValidator, StepValidator
10
-
11
- j2_env = jinja2.Environment(
12
- loader=jinja2.PackageLoader('dsw_tdk'),
13
- extensions=['jinja2.ext.do'],
14
- autoescape=True,
15
- )
16
-
17
-
18
- class UUIDGen:
19
-
20
- _uuids = set() # type: Set[uuid.UUID]
21
-
22
- @classmethod
23
- def used(cls) -> Set[uuid.UUID]:
24
- return cls._uuids
25
-
26
- @classmethod
27
- def generate(cls) -> uuid.UUID:
28
- result = uuid.uuid4()
29
- while result in cls._uuids:
30
- result = uuid.uuid4()
31
- cls._uuids.add(result)
32
- return result
33
-
34
-
35
- class FormatSpec:
36
-
37
- def __init__(self):
38
- self.format = Format()
39
- self.step = Step(
40
- name='jinja',
41
- options={
42
- 'template': 'template.html.j2',
43
- 'content-type': 'text/html',
44
- 'extension': 'html',
45
- }
46
- )
47
- self.format.uuid = str(UUIDGen.generate())
48
- self.format.steps.append(self.step)
49
-
50
- @property
51
- def name(self):
52
- return self.format.name
53
-
54
- @name.setter
55
- def name(self, value: str):
56
- self.format.name = value
57
- FormatValidator.validate_field(self.format, 'name')
58
-
59
- @property
60
- def content_type(self):
61
- return self.step.options['content-type']
62
-
63
- @content_type.setter
64
- def content_type(self, value: str):
65
- self.step.options['content-type'] = value
66
- StepValidator.validate(self.step, 'format')
67
-
68
- @property
69
- def file_extension(self):
70
- return self.step.options['extension']
71
-
72
- @file_extension.setter
73
- def file_extension(self, value: str):
74
- self.step.options['extension'] = value
75
- self.format.short_name = value
76
- StepValidator.validate(self.step, 'format')
77
-
78
- @property
79
- def filename(self):
80
- return self.step.options['template']
81
-
82
- @filename.setter
83
- def filename(self, value: str):
84
- self.step.options['template'] = str(pathlib.PurePosixPath(pathlib.Path(value)))
85
- StepValidator.validate(self.step, 'format')
86
-
87
-
88
- class TemplateBuilder:
89
-
90
- def __init__(self):
91
- self.template = Template()
92
- self._formats = [] # type: List[FormatSpec]
93
-
94
- @property
95
- def formats(self) -> List[FormatSpec]:
96
- return self._formats
97
-
98
- def _validate_field(self, field_name: str):
99
- TemplateValidator.validate_field(self.template, field_name)
100
-
101
- def add_format(self, format_spec: FormatSpec):
102
- self._formats.append(format_spec)
103
- self.template.formats.append(format_spec.format)
104
-
105
- @property
106
- def name(self):
107
- return self.template.name
108
-
109
- @name.setter
110
- def name(self, value: str):
111
- self.template.name = value
112
- self._validate_field('name')
113
-
114
- @property
115
- def template_id(self):
116
- return self.template.template_id
117
-
118
- @template_id.setter
119
- def template_id(self, value: str):
120
- self.template.template_id = value
121
- self._validate_field('template_id')
122
-
123
- @property
124
- def organization_id(self):
125
- return self.template.organization_id
126
-
127
- @organization_id.setter
128
- def organization_id(self, value: str):
129
- self.template.organization_id = value
130
- self._validate_field('organization_id')
131
-
132
- @property
133
- def version(self):
134
- return self.template.version
135
-
136
- @version.setter
137
- def version(self, value: str):
138
- self.template.version = value
139
- self._validate_field('version')
140
-
141
- @property
142
- def description(self):
143
- return self.template.description
144
-
145
- @description.setter
146
- def description(self, value: str):
147
- self.template.description = value
148
- self._validate_field('description')
149
-
150
- @property
151
- def license(self):
152
- return self.template.license
153
-
154
- @license.setter
155
- def license(self, value: str):
156
- self.template.license = value
157
- self._validate_field('license')
158
-
159
- def build(self) -> Template:
160
- readme = j2_env.get_template('README.md.j2').render(template=self.template)
161
- self.template.readme = readme
162
- self.template.tdk_config.readme_file = DEFAULT_README
163
- TemplateValidator.validate(self.template)
164
- for format_spec in self._formats:
165
- content = j2_env.get_template('starter.j2').render(template=self.template)
166
- self.template.files[format_spec.filename] = TemplateFile(
167
- filename=format_spec.filename,
168
- content_type='text/plain',
169
- content=content.encode(encoding=DEFAULT_ENCODING)
170
- )
171
- self.template.tdk_config.files.append(str(format_spec.filename))
172
- self.template.allowed_packages.append(PackageFilter())
173
- return self.template
1
+ import pathlib
2
+ import uuid
3
+
4
+ import jinja2
5
+
6
+ from . import consts
7
+ from .model import Format, PackageFilter, Step, Template, TemplateFile
8
+ from .validation import FormatValidator, StepValidator, TemplateValidator
9
+
10
+
11
+ TEMPLATES_DIR = pathlib.Path(__file__).parent / 'templates'
12
+
13
+ j2_env = jinja2.Environment(
14
+ loader=jinja2.FileSystemLoader(TEMPLATES_DIR),
15
+ extensions=['jinja2.ext.do'],
16
+ autoescape=True,
17
+ )
18
+
19
+
20
+ class UUIDGen:
21
+
22
+ _uuids: set[uuid.UUID] = set()
23
+
24
+ @classmethod
25
+ def used(cls) -> set[uuid.UUID]:
26
+ return cls._uuids
27
+
28
+ @classmethod
29
+ def generate(cls) -> uuid.UUID:
30
+ result = uuid.uuid4()
31
+ while result in cls._uuids:
32
+ result = uuid.uuid4()
33
+ cls._uuids.add(result)
34
+ return result
35
+
36
+
37
+ class FormatSpec:
38
+
39
+ def __init__(self):
40
+ self.format = Format()
41
+ self.step = Step(
42
+ name='jinja',
43
+ options={
44
+ 'template': 'template.html.j2',
45
+ 'content-type': 'text/html',
46
+ 'extension': 'html',
47
+ },
48
+ )
49
+ self.format.uuid = str(UUIDGen.generate())
50
+ self.format.steps.append(self.step)
51
+
52
+ @property
53
+ def name(self):
54
+ return self.format.name
55
+
56
+ @name.setter
57
+ def name(self, value: str):
58
+ self.format.name = value
59
+ FormatValidator.validate_field(self.format, 'name')
60
+
61
+ @property
62
+ def content_type(self):
63
+ return self.step.options['content-type']
64
+
65
+ @content_type.setter
66
+ def content_type(self, value: str):
67
+ self.step.options['content-type'] = value
68
+ StepValidator.validate(self.step, 'format')
69
+
70
+ @property
71
+ def file_extension(self):
72
+ return self.step.options['extension']
73
+
74
+ @file_extension.setter
75
+ def file_extension(self, value: str):
76
+ self.step.options['extension'] = value
77
+ StepValidator.validate(self.step, 'format')
78
+
79
+ @property
80
+ def filename(self):
81
+ return self.step.options['template']
82
+
83
+ @filename.setter
84
+ def filename(self, value: str):
85
+ self.step.options['template'] = str(pathlib.PurePosixPath(pathlib.Path(value)))
86
+ StepValidator.validate(self.step, 'format')
87
+
88
+
89
+ class TemplateBuilder:
90
+
91
+ def __init__(self):
92
+ self.template = Template()
93
+ self._formats: list[FormatSpec] = []
94
+
95
+ @property
96
+ def formats(self) -> list[FormatSpec]:
97
+ return self._formats
98
+
99
+ def _validate_field(self, field_name: str):
100
+ TemplateValidator.validate_field(self.template, field_name)
101
+
102
+ def add_format(self, format_spec: FormatSpec):
103
+ self._formats.append(format_spec)
104
+ self.template.formats.append(format_spec.format)
105
+
106
+ @property
107
+ def name(self):
108
+ return self.template.name
109
+
110
+ @name.setter
111
+ def name(self, value: str):
112
+ self.template.name = value
113
+ self._validate_field('name')
114
+
115
+ @property
116
+ def template_id(self):
117
+ return self.template.template_id
118
+
119
+ @template_id.setter
120
+ def template_id(self, value: str):
121
+ self.template.template_id = value
122
+ self._validate_field('template_id')
123
+
124
+ @property
125
+ def organization_id(self):
126
+ return self.template.organization_id
127
+
128
+ @organization_id.setter
129
+ def organization_id(self, value: str):
130
+ self.template.organization_id = value
131
+ self._validate_field('organization_id')
132
+
133
+ @property
134
+ def version(self):
135
+ return self.template.version
136
+
137
+ @version.setter
138
+ def version(self, value: str):
139
+ self.template.version = value
140
+ self._validate_field('version')
141
+
142
+ @property
143
+ def description(self):
144
+ return self.template.description
145
+
146
+ @description.setter
147
+ def description(self, value: str):
148
+ self.template.description = value
149
+ self._validate_field('description')
150
+
151
+ @property
152
+ def license(self):
153
+ return self.template.license
154
+
155
+ @license.setter
156
+ def license(self, value: str):
157
+ self.template.license = value
158
+ self._validate_field('license')
159
+
160
+ def build(self) -> Template:
161
+ readme = j2_env.get_template('README.md.j2').render(template=self.template)
162
+ self.template.readme = readme
163
+ self.template.tdk_config.readme_file = consts.DEFAULT_README
164
+ TemplateValidator.validate(self.template)
165
+
166
+ for format_spec in self._formats:
167
+ content = j2_env.get_template('starter.j2').render(template=self.template)
168
+ self.template.files[format_spec.filename] = TemplateFile(
169
+ filename=format_spec.filename,
170
+ content_type='text/plain',
171
+ content=content.encode(encoding=consts.DEFAULT_ENCODING),
172
+ )
173
+ self.template.tdk_config.files = ['src/**/*', '!.git/', '!.env']
174
+ self.template.allowed_packages.append(PackageFilter())
175
+
176
+ license_file = j2_env.get_template('LICENSE.j2').render(template=self.template)
177
+ self.template.tdk_config.files.append('LICENSE')
178
+ self.template.files['LICENSE'] = TemplateFile(
179
+ filename=pathlib.Path('LICENSE'),
180
+ content_type='text/plain',
181
+ content=license_file.encode(encoding=consts.DEFAULT_ENCODING),
182
+ )
183
+
184
+ self.template.files['.env'] = TemplateFile(
185
+ filename=pathlib.Path('.env'),
186
+ content_type='text/plain',
187
+ content=create_dot_env().encode(encoding=consts.DEFAULT_ENCODING),
188
+ )
189
+
190
+ return self.template
191
+
192
+
193
+ def create_dot_env(api_url: str | None = None, api_key: str | None = None) -> str:
194
+ return j2_env.get_template('env.j2').render(api_url=api_url, api_key=api_key)
195
+
196
+
197
+ def safe_utf8(text: str) -> str:
198
+ return text.encode(encoding='utf-8', errors='ignore').decode(encoding='utf-8')