ssc_codegen 0.9.0__tar.gz → 0.9.2__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.
Potentially problematic release.
This version of ssc_codegen might be problematic. Click here for more details.
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/PKG-INFO +38 -34
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/README.md +37 -33
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/pyproject.toml +1 -1
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/__init__.py +1 -1
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_build/main.py +17 -6
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/consts.py +1 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/main.py +18 -2
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/py_base.py +2 -3
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/.gitignore +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/LICENSE +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/_compat.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_array.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_cast.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_core.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_filter.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_selectors.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_string.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_/nodes_validate.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_build/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/ast_build/utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/cli_callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/cli_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/code_callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/cli/runtime_parse_runners.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/compiler.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/consts.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/go_goquery.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/helpers.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/js_pure.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/py_bs4.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/py_parsel.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/py_selectolax.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/templates/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/templates/go_goquery.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/converters/templates/js_pure.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/document.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/document_utlis.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/json_struct.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/json_to_scc.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/logs.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/pseudo_selectors.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/schema.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/selector_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/static_checker/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/static_checker/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/static_checker/callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/str_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.2}/ssc_codegen/tokens.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ssc_codegen
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.2
|
|
4
4
|
Summary: Python-dsl code converter to html parser for web scraping
|
|
5
5
|
Project-URL: Documentation, https://github.com/vypivshiy/selector_schema_codegen#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/vypivshiy/selector_schema_codegen/issues
|
|
@@ -41,42 +41,49 @@ ssc-gen - based-python DSL language for writing html parsers in dataclass style
|
|
|
41
41
|
Project solving next problems:
|
|
42
42
|
|
|
43
43
|
- decrease boilerplate code
|
|
44
|
-
-
|
|
44
|
+
- generation DDD-like modules independent of the project
|
|
45
|
+
- generate types or type annotations if possible and documentation
|
|
45
46
|
- simplify code support
|
|
46
|
-
- portability to other languages
|
|
47
|
+
- portability to other languages and HTML parser backends
|
|
48
|
+
- designed for server-side-render pages parse.
|
|
49
|
+
For REST-API, GRAPHQL use tools like [mitmproxy2swagger](https://github.com/alufers/mitmproxy2swagger)
|
|
50
|
+
for simplify convert to code
|
|
47
51
|
|
|
48
52
|
## Support converters
|
|
49
53
|
|
|
50
54
|
Current support converters
|
|
51
55
|
|
|
52
|
-
| Language |
|
|
53
|
-
|
|
54
|
-
| Python (3.8+) | bs4
|
|
55
|
-
| ... | parsel
|
|
56
|
-
| ... | selectolax (lexbor)
|
|
57
|
-
| js (ES6) | pure (firefox/chrome/nodejs)
|
|
58
|
-
| go (1.10+) | goquery
|
|
59
|
-
|
|
56
|
+
| Language | HTML parser backend | XPath | CSS3 | CSS4 | Generated types, structs | formatter dependency |
|
|
57
|
+
|---------------|------------------------------|-------|------|------|-----------------------------------|----------------------|
|
|
58
|
+
| Python (3.8+) | bs4 | N | Y | Y | TypedDict*, list, dict | ruff |
|
|
59
|
+
| ... | parsel | Y | Y | N | ... | ... |
|
|
60
|
+
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
61
|
+
| js (ES6) | pure (firefox/chrome/nodejs) | Y | Y | Y | Array, Map** | prettier |
|
|
62
|
+
| go (1.10+) | goquery | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
63
|
+
|
|
64
|
+
- **CSS3** means support next selectors:
|
|
65
|
+
- basic: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
66
|
+
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`)
|
|
67
|
+
- attribute: (`a[href]`, `input[type='text']`, `a[href*='...']`, ...)
|
|
68
|
+
- basic pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)
|
|
69
|
+
- **CSS4** means support next selectors:
|
|
70
|
+
- `:has()`, `:nth-of-type()`, `:where()`, `:is()` etc
|
|
60
71
|
- *this annotation type was deliberately chosen as a compromise reasons.
|
|
61
72
|
Python has many ways of serialization: `namedtuple, dataclass, attrs, pydantic, msgspec, etc`
|
|
62
73
|
- TypedDict is like a build-in dict, but with IDE and linter hint support, and you can easily implement an adapter for the required structure.
|
|
63
|
-
- **js exclude build-in serialization methods
|
|
74
|
+
- **js exclude build-in serialization methods, used standard Array and Map structures
|
|
75
|
+
- **formatter** - optional dependency for prettify and fix codestyle
|
|
64
76
|
|
|
65
77
|
### Limitations
|
|
66
78
|
|
|
67
79
|
For maximum portability of the configuration to the target language:
|
|
68
80
|
|
|
69
81
|
- Use CSS selectors: they are guaranteed to be converted to XPATH
|
|
70
|
-
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
71
|
-
|
|
72
|
-
- basic selectors: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
73
|
-
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`\[1])
|
|
74
|
-
- attribute: (`a[href]`, `input[type='text']`)\[2]
|
|
75
|
-
- pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)\[3]
|
|
76
|
-
- **often, not support more complex, dynamic styles**: (`:has()`, `:nth-of-type()`, `:where()`, `:is()`)
|
|
82
|
+
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
83
|
+
Check the html parser lib documentation before implement CSS selectors
|
|
77
84
|
|
|
78
85
|
1. Several libs not support `+` operations (eg: [selectolax(modest)](https://github.com/rushter/selectolax), [dart.universal_html](https://pub.dev/packages/universal_html))
|
|
79
|
-
2.
|
|
86
|
+
2. HTML parser libs maybe not supports attribute operations like `*=`, `~=`, `|=`, `^=` and `$=`
|
|
80
87
|
3. Several libs not support pseudo classes (eg: standard [dart.html](https://dart.dev/libraries/dart-html) lib miss this feature).
|
|
81
88
|
This project will not implement converters with such a cons
|
|
82
89
|
|
|
@@ -120,7 +127,7 @@ class HelloWorld(ItemSchema):
|
|
|
120
127
|
### try it in cli
|
|
121
128
|
|
|
122
129
|
>[!note]
|
|
123
|
-
> this tools developed for testing purposes, not for web-scraping
|
|
130
|
+
> this tools developed for testing purposes, not for web-scraping tasks
|
|
124
131
|
|
|
125
132
|
### from file
|
|
126
133
|
|
|
@@ -167,7 +174,7 @@ ssc-gen parse-from-chrome https://example.com -t schema.py:HelloWorld -sc /usr/b
|
|
|
167
174
|
|
|
168
175
|
Convert to code for use in projects:
|
|
169
176
|
|
|
170
|
-
|
|
177
|
+
>[!note]
|
|
171
178
|
> for example, used js: it can be fast test in developer console
|
|
172
179
|
|
|
173
180
|
|
|
@@ -175,7 +182,7 @@ Convert to code for use in projects:
|
|
|
175
182
|
ssc-gen js schema.py -o .
|
|
176
183
|
```
|
|
177
184
|
|
|
178
|
-
Code output looks like this
|
|
185
|
+
Code output looks like this:
|
|
179
186
|
|
|
180
187
|
```javascript
|
|
181
188
|
// autogenerated by ssc-gen DO NOT_EDIT
|
|
@@ -216,7 +223,7 @@ class HelloWorld {
|
|
|
216
223
|
}
|
|
217
224
|
```
|
|
218
225
|
|
|
219
|
-
###
|
|
226
|
+
### Copy code output and past to developer console:
|
|
220
227
|
|
|
221
228
|
Print output:
|
|
222
229
|
|
|
@@ -229,17 +236,14 @@ alert(JSON.stringify((new HelloWorld(document).parse())))
|
|
|
229
236
|
|
|
230
237
|
You can use any html source:
|
|
231
238
|
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
- use in third-party tools in stdin pipeline:
|
|
238
|
-
(from [ProjectDiscovery](https://github.com/projectdiscovery), for example)
|
|
239
|
-
|
|
239
|
+
- parse from html files
|
|
240
|
+
- parse from http responses
|
|
241
|
+
- parse from browsers: playwright, selenium, chrome-cdp, etc.
|
|
242
|
+
- call curl in shell and parse STDIN
|
|
243
|
+
- use in STDIN pipelines with third-party tools like [projectdiscovery/httpx](https://github.com/projectdiscovery/httpx)
|
|
240
244
|
|
|
241
245
|
## See also
|
|
242
246
|
- [Brief](docs/brief.md) about css selectors and regular expressions.
|
|
243
|
-
- [Tutorial](docs/tutorial.md)
|
|
244
|
-
- [Reference](docs/reference.md) about
|
|
247
|
+
- [Tutorial](docs/tutorial.md) basic usage ssc-gen
|
|
248
|
+
- [Reference](docs/reference.md) about lib API
|
|
245
249
|
- [AST reference](docs/ast_reference.md) about generation code from AST
|
|
@@ -7,42 +7,49 @@ ssc-gen - based-python DSL language for writing html parsers in dataclass style
|
|
|
7
7
|
Project solving next problems:
|
|
8
8
|
|
|
9
9
|
- decrease boilerplate code
|
|
10
|
-
-
|
|
10
|
+
- generation DDD-like modules independent of the project
|
|
11
|
+
- generate types or type annotations if possible and documentation
|
|
11
12
|
- simplify code support
|
|
12
|
-
- portability to other languages
|
|
13
|
+
- portability to other languages and HTML parser backends
|
|
14
|
+
- designed for server-side-render pages parse.
|
|
15
|
+
For REST-API, GRAPHQL use tools like [mitmproxy2swagger](https://github.com/alufers/mitmproxy2swagger)
|
|
16
|
+
for simplify convert to code
|
|
13
17
|
|
|
14
18
|
## Support converters
|
|
15
19
|
|
|
16
20
|
Current support converters
|
|
17
21
|
|
|
18
|
-
| Language |
|
|
19
|
-
|
|
20
|
-
| Python (3.8+) | bs4
|
|
21
|
-
| ... | parsel
|
|
22
|
-
| ... | selectolax (lexbor)
|
|
23
|
-
| js (ES6) | pure (firefox/chrome/nodejs)
|
|
24
|
-
| go (1.10+) | goquery
|
|
25
|
-
|
|
22
|
+
| Language | HTML parser backend | XPath | CSS3 | CSS4 | Generated types, structs | formatter dependency |
|
|
23
|
+
|---------------|------------------------------|-------|------|------|-----------------------------------|----------------------|
|
|
24
|
+
| Python (3.8+) | bs4 | N | Y | Y | TypedDict*, list, dict | ruff |
|
|
25
|
+
| ... | parsel | Y | Y | N | ... | ... |
|
|
26
|
+
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
27
|
+
| js (ES6) | pure (firefox/chrome/nodejs) | Y | Y | Y | Array, Map** | prettier |
|
|
28
|
+
| go (1.10+) | goquery | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
29
|
+
|
|
30
|
+
- **CSS3** means support next selectors:
|
|
31
|
+
- basic: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
32
|
+
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`)
|
|
33
|
+
- attribute: (`a[href]`, `input[type='text']`, `a[href*='...']`, ...)
|
|
34
|
+
- basic pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)
|
|
35
|
+
- **CSS4** means support next selectors:
|
|
36
|
+
- `:has()`, `:nth-of-type()`, `:where()`, `:is()` etc
|
|
26
37
|
- *this annotation type was deliberately chosen as a compromise reasons.
|
|
27
38
|
Python has many ways of serialization: `namedtuple, dataclass, attrs, pydantic, msgspec, etc`
|
|
28
39
|
- TypedDict is like a build-in dict, but with IDE and linter hint support, and you can easily implement an adapter for the required structure.
|
|
29
|
-
- **js exclude build-in serialization methods
|
|
40
|
+
- **js exclude build-in serialization methods, used standard Array and Map structures
|
|
41
|
+
- **formatter** - optional dependency for prettify and fix codestyle
|
|
30
42
|
|
|
31
43
|
### Limitations
|
|
32
44
|
|
|
33
45
|
For maximum portability of the configuration to the target language:
|
|
34
46
|
|
|
35
47
|
- Use CSS selectors: they are guaranteed to be converted to XPATH
|
|
36
|
-
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
37
|
-
|
|
38
|
-
- basic selectors: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
39
|
-
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`\[1])
|
|
40
|
-
- attribute: (`a[href]`, `input[type='text']`)\[2]
|
|
41
|
-
- pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)\[3]
|
|
42
|
-
- **often, not support more complex, dynamic styles**: (`:has()`, `:nth-of-type()`, `:where()`, `:is()`)
|
|
48
|
+
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
49
|
+
Check the html parser lib documentation before implement CSS selectors
|
|
43
50
|
|
|
44
51
|
1. Several libs not support `+` operations (eg: [selectolax(modest)](https://github.com/rushter/selectolax), [dart.universal_html](https://pub.dev/packages/universal_html))
|
|
45
|
-
2.
|
|
52
|
+
2. HTML parser libs maybe not supports attribute operations like `*=`, `~=`, `|=`, `^=` and `$=`
|
|
46
53
|
3. Several libs not support pseudo classes (eg: standard [dart.html](https://dart.dev/libraries/dart-html) lib miss this feature).
|
|
47
54
|
This project will not implement converters with such a cons
|
|
48
55
|
|
|
@@ -86,7 +93,7 @@ class HelloWorld(ItemSchema):
|
|
|
86
93
|
### try it in cli
|
|
87
94
|
|
|
88
95
|
>[!note]
|
|
89
|
-
> this tools developed for testing purposes, not for web-scraping
|
|
96
|
+
> this tools developed for testing purposes, not for web-scraping tasks
|
|
90
97
|
|
|
91
98
|
### from file
|
|
92
99
|
|
|
@@ -133,7 +140,7 @@ ssc-gen parse-from-chrome https://example.com -t schema.py:HelloWorld -sc /usr/b
|
|
|
133
140
|
|
|
134
141
|
Convert to code for use in projects:
|
|
135
142
|
|
|
136
|
-
|
|
143
|
+
>[!note]
|
|
137
144
|
> for example, used js: it can be fast test in developer console
|
|
138
145
|
|
|
139
146
|
|
|
@@ -141,7 +148,7 @@ Convert to code for use in projects:
|
|
|
141
148
|
ssc-gen js schema.py -o .
|
|
142
149
|
```
|
|
143
150
|
|
|
144
|
-
Code output looks like this
|
|
151
|
+
Code output looks like this:
|
|
145
152
|
|
|
146
153
|
```javascript
|
|
147
154
|
// autogenerated by ssc-gen DO NOT_EDIT
|
|
@@ -182,7 +189,7 @@ class HelloWorld {
|
|
|
182
189
|
}
|
|
183
190
|
```
|
|
184
191
|
|
|
185
|
-
###
|
|
192
|
+
### Copy code output and past to developer console:
|
|
186
193
|
|
|
187
194
|
Print output:
|
|
188
195
|
|
|
@@ -195,17 +202,14 @@ alert(JSON.stringify((new HelloWorld(document).parse())))
|
|
|
195
202
|
|
|
196
203
|
You can use any html source:
|
|
197
204
|
|
|
198
|
-
-
|
|
199
|
-
-
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
-
|
|
203
|
-
- use in third-party tools in stdin pipeline:
|
|
204
|
-
(from [ProjectDiscovery](https://github.com/projectdiscovery), for example)
|
|
205
|
-
|
|
205
|
+
- parse from html files
|
|
206
|
+
- parse from http responses
|
|
207
|
+
- parse from browsers: playwright, selenium, chrome-cdp, etc.
|
|
208
|
+
- call curl in shell and parse STDIN
|
|
209
|
+
- use in STDIN pipelines with third-party tools like [projectdiscovery/httpx](https://github.com/projectdiscovery/httpx)
|
|
206
210
|
|
|
207
211
|
## See also
|
|
208
212
|
- [Brief](docs/brief.md) about css selectors and regular expressions.
|
|
209
|
-
- [Tutorial](docs/tutorial.md)
|
|
210
|
-
- [Reference](docs/reference.md) about
|
|
213
|
+
- [Tutorial](docs/tutorial.md) basic usage ssc-gen
|
|
214
|
+
- [Reference](docs/reference.md) about lib API
|
|
211
215
|
- [AST reference](docs/ast_reference.md) about generation code from AST
|
|
@@ -47,6 +47,7 @@ def build_ast_module_parser(
|
|
|
47
47
|
*,
|
|
48
48
|
css_to_xpath: bool = False,
|
|
49
49
|
xpath_to_css: bool = False,
|
|
50
|
+
gen_docstring: bool = True,
|
|
50
51
|
) -> ModuleProgram:
|
|
51
52
|
"""build ast from python sscgen config file
|
|
52
53
|
|
|
@@ -66,12 +67,18 @@ def build_ast_module_parser(
|
|
|
66
67
|
"Should be chosen one variant (css_to_xpath OR xpath_to_css)"
|
|
67
68
|
)
|
|
68
69
|
py_module = exec_module_code(path)
|
|
69
|
-
docstr = py_module.__dict__.get("__doc__") or "" # type: str
|
|
70
70
|
ast_module = ModuleProgram()
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
|
|
72
|
+
if gen_docstring:
|
|
73
|
+
docstr = py_module.__dict__.get("__doc__") or "" # type: str
|
|
74
|
+
module_body: list[BaseAstNode] = [
|
|
75
|
+
Docstring(kwargs={"value": docstr}, parent=ast_module),
|
|
76
|
+
ModuleImports(parent=ast_module),
|
|
77
|
+
]
|
|
78
|
+
else:
|
|
79
|
+
module_body: list[BaseAstNode] = [
|
|
80
|
+
ModuleImports(parent=ast_module),
|
|
81
|
+
]
|
|
75
82
|
|
|
76
83
|
schemas = extract_schemas_from_module(py_module)
|
|
77
84
|
json_structs = extract_json_structs_from_module(py_module)
|
|
@@ -85,6 +92,7 @@ def build_ast_module_parser(
|
|
|
85
92
|
ast_module,
|
|
86
93
|
css_to_xpath=css_to_xpath,
|
|
87
94
|
xpath_to_css=xpath_to_css,
|
|
95
|
+
gen_docstring=gen_docstring,
|
|
88
96
|
)
|
|
89
97
|
for sc in schemas
|
|
90
98
|
]
|
|
@@ -98,6 +106,7 @@ def build_ast_module_parser(
|
|
|
98
106
|
ast_module,
|
|
99
107
|
css_to_xpath=css_to_xpath,
|
|
100
108
|
xpath_to_css=xpath_to_css,
|
|
109
|
+
gen_docstring=gen_docstring,
|
|
101
110
|
)
|
|
102
111
|
except SyntaxError as e:
|
|
103
112
|
errors.append(e)
|
|
@@ -187,6 +196,7 @@ def build_ast_struct_parser(
|
|
|
187
196
|
*,
|
|
188
197
|
css_to_xpath: bool = False,
|
|
189
198
|
xpath_to_css: bool = False,
|
|
199
|
+
gen_docstring: bool = True,
|
|
190
200
|
) -> StructParser:
|
|
191
201
|
errors_count = run_analyze_schema(schema)
|
|
192
202
|
if errors_count > 0:
|
|
@@ -195,11 +205,12 @@ def build_ast_struct_parser(
|
|
|
195
205
|
docstring = (
|
|
196
206
|
(schema.__doc__ or "") + "\n\n" + generate_docstring_signature(schema)
|
|
197
207
|
)
|
|
208
|
+
|
|
198
209
|
st = StructParser(
|
|
199
210
|
kwargs={
|
|
200
211
|
"name": schema.__name__,
|
|
201
212
|
"struct_type": schema.__SCHEMA_TYPE__,
|
|
202
|
-
"docstring": docstring,
|
|
213
|
+
"docstring": docstring if gen_docstring else "",
|
|
203
214
|
},
|
|
204
215
|
parent=module_ref,
|
|
205
216
|
)
|
|
@@ -32,6 +32,7 @@ HELP_TO_CSS = "convert all xpath queries to css (works not guaranteed)"
|
|
|
32
32
|
HELP_DEBUG_COMM_TOKENS = "add debug comment for each generated instruction"
|
|
33
33
|
HELP_JSON_TO_SCHEMA = "convert json response to ssc-gen schema"
|
|
34
34
|
# cmd group description
|
|
35
|
+
HELP_DOCSTRING = "disable docstring and fields signature generate"
|
|
35
36
|
CMD_VERSION = "Show version and exit"
|
|
36
37
|
CMD_PY = "generate python modules"
|
|
37
38
|
CMD_JS = "generate javascript modules"
|
|
@@ -43,6 +43,7 @@ from ssc_codegen.cli.consts import (
|
|
|
43
43
|
CMD_GO,
|
|
44
44
|
CMD_JSON_GEN,
|
|
45
45
|
DEFAULT_UA,
|
|
46
|
+
HELP_DOCSTRING,
|
|
46
47
|
)
|
|
47
48
|
from ssc_codegen.cli.runtime_parse_runners import (
|
|
48
49
|
assert_cls_target,
|
|
@@ -84,6 +85,7 @@ def generate_code(
|
|
|
84
85
|
css_to_xpath: bool = False,
|
|
85
86
|
xpath_to_css: bool = False,
|
|
86
87
|
debug_instructions: bool = False,
|
|
88
|
+
gen_docstring: bool = True,
|
|
87
89
|
) -> None:
|
|
88
90
|
"""universal generate code entrypoint"""
|
|
89
91
|
variables_patches = variables_patches or {}
|
|
@@ -113,6 +115,7 @@ def generate_code(
|
|
|
113
115
|
file_cfg,
|
|
114
116
|
css_to_xpath=css_to_xpath,
|
|
115
117
|
xpath_to_css=xpath_to_css,
|
|
118
|
+
gen_docstring=gen_docstring,
|
|
116
119
|
)
|
|
117
120
|
LOGGER.info("Convert to code %s...", file_cfg.name)
|
|
118
121
|
code_parts = converter.convert_program(ast_module, comment=comment_str)
|
|
@@ -155,6 +158,9 @@ def gen_py(
|
|
|
155
158
|
debug: Annotated[
|
|
156
159
|
bool, Option(help=HELP_DEBUG_COMM_TOKENS, is_flag=True)
|
|
157
160
|
] = False,
|
|
161
|
+
docstring: Annotated[
|
|
162
|
+
bool, Option(help=HELP_DOCSTRING, is_flag=True)
|
|
163
|
+
] = True,
|
|
158
164
|
) -> None:
|
|
159
165
|
converter = import_converter(f"py_{lib.value}")
|
|
160
166
|
if fmt:
|
|
@@ -174,6 +180,7 @@ def gen_py(
|
|
|
174
180
|
css_to_xpath=to_xpath,
|
|
175
181
|
debug_instructions=debug,
|
|
176
182
|
code_cb=CB_PY_CODE,
|
|
183
|
+
gen_docstring=docstring,
|
|
177
184
|
)
|
|
178
185
|
|
|
179
186
|
|
|
@@ -202,11 +209,15 @@ def gen_js(
|
|
|
202
209
|
debug: Annotated[
|
|
203
210
|
bool, Option(help=HELP_DEBUG_COMM_TOKENS, is_flag=True)
|
|
204
211
|
] = False,
|
|
212
|
+
docstring: Annotated[
|
|
213
|
+
bool, Option(help=HELP_DOCSTRING, is_flag=True)
|
|
214
|
+
] = True,
|
|
205
215
|
) -> None:
|
|
206
216
|
converter = import_converter(f"js_{lib.value}")
|
|
207
217
|
if fmt:
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
commands: list[str] = [
|
|
219
|
+
'prettier --write --tab-width 4 --single-quote --trailing-comma all --semi {}',
|
|
220
|
+
]
|
|
210
221
|
fmt_cmd = create_fmt_cmd(ssc_files, prefix, suffix, out, commands)
|
|
211
222
|
else:
|
|
212
223
|
fmt_cmd = []
|
|
@@ -222,6 +233,7 @@ def gen_js(
|
|
|
222
233
|
css_to_xpath=to_xpath,
|
|
223
234
|
debug_instructions=debug,
|
|
224
235
|
code_cb=CB_JS_CODE,
|
|
236
|
+
gen_docstring=docstring,
|
|
225
237
|
)
|
|
226
238
|
|
|
227
239
|
|
|
@@ -252,6 +264,9 @@ def gen_go(
|
|
|
252
264
|
to_xpath: Annotated[bool, Option(help=HELP_TO_XPATH, is_flag=True)] = False,
|
|
253
265
|
to_css: Annotated[bool, Option(help=HELP_TO_CSS, is_flag=True)] = False,
|
|
254
266
|
debug: Annotated[bool, Option(help=HELP_DEBUG_COMM_TOKENS)] = False,
|
|
267
|
+
docstring: Annotated[
|
|
268
|
+
bool, Option(help=HELP_DOCSTRING, is_flag=True)
|
|
269
|
+
] = True,
|
|
255
270
|
) -> None:
|
|
256
271
|
converter = import_converter(f"go_{lib.value}")
|
|
257
272
|
if fmt:
|
|
@@ -273,6 +288,7 @@ def gen_go(
|
|
|
273
288
|
xpath_to_css=to_css,
|
|
274
289
|
css_to_xpath=to_xpath,
|
|
275
290
|
debug_instructions=debug,
|
|
291
|
+
gen_docstring=docstring,
|
|
276
292
|
)
|
|
277
293
|
|
|
278
294
|
|
|
@@ -491,7 +491,7 @@ def post_start_parse(node: StartParseMethod) -> str:
|
|
|
491
491
|
code += f"{name!r}: self._parse_{name}(self._document),"
|
|
492
492
|
code += "}"
|
|
493
493
|
case StructType.ACC_LIST:
|
|
494
|
-
code += INDENT_METHOD_BODY + "return list(
|
|
494
|
+
code += INDENT_METHOD_BODY + "return list(set("
|
|
495
495
|
methods = []
|
|
496
496
|
for expr in node.body:
|
|
497
497
|
name = expr.kwargs["name"]
|
|
@@ -1100,8 +1100,7 @@ def pre_list_unique(node: ExprListUnique) -> str:
|
|
|
1100
1100
|
INDENT_DEFAULT_BODY if have_default_expr(node) else INDENT_METHOD_BODY
|
|
1101
1101
|
)
|
|
1102
1102
|
prv, nxt = prev_next_var(node)
|
|
1103
|
-
|
|
1104
|
-
return f"{indent}{nxt} = list(dict.fromkeys({prv}))"
|
|
1103
|
+
return f"{indent}{nxt} = list(set({prv}))"
|
|
1105
1104
|
|
|
1106
1105
|
|
|
1107
1106
|
def pre_str_map_replace(node: ExprStringMapReplace) -> str:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|