ssc_codegen 0.9.0__tar.gz → 0.9.1__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.
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/PKG-INFO +35 -34
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/README.md +34 -33
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/pyproject.toml +1 -1
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/__init__.py +1 -1
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_build/main.py +17 -6
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/consts.py +1 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/main.py +18 -2
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/.gitignore +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/LICENSE +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/_compat.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_array.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_cast.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_core.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_filter.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_selectors.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_string.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_/nodes_validate.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_build/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/ast_build/utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/cli_callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/cli_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/code_callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/cli/runtime_parse_runners.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/compiler.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/consts.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/go_goquery.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/helpers.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/js_pure.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/py_base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/py_bs4.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/py_parsel.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/py_selectolax.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/templates/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/templates/go_goquery.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/converters/templates/js_pure.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/document.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/document_utlis.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/json_struct.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/json_to_scc.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/logs.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/pseudo_selectors.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/schema.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/selector_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/static_checker/__init__.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/static_checker/base.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/static_checker/callbacks.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/ssc_codegen/str_utils.py +0 -0
- {ssc_codegen-0.9.0 → ssc_codegen-0.9.1}/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.1
|
|
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,46 @@ 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
|
|
47
48
|
|
|
48
49
|
## Support converters
|
|
49
50
|
|
|
50
51
|
Current support converters
|
|
51
52
|
|
|
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
|
-
|
|
53
|
+
| Language | HTML parser backend | XPath | CSS3 | CSS4 | Generated types, structs | formatter dependency |
|
|
54
|
+
|---------------|------------------------------|-------|------|------|-----------------------------------|----------------------|
|
|
55
|
+
| Python (3.8+) | bs4 | N | Y | Y | TypedDict*, list, dict | ruff |
|
|
56
|
+
| ... | parsel | Y | Y | N | ... | ... |
|
|
57
|
+
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
58
|
+
| js (ES6) | pure (firefox/chrome/nodejs) | Y | Y | Y | Array, Map** | prettier |
|
|
59
|
+
| go (1.10+) | goquery | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
60
|
+
|
|
61
|
+
- **CSS3** means support next selectors:
|
|
62
|
+
- basic: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
63
|
+
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`)
|
|
64
|
+
- attribute: (`a[href]`, `input[type='text']`, `a[href*='...']`, ...)
|
|
65
|
+
- basic pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)
|
|
66
|
+
- **CSS4** means support next selectors:
|
|
67
|
+
- `:has()`, `:nth-of-type()`, `:where()`, `:is()` etc
|
|
60
68
|
- *this annotation type was deliberately chosen as a compromise reasons.
|
|
61
69
|
Python has many ways of serialization: `namedtuple, dataclass, attrs, pydantic, msgspec, etc`
|
|
62
70
|
- 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
|
|
71
|
+
- **js exclude build-in serialization methods, used standard Array and Map structures
|
|
72
|
+
- **formatter** - optional dependency for prettify and fix codestyle
|
|
64
73
|
|
|
65
74
|
### Limitations
|
|
66
75
|
|
|
67
76
|
For maximum portability of the configuration to the target language:
|
|
68
77
|
|
|
69
78
|
- 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()`)
|
|
79
|
+
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
80
|
+
Check the html parser lib documentation before implement CSS selectors
|
|
77
81
|
|
|
78
82
|
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.
|
|
83
|
+
2. HTML parser libs maybe not supports attribute operations like `*=`, `~=`, `|=`, `^=` and `$=`
|
|
80
84
|
3. Several libs not support pseudo classes (eg: standard [dart.html](https://dart.dev/libraries/dart-html) lib miss this feature).
|
|
81
85
|
This project will not implement converters with such a cons
|
|
82
86
|
|
|
@@ -120,7 +124,7 @@ class HelloWorld(ItemSchema):
|
|
|
120
124
|
### try it in cli
|
|
121
125
|
|
|
122
126
|
>[!note]
|
|
123
|
-
> this tools developed for testing purposes, not for web-scraping
|
|
127
|
+
> this tools developed for testing purposes, not for web-scraping tasks
|
|
124
128
|
|
|
125
129
|
### from file
|
|
126
130
|
|
|
@@ -167,7 +171,7 @@ ssc-gen parse-from-chrome https://example.com -t schema.py:HelloWorld -sc /usr/b
|
|
|
167
171
|
|
|
168
172
|
Convert to code for use in projects:
|
|
169
173
|
|
|
170
|
-
|
|
174
|
+
>[!note]
|
|
171
175
|
> for example, used js: it can be fast test in developer console
|
|
172
176
|
|
|
173
177
|
|
|
@@ -175,7 +179,7 @@ Convert to code for use in projects:
|
|
|
175
179
|
ssc-gen js schema.py -o .
|
|
176
180
|
```
|
|
177
181
|
|
|
178
|
-
Code output looks like this
|
|
182
|
+
Code output looks like this:
|
|
179
183
|
|
|
180
184
|
```javascript
|
|
181
185
|
// autogenerated by ssc-gen DO NOT_EDIT
|
|
@@ -216,7 +220,7 @@ class HelloWorld {
|
|
|
216
220
|
}
|
|
217
221
|
```
|
|
218
222
|
|
|
219
|
-
###
|
|
223
|
+
### Copy code output and past to developer console:
|
|
220
224
|
|
|
221
225
|
Print output:
|
|
222
226
|
|
|
@@ -229,17 +233,14 @@ alert(JSON.stringify((new HelloWorld(document).parse())))
|
|
|
229
233
|
|
|
230
234
|
You can use any html source:
|
|
231
235
|
|
|
232
|
-
-
|
|
233
|
-
-
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
- use in third-party tools in stdin pipeline:
|
|
238
|
-
(from [ProjectDiscovery](https://github.com/projectdiscovery), for example)
|
|
239
|
-
|
|
236
|
+
- parse from html files
|
|
237
|
+
- parse from http responses
|
|
238
|
+
- parse from browsers: playwright, selenium, chrome-cdp, etc.
|
|
239
|
+
- call curl in shell and parse STDIN
|
|
240
|
+
- use in STDIN pipelines with third-party tools like [projectdiscovery/httpx](https://github.com/projectdiscovery/httpx)
|
|
240
241
|
|
|
241
242
|
## See also
|
|
242
243
|
- [Brief](docs/brief.md) about css selectors and regular expressions.
|
|
243
|
-
- [Tutorial](docs/tutorial.md)
|
|
244
|
-
- [Reference](docs/reference.md) about
|
|
244
|
+
- [Tutorial](docs/tutorial.md) basic usage ssc-gen
|
|
245
|
+
- [Reference](docs/reference.md) about lib API
|
|
245
246
|
- [AST reference](docs/ast_reference.md) about generation code from AST
|
|
@@ -7,42 +7,46 @@ 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
|
|
13
14
|
|
|
14
15
|
## Support converters
|
|
15
16
|
|
|
16
17
|
Current support converters
|
|
17
18
|
|
|
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
|
-
|
|
19
|
+
| Language | HTML parser backend | XPath | CSS3 | CSS4 | Generated types, structs | formatter dependency |
|
|
20
|
+
|---------------|------------------------------|-------|------|------|-----------------------------------|----------------------|
|
|
21
|
+
| Python (3.8+) | bs4 | N | Y | Y | TypedDict*, list, dict | ruff |
|
|
22
|
+
| ... | parsel | Y | Y | N | ... | ... |
|
|
23
|
+
| ... | selectolax (lexbor) | N | Y | N | ... | ... |
|
|
24
|
+
| js (ES6) | pure (firefox/chrome/nodejs) | Y | Y | Y | Array, Map** | prettier |
|
|
25
|
+
| go (1.10+) | goquery | N | Y | N | struct(+json anchors), array, map | gofmt |
|
|
26
|
+
|
|
27
|
+
- **CSS3** means support next selectors:
|
|
28
|
+
- basic: (`tag`, `.class`, `#id`, `tag1,tag2`)
|
|
29
|
+
- combined: (`div p`, `ul > li`, `h2 +p`, `title ~head`)
|
|
30
|
+
- attribute: (`a[href]`, `input[type='text']`, `a[href*='...']`, ...)
|
|
31
|
+
- basic pseudo classes: (`:nth-child(n)`, `:first-child`, `:last-child`)
|
|
32
|
+
- **CSS4** means support next selectors:
|
|
33
|
+
- `:has()`, `:nth-of-type()`, `:where()`, `:is()` etc
|
|
26
34
|
- *this annotation type was deliberately chosen as a compromise reasons.
|
|
27
35
|
Python has many ways of serialization: `namedtuple, dataclass, attrs, pydantic, msgspec, etc`
|
|
28
36
|
- 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
|
|
37
|
+
- **js exclude build-in serialization methods, used standard Array and Map structures
|
|
38
|
+
- **formatter** - optional dependency for prettify and fix codestyle
|
|
30
39
|
|
|
31
40
|
### Limitations
|
|
32
41
|
|
|
33
42
|
For maximum portability of the configuration to the target language:
|
|
34
43
|
|
|
35
44
|
- 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()`)
|
|
45
|
+
- Unlike javascript, most html parse libs implement [CSS3 selectors standard](https://www.w3.org/TR/selectors-3/).
|
|
46
|
+
Check the html parser lib documentation before implement CSS selectors
|
|
43
47
|
|
|
44
48
|
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.
|
|
49
|
+
2. HTML parser libs maybe not supports attribute operations like `*=`, `~=`, `|=`, `^=` and `$=`
|
|
46
50
|
3. Several libs not support pseudo classes (eg: standard [dart.html](https://dart.dev/libraries/dart-html) lib miss this feature).
|
|
47
51
|
This project will not implement converters with such a cons
|
|
48
52
|
|
|
@@ -86,7 +90,7 @@ class HelloWorld(ItemSchema):
|
|
|
86
90
|
### try it in cli
|
|
87
91
|
|
|
88
92
|
>[!note]
|
|
89
|
-
> this tools developed for testing purposes, not for web-scraping
|
|
93
|
+
> this tools developed for testing purposes, not for web-scraping tasks
|
|
90
94
|
|
|
91
95
|
### from file
|
|
92
96
|
|
|
@@ -133,7 +137,7 @@ ssc-gen parse-from-chrome https://example.com -t schema.py:HelloWorld -sc /usr/b
|
|
|
133
137
|
|
|
134
138
|
Convert to code for use in projects:
|
|
135
139
|
|
|
136
|
-
|
|
140
|
+
>[!note]
|
|
137
141
|
> for example, used js: it can be fast test in developer console
|
|
138
142
|
|
|
139
143
|
|
|
@@ -141,7 +145,7 @@ Convert to code for use in projects:
|
|
|
141
145
|
ssc-gen js schema.py -o .
|
|
142
146
|
```
|
|
143
147
|
|
|
144
|
-
Code output looks like this
|
|
148
|
+
Code output looks like this:
|
|
145
149
|
|
|
146
150
|
```javascript
|
|
147
151
|
// autogenerated by ssc-gen DO NOT_EDIT
|
|
@@ -182,7 +186,7 @@ class HelloWorld {
|
|
|
182
186
|
}
|
|
183
187
|
```
|
|
184
188
|
|
|
185
|
-
###
|
|
189
|
+
### Copy code output and past to developer console:
|
|
186
190
|
|
|
187
191
|
Print output:
|
|
188
192
|
|
|
@@ -195,17 +199,14 @@ alert(JSON.stringify((new HelloWorld(document).parse())))
|
|
|
195
199
|
|
|
196
200
|
You can use any html source:
|
|
197
201
|
|
|
198
|
-
-
|
|
199
|
-
-
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
-
|
|
203
|
-
- use in third-party tools in stdin pipeline:
|
|
204
|
-
(from [ProjectDiscovery](https://github.com/projectdiscovery), for example)
|
|
205
|
-
|
|
202
|
+
- parse from html files
|
|
203
|
+
- parse from http responses
|
|
204
|
+
- parse from browsers: playwright, selenium, chrome-cdp, etc.
|
|
205
|
+
- call curl in shell and parse STDIN
|
|
206
|
+
- use in STDIN pipelines with third-party tools like [projectdiscovery/httpx](https://github.com/projectdiscovery/httpx)
|
|
206
207
|
|
|
207
208
|
## See also
|
|
208
209
|
- [Brief](docs/brief.md) about css selectors and regular expressions.
|
|
209
|
-
- [Tutorial](docs/tutorial.md)
|
|
210
|
-
- [Reference](docs/reference.md) about
|
|
210
|
+
- [Tutorial](docs/tutorial.md) basic usage ssc-gen
|
|
211
|
+
- [Reference](docs/reference.md) about lib API
|
|
211
212
|
- [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
|
|
|
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
|
|
File without changes
|