API Reference
cdd
cdd
Root init
Parameters:
Name | Type | Description | Default |
---|
cdd.argparse_function
cdd.argparse_function
Argparse function parser and emitter
Parameters:
Name | Type | Description | Default |
---|
cdd.argparse_function.emit
cdd.argparse_function.emit
Argparse emitter
Parameters:
Name | Type | Description | Default |
---|
argparse_function
argparse_function(intermediate_repr, emit_default_doc=False, function_name='set_cli_args', function_type='static', wrap_description=False, word_wrap=True, docstring_format='rest')
Convert to an argparse FunctionDef
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
function_name
|
name
|
name of function_def |
required |
function_type
|
Literal['self', 'cls', 'static']
|
Type of function, static is static or global method, others just become first arg |
required |
wrap_description
|
bool
|
Whether to word-wrap the description. Set |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
AST node for function definition which constructs argparse |
Source code in cdd/argparse_function/emit.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
cdd.argparse_function.parse
cdd.argparse_function.parse
Argparse function parser
Parameters:
Name | Type | Description | Default |
---|
argparse_ast
argparse_ast(function_def, function_type=None, function_name=None, parse_original_whitespace=False, word_wrap=False)
Converts an argparse AST to our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_def
|
FunctionDef
|
AST of argparse function_def |
required |
function_type
|
Literal['self', 'cls', 'static']
|
Type of function, static is static or global method, others just become first arg |
required |
function_name
|
name
|
name of function_def |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/argparse_function/parse.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
cdd.argparse_function.utils
cdd.argparse_function.utils
Argparse function parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.argparse_function.utils.emit_utils
cdd.argparse_function.utils.emit_utils
Utility functions for cdd.emit.argparse_function
Parameters:
Name | Type | Description | Default |
---|
parse_out_param
Turns the class_def repr of '--dataset_name', type=str, help='name of dataset.', required=True, default='mnist' into Tuple[Literal['dataset_name'], {"typ": Literal["str"], "doc": Literal["name of dataset."], "default": Literal["mnist"]}]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
Expr
|
Expr |
required |
require_default
|
bool
|
Whether a default is required, if not found in doc, infer the proper default from type |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Name, dict with keys: 'typ', 'doc', 'default' |
Source code in cdd/argparse_function/utils/emit_utils.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
cdd.class_
cdd.class_
class parser and emitter
Parameters:
Name | Type | Description | Default |
---|
cdd.class_.emit
cdd.class_.emit
class
emitter
Parameters:
Name | Type | Description | Default |
---|
class_
class_(intermediate_repr, emit_call=False, class_name=None, class_bases=('object',), decorator_list=None, word_wrap=True, docstring_format='rest', emit_original_whitespace=False, emit_default_doc=False)
Construct a class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_call
|
bool
|
Whether to emit a |
required |
class_name
|
name
|
name of class |
required |
class_bases
|
Iterable[str]
|
bases of class (the generated class will inherit these) |
required |
decorator_list
|
Optional[List[str]]
|
List of decorators |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
emit_original_whitespace
|
bool
|
Whether to emit original whitespace or strip it out (in docstring) |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ClassDef
|
Class AST |
Source code in cdd/class_/emit.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
cdd.class_.parse
cdd.class_.parse
class
parser
Parameters:
Name | Type | Description | Default |
---|
class_
class_(class_def, class_name=None, merge_inner_function=None, infer_type=False, parse_original_whitespace=False, word_wrap=True)
Converts an AST to our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_def
|
Union[Module, ClassDef]
|
Class AST or Module AST with a ClassDef inside |
required |
class_name
|
Optional[str]
|
Name of |
required |
merge_inner_function
|
Optional[str]
|
Name of inner function to merge. If None, merge nothing. |
required |
infer_type
|
bool
|
Whether to try inferring the typ (from the default) |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/class_/parse.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
cdd.class_.utils
cdd.class_.utils
class parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.class_.utils.emit_utils
cdd.class_.utils.emit_utils
Utility functions for cdd.emit.class_
Parameters:
Name | Type | Description | Default |
---|
RewriteName
Bases: NodeTransformer
A :class:NodeTransformer
subclass that walks the abstract syntax tree and
allows modification of nodes. Here it modifies parameter names to be self.param_name
Parameters:
Name | Type | Description | Default |
---|
Set parameter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_ids
|
id
|
Container of AST |
required |
Source code in cdd/class_/utils/emit_utils.py
visit_Name
Rename parameter name with a self.
attribute prefix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Name
|
The AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[Name, Attribute]
|
|
Source code in cdd/class_/utils/emit_utils.py
cdd.class_.utils.parse_utils
cdd.class_.utils.parse_utils
Utility functions for cdd.parse.class
Parameters:
Name | Type | Description | Default |
---|
get_source
Call inspect.getsource and raise an error unless class definition could not be found
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
object to inspect |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[str]
|
The source |
Source code in cdd/class_/utils/parse_utils.py
cdd.class_.utils.shared_utils
cdd.class_.utils.shared_utils
Shared utility functions for cdd.class_
Parameters:
Name | Type | Description | Default |
---|
ClassEmitProtocol
Bases: Protocol
Protocol for class emitter
Parameters:
Name | Type | Description | Default |
---|
__call__
__call__(intermediate_repr: IntermediateRepr, emit_call: bool = False, class_name: Optional[str] = None, class_bases: Tuple[str] = ('object',), decorator_list: Optional[List[str]] = None, word_wrap: bool = True, docstring_format: Literal['rest', 'numpydoc', 'google'] = 'rest', emit_original_whitespace: bool = False, emit_default_doc: bool = False) -> ClassDef
Construct a class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_call
|
Whether to emit a |
required | |
class_name
|
name
|
name of class |
required |
class_bases
|
bases of class (the generated class will inherit these) |
required | |
decorator_list
|
List of decorators |
required | |
word_wrap
|
Whether to word-wrap. Set |
required | |
docstring_format
|
Format of docstring |
required | |
emit_original_whitespace
|
Whether to emit original whitespace or strip it out (in docstring) |
required | |
emit_default_doc
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Class AST |
Source code in cdd/class_/utils/shared_utils.py
ClassParserProtocol
Bases: Protocol
Protocol for class parser
Parameters:
Name | Type | Description | Default |
---|
__call__
__call__(class_def: Union[Module, ClassDef], class_name: Optional[str] = None, merge_inner_function: Optional[str] = None, infer_type: bool = False, parse_original_whitespace: bool = False, word_wrap: bool = True) -> IntermediateRepr
Converts an AST to our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_def
|
Class AST or Module AST with a ClassDef inside |
required | |
class_name
|
Name of |
required | |
merge_inner_function
|
Name of inner function to merge. If None, merge nothing. |
required | |
infer_type
|
Whether to try inferring the typ (from the default) |
required | |
parse_original_whitespace
|
Whether to parse original whitespace or strip it out |
required | |
word_wrap
|
Whether to word-wrap. Set |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
a dictionary consistent with |
Source code in cdd/class_/utils/shared_utils.py
cdd.compound
cdd.compound
cdd.compound
contains modules that combine multiple others
This is used for OpenAPI, CLI subcommands, and similar.
Parameters:
Name | Type | Description | Default |
---|
cdd.compound.doctrans
cdd.compound.doctrans
Helper to traverse the AST of the input file, extract the docstring out, parse and format to intended style, and emit
Parameters:
Name | Type | Description | Default |
---|
doctrans
Transform the docstrings found within provided filename to intended docstring_format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Python file to convert docstrings within. Edited in place. |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
type_annotations
|
bool
|
True to have type annotations (3.6+), False to place in docstring |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
Source code in cdd/compound/doctrans.py
cdd.compound.doctrans_utils
cdd.compound.doctrans_utils
Helpers to traverse the AST, extract the docstring out, parse and format to intended style
Parameters:
Name | Type | Description | Default |
---|
DocTrans
Bases: NodeTransformer
Walk the nodes modifying the docstring and inlining||commenting types as it goes
Parameters:
Name | Type | Description | Default |
---|
Transform the docstrings found to intended docstring_format, potentially manipulating type annotations also
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
type_annotations
|
bool
|
True to have type annotations (3.6+), False to place in docstring |
required |
existing_type_annotations
|
bool
|
Whether there are any type annotations (3.6+) |
required |
whole_ast
|
AST``
|
The entire input AST, useful for lookups by location |
required |
Source code in cdd/compound/doctrans_utils.py
visit_AnnAssign
Handle AnnAssign
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AnnAssign
|
AnnAssign |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[AnnAssign, Assign]
|
|
Source code in cdd/compound/doctrans_utils.py
visit_Assign
Handle Assign
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Assign
|
Assign |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[Assign, AnnAssign]
|
|
Source code in cdd/compound/doctrans_utils.py
visit_FunctionDef
visits the FunctionDef
, potentially augmenting its docstring and argument types
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
FunctionDef
|
FunctionDef |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
Potentially changed FunctionDef |
Source code in cdd/compound/doctrans_utils.py
clear_annotation
Remove annotations and type_comments from node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
AST node with annotations and type_comments set to |
Source code in cdd/compound/doctrans_utils.py
doctransify_cst
Carefully replace only docstrings, function return annotations, assignment and annotation assignments. (maintaining all other existing whitespace, comments, &etc.); and only when cdd has changed them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cst_list
|
list[NamedTuple]
|
List of |
required |
node
|
AST
|
AST node with a |
required |
Source code in cdd/compound/doctrans_utils.py
has_type_annotations
Whether the node—incl. any nodes within this node—have type annotations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Source code in cdd/compound/doctrans_utils.py
cdd.compound.exmod
cdd.compound.exmod
Not a dead module
Parameters:
Name | Type | Description | Default |
---|
exmod
exmod(emit_name, module, blacklist, whitelist, output_directory, target_module_name, mock_imports, emit_sqlalchemy_submodule, extra_modules, no_word_wrap, recursive, dry_run, filesystem_layout='as_input', extra_modules_to_all=None)
Expose module as emit
types into output_directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emit_name
|
list[Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]]
|
What type(s) to generate. |
required |
module
|
str
|
Module name or path |
required |
blacklist
|
Union[list[str], tuple[str]]
|
Modules/FQN to omit. If unspecified will emit all (unless whitelist). |
required |
whitelist
|
Union[list[str], tuple[str]]
|
Modules/FQN to emit. If unspecified will emit all (minus blacklist). |
required |
output_directory
|
str
|
Where to place the generated exposed interfaces to the given |
required |
target_module_name
|
Optional[str]
|
Target module name |
required |
mock_imports
|
bool
|
Whether to generate mock TensorFlow imports |
required |
emit_sqlalchemy_submodule
|
bool
|
Whether to emit submodule "sqlalchemy_mod/{init,connection,create_tables}.py" |
required |
extra_modules
|
Optional[List[str]]
|
Additional module(s) to expose; specifiable multiple times. Prepended to symbol auto-importer |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
recursive
|
bool
|
Recursively traverse module hierarchy and recreate hierarchy with exposed interfaces |
required |
dry_run
|
bool
|
Show what would be created; don't actually write to the filesystem |
required |
filesystem_layout
|
Literal["java", "as_input"]
|
Hierarchy of folder and file names generated. "java" is file per package per name. |
required |
extra_modules_to_all
|
Optional[tuple[tuple[str, frozenset], ...]]
|
Internal arg. Prepended to symbol resolver. E.g., |
required |
Source code in cdd/compound/exmod.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
exmod_single_folder
exmod_single_folder(emit_name, module, blacklist, whitelist, output_directory, first_output_directory, mock_imports, no_word_wrap, dry_run, module_root_dir, module_root, module_name, new_module_name, filesystem_layout, extra_modules_to_all)
Expose module as emit
types into output_directory
. Single folder (non-recursive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emit_name
|
list[Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]]
|
What type(s) to generate. |
required |
module
|
str
|
Module name or path |
required |
blacklist
|
Union[list[str], tuple[str]]
|
Modules/FQN to omit. If unspecified will emit all (unless whitelist). |
required |
whitelist
|
Union[list[str], tuple[str]]
|
Modules/FQN to emit. If unspecified will emit all (minus blacklist). |
required |
output_directory
|
str
|
Where to place the generated exposed interfaces to the given |
required |
first_output_directory
|
str
|
Initial output directory (e.g., direct from |
required |
mock_imports
|
bool
|
Whether to generate mock TensorFlow imports |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
dry_run
|
bool
|
Show what would be created; don't actually write to the filesystem |
required |
module_root_dir
|
str
|
|
required |
module_root
|
str
|
|
required |
module_name
|
str
|
|
required |
new_module_name
|
str
|
|
required |
filesystem_layout
|
Literal["java", "as_input"]
|
Hierarchy of folder and file names generated. "java" is file per package per name. |
required |
extra_modules_to_all
|
Optional[tuple[tuple[str, frozenset], ...]]
|
Internal arg. Prepended to symbol resolver. E.g., |
required |
Source code in cdd/compound/exmod.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
|
cdd.compound.exmod_utils
cdd.compound.exmod_utils
Exmod utils
Parameters:
Name | Type | Description | Default |
---|
emit_file_on_hierarchy
emit_file_on_hierarchy(name_orig_ir, emit_name, module_name, new_module_name, mock_imports, filesystem_layout, extra_modules_to_all, output_directory, first_output_directory, no_word_wrap, dry_run)
Generate Java-package—or match input—style file hierarchy from fully-qualified module name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_orig_ir
|
str
|
FQ module name, original filename path, IR |
required |
emit_name
|
list[Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]]
|
What type(s) to generate. |
required |
module_name
|
str
|
Name of [original] module |
required |
new_module_name
|
str
|
Name of [new] module |
required |
mock_imports
|
bool
|
Whether to generate mock TensorFlow imports |
required |
filesystem_layout
|
Literal["java", "as_input"]
|
Hierarchy of folder and file names generated. "java" is file per package per name. |
required |
extra_modules_to_all
|
Optional[tuple[tuple[str, frozenset], ...]]
|
Internal arg. Prepended to symbol resolver. E.g., |
required |
output_directory
|
str
|
Where to place the generated exposed interfaces to the given |
required |
first_output_directory
|
str
|
Initial output directory (e.g., direct from |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
dry_run
|
bool
|
Show what would be created; don't actually write to the filesystem |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Tuple[Optional[str], str, ImportFrom]]
|
(mod_name or None, relative_filename_path, ImportFrom) to generated module |
Source code in cdd/compound/exmod_utils.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
emit_files_from_module_and_return_imports
emit_files_from_module_and_return_imports(module_name, module_root_dir, new_module_name, emit_name, module, output_directory, first_output_directory, mock_imports, no_word_wrap, dry_run, filesystem_layout, extra_modules_to_all)
Emit type emit_name
of all files in module_root_dir
into output_directory
on new_module_name
hierarchy. Then return the new imports.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Name of existing module |
required |
module_root_dir
|
str
|
Root dir of existing module |
required |
new_module_name
|
str
|
New module name |
required |
emit_name
|
list[Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]]
|
What type(s) to generate. |
required |
module
|
Module
|
Module itself |
required |
output_directory
|
str
|
Where to place the generated exposed interfaces to the given |
required |
first_output_directory
|
str
|
Initial output directory (e.g., direct from |
required |
mock_imports
|
bool
|
Whether to generate mock TensorFlow imports |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
dry_run
|
bool
|
Show what would be created; don't actually write to the filesystem |
required |
filesystem_layout
|
Literal["java", "as_input"]
|
Hierarchy of folder and file names generated. "java" is file per package per name. |
required |
extra_modules_to_all
|
Optional[tuple[tuple[str, frozenset], ...]]
|
Internal arg. Prepended to symbol resolver. E.g., |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[Tuple[Optional[str], str, ImportFrom]]
|
List of (mod_name or None, relative_filename_path, ImportFrom) to generated module(s) |
Source code in cdd/compound/exmod_utils.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
|
get_module_contents
Helper function to get the recursive inner module contents
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Something to |
required |
module_root_dir
|
str
|
Root of module |
required |
current_module
|
Optional[str]
|
The current module |
required |
_result
|
dict
|
The result var (used internally as accumulator) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Dict[str,Generator[Any]]
|
fully-qualified module name to values (could be modules, classes, and whatever other symbols are exposed) |
Source code in cdd/compound/exmod_utils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
cdd.compound.gen
cdd.compound.gen
Functionality to generate classes, functions, and/or argparse functions from the input mapping
Parameters:
Name | Type | Description | Default |
---|
gen
gen(name_tpl, input_mapping, parse_name, emit_name, output_filename, prepend=None, imports_from_file=None, emit_call=False, emit_default_doc=True, emit_and_infer_imports=False, decorator_list=None, phase=0, no_word_wrap=None)
Generate classes, functions, and/or argparse functions from the input mapping
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tpl
|
str
|
Template for the name, e.g., |
required |
input_mapping
|
str
|
Fully-qualified module, filepath, or directory. |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid", "infer"]
|
Which type to parse. |
required |
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
output_filename
|
str
|
Output file to write to |
required |
prepend
|
Optional[str]
|
Prepend file with this. Use ' ' for newlines. |
required |
imports_from_file
|
Optional[str]
|
Extract imports from file and append to |
required |
emit_call
|
bool
|
Whether to emit a |
required |
emit_and_infer_imports
|
bool
|
Whether to emit and infer imports at the top of the generated code |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
phase
|
int
|
Which phase to run through. E.g., SQLalchemy may require multiple phases to resolve foreign keys |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
Source code in cdd/compound/gen.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
cdd.compound.gen_utils
cdd.compound.gen_utils
Utility functions for cdd.gen
Parameters:
Name | Type | Description | Default |
---|
file_to_input_mapping
Create an input_mapping
from a given file, i.e. Dict[str, AST]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
Location of JSON or Python file |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid", "infer"]
|
Which type to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict``
|
Dictionary of string (name) to AST node |
Source code in cdd/compound/gen_utils.py
gen_file
gen_file(name_tpl, input_mapping_it, parse_name, emit_name, output_filename, prepend, emit_call, emit_and_infer_imports, emit_default_doc, decorator_list, no_word_wrap, imports, functions_and_classes=None)
Generate Python file of containing input_mapping_it
.values converted to emit_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tpl
|
str
|
Template for the name, e.g., |
required |
input_mapping_it
|
Iterator[tuple[str, AST]]
|
Import location of mapping/2-tuple collection. |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to parse. |
required |
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
output_filename
|
str
|
Output file to write to |
required |
prepend
|
Optional[str]
|
Prepend file with this. Use ' ' for newlines. |
required |
emit_call
|
bool
|
Whether to emit a |
required |
emit_and_infer_imports
|
bool
|
Whether to emit and infer imports at the top of the generated code |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
imports
|
str
|
Import to preclude in Python file |
required |
functions_and_classes
|
Optional[tuple[AST]]
|
Functions and classes that have been preparsed |
required |
Source code in cdd/compound/gen_utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
gen_module
gen_module(decorator_list, emit_and_infer_imports, emit_call, emit_default_doc, emit_name, functions_and_classes, imports, input_mapping_it, name_tpl, no_word_wrap, parse_name, prepend, global__all__=None)
Generate Python module input_mapping_it
.values converted to emit_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tpl
|
str
|
Template for the name, e.g., |
required |
input_mapping_it
|
Iterator[tuple[str, AST]]
|
Import location of mapping/2-tuple collection. |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to parse. |
required |
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
prepend
|
Optional[str]
|
Prepend file with this. Use ' ' for newlines. |
required |
emit_call
|
bool
|
Whether to emit a |
required |
emit_and_infer_imports
|
bool
|
Whether to emit and infer imports at the top of the generated code |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
imports
|
Optional[str]
|
Import to preclude in Python file |
required |
functions_and_classes
|
Optional[Tuple[AST]]
|
Functions and classes that have been preparsed |
required |
global__all__
|
list[str]
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Module with everything contained inside, e.g., all the imports, parsed out functions and classes |
Source code in cdd/compound/gen_utils.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
get_emit_kwarg
Emit keyword arguments have different requirements dependent on emitter Determine correct one, and always include the name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
emit_call
|
bool
|
Whether to emit a |
required |
name_tpl
|
str
|
Template for the name, e.g., |
required |
name
|
str
|
Interpolates into |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict``
|
Dictionary of keyword arguments targeted the specialised emit function. |
Source code in cdd/compound/gen_utils.py
get_functions_and_classes
get_functions_and_classes(decorator_list, emit_call, emit_default_doc, emit_name, global__all__, input_mapping_it, name_tpl, no_word_wrap, parse_name)
Emitted functions and/or classes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
emit_call
|
bool
|
Whether to emit a |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
global__all__
|
list[str]
|
|
required |
input_mapping_it
|
Iterator[Tuple[str,AST]]
|
Import location of mapping/2-tuple collection. |
required |
name_tpl
|
str
|
Template for the name, e.g., |
required |
no_word_wrap
|
Optional[Literal[True]]
|
Whether word-wrap is disabled (on emission). |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[Union[FunctionDef, ClassDef]]
|
Side-effect of appending |
Source code in cdd/compound/gen_utils.py
get_input_mapping_from_path
Given (module_path, symbol_name) acquire file path, ast.parse
out all top-level symbols matching emit_name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to generate. |
required |
module_path
|
str
|
Module path |
required |
symbol_name
|
str
|
Symbol to import from module |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Dictionary of (name, AST) where AST is produced by a cdd emitter matching |
Source code in cdd/compound/gen_utils.py
get_parser
Get parser function specialised for input node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
Node to parse |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid","infer"]
|
Which type to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Callable[[...], dict]`
|
Function which returns intermediate_repr |
Source code in cdd/shared/parse/utils/parser_utils.py
cdd.compound.openapi
cdd.compound.openapi
Parsers and emitters for OpenAPI
Parameters:
Name | Type | Description | Default |
---|
cdd.compound.openapi.emit
cdd.compound.openapi.emit
OpenAPI emitter function(s)
Parameters:
Name | Type | Description | Default |
---|
openapi
Emit OpenAPI dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_model_route_id_cruds
|
Iterable[NameModelRouteIdCrud]
|
Collection of (name, model, route, id, crud) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
OpenAPI dict |
Source code in cdd/compound/openapi/emit.py
cdd.compound.openapi.gen_openapi
cdd.compound.openapi.gen_openapi
All encompassing solution to generating the OpenAPI schema
Parameters:
Name | Type | Description | Default |
---|
openapi_bulk
Generate OpenAPI from models, routes on app
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app_name
|
str
|
Variable name (Bottle App) |
required |
model_paths
|
list[str]
|
The path/module-resolution(s) whence the model(s) can be found |
required |
routes_paths
|
list[str]
|
The path/module-resolution(s) whence the route(s) can be found |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
OpenAPI dictionary |
Source code in cdd/compound/openapi/gen_openapi.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
cdd.compound.openapi.gen_routes
cdd.compound.openapi.gen_routes
Generate routes
Parameters:
Name | Type | Description | Default |
---|
gen_routes
Generate route(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
str
|
Variable name (Bottle App) |
required |
model_path
|
str
|
The path/module-resolution whence the model is |
required |
model_name
|
str
|
Name of the model to recover from the |
required |
crud
|
Union[Literal['C', 'R'], Literal['C', 'U'], Literal['C', 'D'], Literal['R', 'C'],
Literal['R', 'U'], Literal['R', 'D'], Literal['U', 'C'], Literal['U', 'R'],
Literal['U', 'D'], Literal['D', 'C'], Literal['D', 'R'], Literal['D', 'U'],
Literal['C', 'R', 'U'], Literal['C', 'R', 'D'], Literal['C', 'U', 'R'],
Literal['C', 'U', 'D'], Literal['C', 'D', 'R'], Literal['C', 'D', 'U'],
Literal['R', 'C', 'U'], Literal['R', 'C', 'D'], Literal['R', 'U', 'C'],
Literal['R', 'U', 'D'], Literal['R', 'D', 'C'], Literal['R', 'D', 'U'],
Literal['U', 'C', 'R'], Literal['U', 'C', 'D'], Literal['U', 'R', 'C'],
Literal['U', 'R', 'D'], Literal['U', 'D', 'C'], Literal['U', 'D', 'R'],
Literal['D', 'C', 'R'], Literal['D', 'C', 'U'], Literal['D', 'R', 'C'],
Literal['D', 'R', 'U'], Literal['D', 'U', 'C'], Literal['D', 'U', 'R']]
|
(C)reate (R)ead (U)pdate (D)elete, like "CRUD" for all or "CD" for "Create" and "Delete" |
required |
route
|
str
|
The path of the resource |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterator[FunctionDef]
|
Iterator of functions representing relevant CRUD operations |
Source code in cdd/compound/openapi/gen_routes.py
upsert_routes
Upsert the routes
to the routes_path
, on merge use existing body and replace interface/prototype
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
str
|
Variable name (Bottle App) |
required |
routes
|
Iterator[FunctionDef]
|
Iterator of functions representing relevant CRUD operations |
required |
route
|
str
|
The path of the resource |
required |
primary_key
|
str
|
The primary key or id to lookup on for the route |
required |
routes_path
|
str
|
The path/module-resolution whence the routes are / will be |
required |
Source code in cdd/compound/openapi/gen_routes.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
cdd.compound.openapi.parse
cdd.compound.openapi.parse
OpenAPI parsers
Parameters:
Name | Type | Description | Default |
---|
openapi
OpenAPI parser
Parameters:
Name | Type | Description | Default |
---|---|---|---|
openapi_str
|
str
|
The OpenAPI str |
required |
routes_dict
|
dict
|
Has keys ("route", "name", "method") |
required |
summary
|
str
|
summary string (used as fallback) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
OpenAPI dictionary |
Source code in cdd/compound/openapi/parse.py
cdd.compound.openapi.utils
cdd.compound.openapi.utils
OpenAPI parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.compound.openapi.utils.emit_openapi_utils
cdd.compound.openapi.utils.emit_openapi_utils
Utility functions for cdd.emit.openapi
Parameters:
Name | Type | Description | Default |
---|
components_paths_from_name_model_route_id_crud
Update components
and paths
from (name, model, route, _id, crud)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
components
|
dict
|
OpenAPI components (updated by this function) |
required |
paths
|
dict
|
OpenAPI paths (updated by this function) |
required |
name
|
str
|
Name of the entity |
required |
model
|
dict
|
Schema of entity |
required |
route
|
str
|
API path |
required |
_id
|
str
|
Primary key to access identity by id |
required |
crud
|
Union[Literal['C', 'R'], Literal['C', 'U'], Literal['C', 'D'], Literal['R', 'C'],
Literal['R', 'U'], Literal['R', 'D'], Literal['U', 'C'], Literal['U', 'R'],
Literal['U', 'D'], Literal['D', 'C'], Literal['D', 'R'], Literal['D', 'U'],
Literal['C', 'R', 'U'], Literal['C', 'R', 'D'], Literal['C', 'U', 'R'],
Literal['C', 'U', 'D'], Literal['C', 'D', 'R'], Literal['C', 'D', 'U'],
Literal['R', 'C', 'U'], Literal['R', 'C', 'D'], Literal['R', 'U', 'C'],
Literal['R', 'U', 'D'], Literal['R', 'D', 'C'], Literal['R', 'D', 'U'],
Literal['U', 'C', 'R'], Literal['U', 'C', 'D'], Literal['U', 'R', 'C'],
Literal['U', 'R', 'D'], Literal['U', 'D', 'C'], Literal['U', 'D', 'R'],
Literal['D', 'C', 'R'], Literal['D', 'C', 'U'], Literal['D', 'R', 'C'],
Literal['D', 'R', 'U'], Literal['D', 'U', 'C'], Literal['D', 'U', 'R']]
|
(C)reate (R)ead (U)pdate (D)elete, like "CRUD" for all or "CD" for "Create" and "Delete" |
required |
Source code in cdd/compound/openapi/utils/emit_openapi_utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
cdd.compound.openapi.utils.emit_utils
cdd.compound.openapi.utils.emit_utils
Utility functions for cdd.emit.sqlalchemy
Parameters:
Name | Type | Description | Default |
---|
cdd.compound.openapi.utils.parse_utils
cdd.compound.openapi.utils.parse_utils
Utility functions for cdd.parse.openapi
Parameters:
Name | Type | Description | Default |
---|
extract_entities
Extract entities from an OpenAPI string, where entities are defines as anything within "```"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
openapi_str
|
str
|
The OpenAPI str |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[str]
|
Entities |
Source code in cdd/compound/openapi/utils/parse_utils.py
cdd.compound.sync_properties
cdd.compound.sync_properties
Functionality to synchronise properties
Parameters:
Name | Type | Description | Default |
---|
sync_properties
sync_properties(input_eval, input_filename, input_params, output_filename, output_params, output_param_wrap=None)
Sync one property, inline to a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_eval
|
bool
|
Whether to evaluate the |
required |
input_filename
|
str
|
Filename to find |
required |
input_params
|
list[str]
|
Locations within file of properties. Can be top level like |
required |
output_filename
|
str
|
Filename that will be edited in place, the property within this file (to update) is selected by |
required |
output_params
|
list[str]
|
Parameters to update. E.g., |
required |
output_param_wrap
|
|
required |
Source code in cdd/compound/sync_properties.py
sync_property
sync_property(input_eval, input_param, input_ast, input_filename, output_param, output_param_wrap, output_ast)
Sync a single property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_eval
|
bool
|
Whether to evaluate the |
required |
input_param
|
list[str]
|
Location within file of property. Can be top level like |
required |
input_ast
|
AST
|
AST of the input file |
required |
input_filename
|
str
|
Filename of the input (used in |
required |
output_param
|
str
|
Parameters to update. E.g., |
required |
output_param_wrap
|
|
required | |
output_ast
|
AST
|
AST of the input file |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
New AST derived from |
Source code in cdd/compound/sync_properties.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
cdd.docstring
cdd.docstring
docstring parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.docstring.emit
cdd.docstring.emit
Docstring emitter.
Emits into these formats from the cdd_python common IR format: - ReST docstring format (Sphinx) - numpydoc docstring format - Google's docstring format
Parameters:
Name | Type | Description | Default |
---|
docstring
docstring(intermediate_repr, docstring_format='rest', purpose='function', word_wrap=True, indent_level=0, emit_separating_tab=True, emit_types=True, emit_original_whitespace=False, emit_default_doc=True)
Converts an IR to a docstring
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
purpose
|
Literal['class', 'function']
|
|
required |
if purpose == 'function' elif purpose == 'class' then
|
:param |
required | |
:cvar`
|
:cvar` |
required | |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
indent_level
|
int
|
indentation level whence: 0=no_tabs, 1=one tab; 2=two tabs |
required |
emit_separating_tab
|
bool
|
|
required |
and return and desc
|
:param and return and desc |
required | |
emit_types
|
bool
|
|
required |
lines
|
:type` lines
|
|
required |
emit_original_whitespace
|
bool
|
Whether to emit original whitespace or strip it out |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
docstring |
Source code in cdd/docstring/emit.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
cdd.docstring.parse
cdd.docstring.parse
Docstring parser
Parameters:
Name | Type | Description | Default |
---|
docstring
docstring(doc_string, infer_type=False, return_tuple=False, parse_original_whitespace=False, emit_default_prop=True, emit_default_doc=True)
Converts a docstring to an AST
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_string
|
Union[str, Dict]
|
docstring portion |
required |
infer_type
|
bool
|
Whether to try inferring the typ (from the default) |
required |
return_tuple
|
Tuple
|
Whether to return a tuple, or just the intermediate_repr |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
emit_default_prop
|
dict
|
Whether to include the default dictionary property. |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Union[dict, Tuple[dict, bool]]]
|
intermediate_repr, whether it returns or not |
Source code in cdd/docstring/parse.py
cdd.docstring.utils
cdd.docstring.utils
docstring parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.docstring.utils.emit_utils
cdd.docstring.utils.emit_utils
Utility functions for cdd.emit.docstring
Parameters:
Name | Type | Description | Default |
---|
interpolate_defaults
interpolate_defaults(param, default_search_announce=None, require_default=False, emit_default_doc=True)
Correctly set the 'default' and 'doc' parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
default_search_announce
|
Optional[Union[str, Iterable[str]]]
|
Default text(s) to look for. If None, uses default specified in default_utils. |
required |
require_default
|
bool
|
Whether a default is required, if not found in doc, infer the proper default from type |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Name, dict with keys: 'typ', 'doc', 'default' |
Source code in cdd/docstring/utils/emit_utils.py
cdd.docstring.utils.parse_utils
cdd.docstring.utils.parse_utils
Docstring parse utils
Parameters:
Name | Type | Description | Default |
---|
parse_adhoc_doc_for_typ
Google's Keras and other frameworks have an adhoc syntax.
Call this function after the first-pass; i.e., after the arg {name, doc, typ, default} are 'known'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc
|
str
|
Possibly ambiguous docstring for argument, that might hint as to the type |
required |
name
|
str
|
Name of argument; useful for debugging and if the name hints as to the type |
required |
default_is_none
|
bool
|
Whether the default is |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[str]
|
The type (if determined) else |
Source code in cdd/docstring/utils/parse_utils.py
cdd.function
cdd.function
function parser and emitter module
Parameters:
Name | Type | Description | Default |
---|
cdd.function.emit
cdd.function.emit
Function/method emitter
Parameters:
Name | Type | Description | Default |
---|
function
function(intermediate_repr, function_name, function_type, word_wrap=True, emit_default_doc=False, docstring_format='rest', indent_level=2, emit_separating_tab=PY3_8, type_annotations=True, emit_as_kwonlyargs=True, emit_original_whitespace=False)
Construct a function from our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
function_name
|
name
|
name of function_def |
required |
function_type
|
Optional[Literal['self', 'cls', 'static']]
|
Type of function, static is static or global method, others just become first arg |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
indent_level
|
int
|
docstring indentation level whence: 0=no_tabs, 1=one tab; 2=two tabs |
required |
emit_separating_tab
|
bool
|
|
required |
and return and desc
|
:param and return and desc |
required | |
type_annotations
|
bool
|
True to have type annotations (3.6+), False to place in docstring |
required |
emit_as_kwonlyargs
|
bool
|
Whether argument(s) emitted must be keyword only |
required |
emit_original_whitespace
|
bool
|
Whether to emit an original whitespace (in docstring) or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
AST node for function definition |
Source code in cdd/function/emit.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
cdd.function.parse
cdd.function.parse
Function parser
Parameters:
Name | Type | Description | Default |
---|
function
function(function_def, infer_type=False, parse_original_whitespace=False, word_wrap=True, function_type=None, function_name=None)
Converts a method to our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_def
|
Union[FunctionDef, FunctionType]
|
AST node for function definition |
required |
infer_type
|
bool
|
Whether to try inferring the typ (from the default) |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
function_type
|
Literal['self', 'cls', 'static']
|
Type of function, static is static or global method, others just become first arg |
required |
function_name
|
name
|
name of function_def |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/function/parse.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
cdd.function.utils
cdd.function.utils
function parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.function.utils.emit_utils
cdd.function.utils.emit_utils
Utility functions for cdd.emit.function_utils
Parameters:
Name | Type | Description | Default |
---|
make_call_meth
Construct a __call__
method from the provided body
Parameters:
Name | Type | Description | Default |
---|---|---|---|
body
|
list[AST]
|
The body, probably from a |
required |
return_type
|
Optional[str]
|
The return type of the parent symbol (probably class). Used to fill in |
required |
param_names
|
id
|
Container of AST |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
Internal function for |
Source code in cdd/function/utils/emit_utils.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
cdd.function.utils.parse_utils
cdd.function.utils.parse_utils
Utility functions for cdd.parse.function
Parameters:
Name | Type | Description | Default |
---|
cdd.json_schema
cdd.json_schema
JSON-schema parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.json_schema.emit
cdd.json_schema.emit
JSON schema emitter
Parameters:
Name | Type | Description | Default |
---|
json_schema
json_schema(intermediate_repr, identifier=None, emit_original_whitespace=False, emit_default_doc=False, word_wrap=False)
Construct a JSON schema dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
identifier
|
id
|
The |
required |
emit_original_whitespace
|
bool
|
Whether to emit original whitespace (in top-level |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
JSON Schema dict |
Source code in cdd/json_schema/emit.py
json_schema_file
Emit input_mapping
—as JSON schema—into output_filename
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_mapping
|
Dict[str, AST]
|
Import location of mapping/2-tuple collection. |
required |
output_filename
|
str
|
Output file to write to |
required |
Source code in cdd/json_schema/emit.py
cdd.json_schema.parse
cdd.json_schema.parse
JSON schema parser
Parameters:
Name | Type | Description | Default |
---|
json_schema
Parse a JSON schema into the IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_schema_dict
|
dict
|
A valid JSON schema as a Python dict |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
IR representation of the given JSON schema |
Source code in cdd/json_schema/parse.py
cdd.json_schema.utils
cdd.json_schema.utils
JSON-schema parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.json_schema.utils.emit_utils
cdd.json_schema.utils.emit_utils
Utility functions for cdd.emit.json_schema
Parameters:
Name | Type | Description | Default |
---|
param2json_schema_property
Turn a param into a JSON schema property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
required
|
list
|
Required parameters. This function may push to the list. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
JSON schema property. Also, may push to |
Source code in cdd/json_schema/utils/emit_utils.py
cdd.json_schema.utils.parse_utils
cdd.json_schema.utils.parse_utils
Utility functions for cdd.parse.json_schema
Parameters:
Name | Type | Description | Default |
---|
json_schema_property_to_param
Convert a JSON schema property to a param
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
required
|
FrozenSet[str]
|
Names of all required parameters |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Name, dict with keys: 'typ', 'doc', 'default' |
Source code in cdd/json_schema/utils/parse_utils.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
cdd.json_schema.utils.shared_utils
cdd.json_schema.utils.shared_utils
Shared utility functions for JSON schema
Parameters:
Name | Type | Description | Default |
---|
cdd.pydantic
cdd.pydantic
pydantic parser and emitter utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.pydantic.emit
cdd.pydantic.emit
Pydantic class
emitter
https://pydantic-docs.helpmanual.io/usage/schema/
Parameters:
Name | Type | Description | Default |
---|
cdd.pydantic.parse
cdd.pydantic.parse
Pydantic class
parser
https://pydantic-docs.helpmanual.io/usage/schema/
Parameters:
Name | Type | Description | Default |
---|
cdd.routes
cdd.routes
Routes for parsing/emitting. Currently, Bottle, and aimed for OpenAPI.
Parameters:
Name | Type | Description | Default |
---|
cdd.routes.emit
cdd.routes.emit
Module of route emitters
Parameters:
Name | Type | Description | Default |
---|
cdd.routes.emit.bottle
cdd.routes.emit.bottle
Emit constant strings with interpolated values for route generation
Parameters:
Name | Type | Description | Default |
---|
create
Create the create
route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
str
|
Variable name (Bottle App) |
required |
name
|
str
|
Name of entity |
required |
route
|
str
|
The path of the resource |
required |
variant
|
int
|
Number of variant |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Create route variant with interpolated values |
Source code in cdd/routes/emit/bottle.py
create_util
Create utility function that the create
emitter above uses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of entity |
required |
route
|
str
|
The path of the resource |
required |
variant
|
int
|
Number of variant |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Create route variant with interpolated values |
Source code in cdd/routes/emit/bottle.py
destroy
Create the destroy
route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
str
|
Variable name (Bottle App) |
required |
name
|
str
|
Name of entity |
required |
route
|
str
|
The path of the resource |
required |
primary_key
|
Any
|
The id |
required |
variant
|
int
|
Number of variant |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Create route variant with interpolated values |
Source code in cdd/routes/emit/bottle.py
read
Create the read
route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
str
|
Variable name (Bottle App) |
required |
name
|
str
|
Name of entity |
required |
route
|
str
|
The path of the resource |
required |
primary_key
|
Any
|
The id |
required |
variant
|
int
|
Number of variant |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Create route variant with interpolated values |
Source code in cdd/routes/emit/bottle.py
cdd.routes.emit.bottle_constants_utils
cdd.routes.emit.bottle_constants_utils
Constant strings and tuples of strings which are to be interpolated in emit.py
Parameters:
Name | Type | Description | Default |
---|
cdd.routes.parse
cdd.routes.parse
Module of route parsers
Parameters:
Name | Type | Description | Default |
---|
cdd.routes.parse.bottle
cdd.routes.parse.bottle
Parsers for routes
Parameters:
Name | Type | Description | Default |
---|
bottle
Parse bottle API
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_def
|
Union[FunctionDef, FunctionType]
|
Function definition of a bottle route, like |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
OpenAPI representation of the given route |
Source code in cdd/routes/parse/bottle.py
cdd.routes.parse.bottle_utils
cdd.routes.parse.bottle_utils
Parser utils for routes
Parameters:
Name | Type | Description | Default |
---|
get_route_meta
Get the (func_name, app_name, route_path, http_method)s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mod
|
Module
|
Parsed AST containing routes |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterator[tuple[str, str, str, str]]
|
Iterator of tuples of (func_name, app_name, route_path, http_method) |
Source code in cdd/routes/parse/bottle_utils.py
cdd.routes.parse.fastapi
cdd.routes.parse.fastapi
FastAPI route parser
Parameters:
Name | Type | Description | Default |
---|
fastapi
Parse a single FastAPI route
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fastapi_route
|
AsyncFunctionDef
|
A single FastAPI route |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Pair of (str, dict) consisting of API path to a dictionary of form { Literal["post","get","put","patch"]: { "requestBody": { "$ref": str, "required": boolean }, "responses": { number: { "content": {string: {"schema": {"$ref": string}, "description": string} } } }, "summary": string } } |
Source code in cdd/routes/parse/fastapi.py
cdd.routes.parse.fastapi_utils
cdd.routes.parse.fastapi_utils
FastAPI utils
Parameters:
Name | Type | Description | Default |
---|
model_handler
Create fully-qualified model name from unqualified name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Key name |
required |
model_name
|
Union[Literal["ref"], str]
|
Not fully-qualified model name or a |
required |
location
|
str
|
Full-qualified parent path |
required |
mime_type
|
str
|
MIME type |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[Union[str,"content"], dict]
|
Tuple["content", JSON ref to model name, of form |
Source code in cdd/routes/parse/fastapi_utils.py
parse_fastapi_responses
Parse FastAPI "responses" key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
responses
|
Dict
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Transformed FastAPI "responses" |
Source code in cdd/routes/parse/fastapi_utils.py
cdd.shared
cdd.shared
cdd-wide shared utilities module
Parameters:
Name | Type | Description | Default |
---|
cdd.shared.ast_cst_utils
cdd.shared.ast_cst_utils
Utils for working with AST (builtin) and cdd's CST
Parameters:
Name | Type | Description | Default |
---|
Delta
Bases: Enum
Maybe Enum for what every maybe_
function in ast_cst_utils
can return
Parameters:
Name | Type | Description | Default |
---|
debug_doctrans
Print debug statement if changed is not nop
Parameters:
Name | Type | Description | Default |
---|---|---|---|
changed
|
Delta
|
Delta value indicating what changed (if anything) |
required |
affector
|
str
|
What is being changed |
required |
name
|
str
|
Name of what is being changed |
required |
typ
|
str
|
AST type name of what is being changed |
required |
Source code in cdd/shared/ast_cst_utils.py
find_cst_at_ast
Find (first) CST node matching AST node
(uses _location
from annotate_ancestry
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cst_list
|
list[NamedTuple]
|
List of |
required |
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[Optional[int], Optional[NamedTuple]]`
|
Matching idx and element from cst_list if found else (None, None) |
Source code in cdd/shared/ast_cst_utils.py
maybe_replace_doc_str_in_function_or_class
Maybe replace the doc_str of a function or class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[ClassDef, AsyncFunctionDef, FunctionDef]
|
AST node |
required |
cst_idx
|
int
|
Index of start of function/class in cst_list |
required |
cst_list
|
list[NamedTuple]
|
List of |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Delta
|
Delta value indicating what changed (if anything) |
Source code in cdd/shared/ast_cst_utils.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
maybe_replace_function_args
Maybe replace the doc_str of a function or class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_node
|
Union[AsyncFunctionDef, FunctionDef]
|
AST function node |
required |
cur_ast_node
|
AST
|
AST function node of CST (with fake body) |
required |
cst_idx
|
int
|
Index of start of function/class in cst_list |
required |
cst_list
|
list[NamedTuple]
|
List of |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Delta
|
Delta value indicating what changed (if anything) |
Source code in cdd/shared/ast_cst_utils.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
maybe_replace_function_return_type
Maybe replace the function's return type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_node
|
Union[AsyncFunctionDef, FunctionDef]
|
AST function node |
required |
cur_ast_node
|
AST
|
AST function node of CST (with fake body) |
required |
cst_idx
|
int
|
Index of start of function/class in cst_list |
required |
cst_list
|
list[NamedTuple]
|
List of |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Delta
|
Delta value indicating what changed (if anything) |
Source code in cdd/shared/ast_cst_utils.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
cdd.shared.ast_utils
cdd.shared.ast_utils
ast_utils, a bunch of helpers for converting input into ast.* input_str
Parameters:
Name | Type | Description | Default |
---|
RewriteAtQuery
Bases: NodeTransformer
Replace the node at query with given node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search
|
Search query, e.g., ['node_name', 'function_name', 'arg_name'] |
required | |
replacement_node
|
Node to replace this search |
required | |
replaced
|
Whether a node has been replaced (only replaces first occurrence) |
required |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search
|
list[str]
|
Search query, e.g., ['node_name', 'function_name', 'arg_name'] |
required |
replacement_node
|
AST
|
Node to replace this search |
required |
Source code in cdd/shared/ast_utils.py
generic_visit
visits the AST
, if it's the right one, replace it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
The AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
Potentially changed AST node |
Source code in cdd/shared/ast_utils.py
visit_FunctionDef
visits the FunctionDef
, if it's the right one, replace it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
FunctionDef
|
FunctionDef |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
Potentially changed FunctionDef |
Source code in cdd/shared/ast_utils.py
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 |
|
Undefined
Null class
Parameters:
Name | Type | Description | Default |
---|
Dict_to_dict
Create a dict
from a Dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
Dict
|
ast.Dict |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Python dictionary |
annotate_ancestry
Look to your roots. Find the child; find the parent. Sets _location and file attributes to every child node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node. Will be annotated in-place. |
required |
filename
|
Optional[str]
|
Where the node was originally defined. Sets the |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
Annotated AST node; also |
Source code in cdd/shared/ast_utils.py
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
|
ast_elts_to_container
Convert AST container to Python container
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node with elts attribute |
required |
container
|
type
|
Python container |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
instanceof container
|
Python container |
Source code in cdd/shared/ast_utils.py
ast_type_to_python_type
Unparse AST type as Python type
Implementation notes:
- this focuses on 'evaluated scalars' that can be represented as JSON
- think of this as a get_value
alternative
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Num,Bytes,Str,Constant,Dict,Set,Tuple,List]
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[dict,str,int,float,complex,bytes,list,tuple,set]
|
|
Source code in cdd/shared/ast_utils.py
cmp_ast
Compare if two nodes are equal. Verbatim stolen from meta.asttools
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node0
|
Union[AST, List[AST], Tuple[AST]]
|
First node |
required |
node1
|
Union[AST, List[AST], Tuple[AST]]
|
Second node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether they are equal (recursive) |
Source code in cdd/shared/ast_utils.py
code_quoted
Internally user-provided None
and non literal_eval
able input is quoted with ```
This function checks if the input is quoted such
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
Any
|
The input |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the input is code quoted |
Source code in cdd/shared/pure_utils.py
construct_module_with_symbols
Create a module out of the input module that only contains nodes
with a name contained in symbols
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Module
|
Input module |
required |
symbols
|
FrozenSet[str]
|
Symbols |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Module with only members whose |
Source code in cdd/shared/ast_utils.py
deduplicate
Deduplicate an iterable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
it
|
Union[Iterable, Generator, List, Tuple, Set, FrozenSet]
|
An iterable|collection with hashable elements |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterable
|
Deduplicated iterable of the input |
Source code in cdd/shared/ast_utils.py
deduplicate_sorted_imports
Deduplicate sorted imports. NOTE: for a more extensive solution use isort or ruff.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Module
|
Module |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Module but with duplicate import entries in first import block removed |
Source code in cdd/shared/ast_utils.py
2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 |
|
del_ass_where_name
Delete all Assign
/AnnAssign
in node body where id matches name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Module, ClassDef, FunctionDef, If, Try, While, With, AsyncFor, AsyncFunctionDef, AsyncWith,
ExceptHandler, Expression, For, IfExp, Interactive, Lambda ]
|
AST node with a '.body' |
required |
name
|
id
|
Name to match (matches against |
required |
Source code in cdd/shared/ast_utils.py
emit_ann_assign
Produce an AnnAssign
from the input
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AnnAssign
|
Something which parses to the form of |
Source code in cdd/shared/ast_utils.py
emit_arg
Produce an arg
from the input
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ast.arg
|
Something which parses to the form of |
Source code in cdd/shared/ast_utils.py
find_ast_type
Finds first AST node of the given type and possibly name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
Any AST node |
required |
node_name
|
Optional[str]
|
Name of AST node. If None, gives first found. |
required |
of_type
|
AST
|
Of which type to find |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
Found AST node |
Source code in cdd/shared/ast_utils.py
find_in_ast
Find and return the param from within the value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search
|
list[str]
|
Location within AST of property. Can be top level like |
required |
node
|
AST
|
AST node (must have a |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[AST]
|
AST node that was found, or None if nothing was found |
Source code in cdd/shared/ast_utils.py
func_arg2param
Converts a function argument to a param tuple
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func_arg
|
ast.arg
|
Function argument |
required |
default
|
dict
|
The default value, if None isn't added to returned dict |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Name, dict with keys: 'typ', 'doc', 'default' |
Source code in cdd/shared/ast_utils.py
get_ass_where_name
Find all Assign
/AnnAssign
in node body where id matches name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Module, ClassDef, FunctionDef, If, Try, While, With, AsyncFor, AsyncFunctionDef, AsyncWith,
ExceptHandler, Expression, For, IfExp, Interactive, Lambda ]
|
AST node with a '.body' |
required |
name
|
id
|
Name to match (matches against |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Generator[Union[Assign, AnnAssign]]
|
Generator of all matches names (.value) |
Source code in cdd/shared/ast_utils.py
get_at_root
Get the imports from a node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node with .body, probably an |
required |
types
|
tuple[str,...]`
|
The types to search for (uses in an |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[Union[]]
|
List of imports. Doesn't handle those within a try/except, condition, or not in root scope |
Source code in cdd/shared/ast_utils.py
get_doc_str
Similar to ast.get_docstring
except never clean
s and returns None
on failure rather than raising
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[str]
|
Docstring if found else None |
Source code in cdd/shared/ast_utils.py
get_function_type
Get the type of the function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function_def
|
FunctionDef
|
AST node for function definition |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Literal['self', 'cls', 'static']
|
Type of target, static is static or global method, others just become first arg |
Source code in cdd/shared/ast_utils.py
get_names
Get name(s) from: - Assign targets - AnnAssign target - Function, AsyncFunction, ClassDef
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Assign, AnnAssign, Function, AsyncFunctionDef, ClassDef]
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Generator[str]
|
All top-level symbols (except those within try/except and if/elif/else blocks) |
Source code in cdd/shared/ast_utils.py
get_types
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST|str
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Generator[str]
|
|
Source code in cdd/shared/ast_utils.py
get_value
Get the value from a Constant or a Str… or anything with a .value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Bytes, Constant, Name, Str, UnaryOp]
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Union[str, int, float, bool]]
|
Probably a string, but could be any constant value |
Source code in cdd/shared/ast_utils.py
infer_imports
Infer imports from AST nodes (Name|.annotation|.type_comment); in order; these: - typing - typing_extensions - collections.abc - sqlalchemy - pydantic
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Union[Module, ClassDef, FunctionDef, AsyncFunctionDef, Assign, AnnAssign]
|
Module, ClassDef, FunctionDef, AsyncFunctionDef, Assign, AnnAssign |
required |
modules_to_all
|
tuple[tuple[str, frozenset], ...]
|
Tuple of module_name to all of module; (str) to FrozenSet[str] |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Tuple[Union[Import, ImportFrom], ...]]
|
List of imports |
Source code in cdd/shared/ast_utils.py
2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 |
|
infer_type_and_default
Infer the type string from the default and typ
Parameters:
Name | Type | Description | Default |
---|---|---|---|
action
|
Optional[str]
|
Name of the action |
required |
default
|
Any
|
Initial default value |
required |
typ
|
Optional[str]
|
The type of the argument |
required |
required
|
bool
|
Whether to require the argument |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, Any, bool, str]
|
action (e.g., for |
Source code in cdd/shared/ast_utils.py
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
|
is_argparse_add_argument
Checks if AST node is a call to argument_parser.add_argument
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the input is the call to |
Source code in cdd/shared/ast_utils.py
is_argparse_description
Checks if AST node is argument_parser.description
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the input is the call to |
Source code in cdd/shared/ast_utils.py
it2literal
Convert a collection of constants into a type annotation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
it
|
Union[tuple[Union[str, int, float], ...], list[Union[str, int, float], ...]]
|
collection of constants |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Subscript
|
Subscript Literal for annotation |
Source code in cdd/shared/ast_utils.py
merge_assignment_lists
Merge multiple same-name lists within the body of a node into one, e.g., if you have multiple __all__
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Module, ClassDef, FunctionDef, If, Try, While, With, AsyncFor, AsyncFunctionDef, AsyncWith,
ExceptHandler, Expression, For, IfExp, Interactive, Lambda ]
|
AST node with a '.body' |
required |
name
|
id
|
Name to match (matches against |
required |
unique_sort
|
bool
|
Whether to ensure its unique + sorted |
required |
Source code in cdd/shared/ast_utils.py
merge_modules
Merge modules (removing module docstring from mod1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mod0
|
Module
|
Module |
required |
mod1
|
Module
|
Module |
required |
remove_imports_from_second
|
bool
|
Whether to remove global imports from second module |
required |
deduplicate_names
|
bool
|
Whether to deduplicate names; names can be function|class|AnnAssign|Assign name |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Merged module (copy) |
Source code in cdd/shared/ast_utils.py
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 |
|
module_to_all
From input, create (("module_name", {"symbol0", "symbol1"}),)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_or_filepath
|
Union[str, Module]
|
Module or filepath |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
List[str]
|
|
Source code in cdd/shared/ast_utils.py
node_to_dict
Convert AST node to a dict
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Dict representation |
Source code in cdd/shared/ast_utils.py
optimise_imports
Optimise imports involves: - Deduplication of module names - Deduplication of symbols import from module names
For more complicated set-ups I recommend use of: - autoflake --remove-all-unused-imports - isort
Parameters:
Name | Type | Description | Default |
---|---|---|---|
imports
|
Iterable[ImportFrom]
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[ImportFrom]
|
|
Source code in cdd/shared/ast_utils.py
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 |
|
param2argparse_param
Converts a param to an Expr argparse.add_argument
call
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Expr
|
|
Source code in cdd/shared/ast_utils.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
|
param2ast
Converts a param to an AnnAssign
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[AnnAssign, Assign]
|
AST node for assignment |
Source code in cdd/shared/ast_utils.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
parse_to_scalar
Parse the input to a scalar
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Any
|
Any value |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[str, int, float, complex, None]
|
Scalar |
Source code in cdd/shared/ast_utils.py
set_arg
In Python 3.8 expr
and type_comment
need to be set on arg.
This function handles constructs an ast.arg
handling that issue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arg
|
Optional[str]
|
The argument name |
required |
annotation
|
Optional[ast.AST]
|
The argument's annotation |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ast.arg
|
The constructed |
Source code in cdd/shared/ast_utils.py
set_docstring
Set docstring on node that can have a docstring. If doc_str is empty, the doc_str node is removed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_str
|
Optional[str]
|
Docstring |
required |
empty
|
bool
|
Whether the doc_str is empty (micro-optimization) |
required |
node
|
Union[Module, AsyncFunctionDef, FunctionDef, ClassDef]
|
AST node to set the docstring on |
required |
Source code in cdd/shared/ast_utils.py
set_slice
In Python 3.9 there's a new ast parser (PEG) that no longer wraps things in Index. This function handles this issue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
ast.AST
|
An AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[ast.AST, Index]
|
Original node, possibly wrapped in an |
Source code in cdd/shared/ast_utils.py
set_value
Creates a Constant
on Python >= 3.8 otherwise more specific AST type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
AST node |
required |
kind
|
Optional[Any]
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[Constant, Num, Str, NameConstant]
|
Probably a string, but could be any constant value |
Source code in cdd/shared/ast_utils.py
symbol_to_import
Resolve symbol to module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol
|
str
|
symbol to look for within various modules |
required |
modules_to_all
|
tuple[tuple[str, frozenset], ...]
|
Tuple of module_name to all of module; (str) to FrozenSet[str] |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Tuple[str, str]]
|
(symbol, module) if name in module else None |
Source code in cdd/shared/ast_utils.py
to_annotation
Converts the typ to an annotation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ
|
str
|
A string representation of the type to annotate with. Else return give identity. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
The annotation as a |
Source code in cdd/shared/ast_utils.py
to_type_comment
Convert annotation to a type comment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
str
|
AST node with a '.annotation' or Name or str |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
type_comment |
Source code in cdd/shared/ast_utils.py
cdd.shared.conformance
cdd.shared.conformance
Given the truth, show others the path
Parameters:
Name | Type | Description | Default |
---|
ground_truth
There is but one truth. Conform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
Namespace
|
Namespace with the values of the CLI arguments |
required |
truth_file
|
str
|
contains the filename of the one true source |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
OrderedDict
|
Filenames and whether they were changed |
Source code in cdd/shared/conformance.py
cdd.shared.cst
cdd.shared.cst
Concrete Syntax Tree for Python 3.6+ source code
Parameters:
Name | Type | Description | Default |
---|
cst_parse
Parse Python source lines into a Concrete Syntax Tree
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Python source code |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[Any]
|
List of |
Source code in cdd/shared/cst.py
cdd.shared.cst_utils
cdd.shared.cst_utils
Concrete Syntax Tree utility functions
Parameters:
Name | Type | Description | Default |
---|
cst_parse_one_node
Parse one statement into a CST node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement
|
str
|
Statement that was scanned from Python source code |
required |
state
|
dict
|
Number of lines between runs in |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
NamedTuple
|
NamedTuple with at least ("line_no_start", "line_no_end", "value") attributes |
Source code in cdd/shared/cst_utils.py
cst_parser
Checks if what has been scanned (stack) is ready for the scanned
array
Add then clear stack if ready else do nothing with both
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanned
|
list[str]
|
List of statements observed |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[NamedTuple]
|
Parse of scanned statements. One dimensional. |
Source code in cdd/shared/cst_utils.py
cst_scan
Checks if what has been scanned (stack) is ready for the scanned
array
Add then clear stack if ready else do nothing with both
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scanned
|
list[str]
|
List of statements observed |
required |
stack
|
list[str]
|
List of characters observed |
required |
Source code in cdd/shared/cst_utils.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
cst_scanner
Reduce source code into chunks useful for parsing. These chunks include newlines and the array is one dimensional.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Python source code |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[str]
|
List of scanned source code |
Source code in cdd/shared/cst_utils.py
get_construct_name
Find the construct name, currently works for: - AsyncFunctionDef - FunctionDef - ClassDef
Parameters:
Name | Type | Description | Default |
---|---|---|---|
words
|
tuple[str]
|
Tuple of words (no whitespace) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[str]
|
Name of construct if found else None |
Source code in cdd/shared/cst_utils.py
infer_cst_type
Infer the CST type. This is the most important function of the CST parser!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
statement_stripped
|
str
|
Original scanned statement minus both ends of whitespace |
required |
words
|
Iterable[str]
|
List of whitespace stripped and empty-str removed words from original statement |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
NamedTuple
|
CST type… a NamedTuple with at least ("line_no_start", "line_no_end", "value") attributes |
Source code in cdd/shared/cst_utils.py
reindent_block_with_pass_body
Reindent block (e.g., function definition) and give it a pass
body
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Block defining string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Reindented string with |
Source code in cdd/shared/cst_utils.py
set_prev_node
Store the result of the current function run into the prev_node
attribute
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
Callable[[str, dict], NamedTuple]
|
The |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Callable[[], Callable[[str, dict], NamedTuple]]
|
Wrapped function |
Source code in cdd/shared/cst_utils.py
cdd.shared.defaults_utils
cdd.shared.defaults_utils
Functions to handle default parameterisation
Parameters:
Name | Type | Description | Default |
---|
ast_parse_fix
Hack to resolve unbalanced parentheses SyntaxError acquired from PyTorch parsing TODO: remove
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
String to parse |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Value |
Source code in cdd/shared/defaults_utils.py
extract_default
extract_default(line, rstrip_default=True, default_search_announce=None, typ=None, emit_default_doc=True)
Extract a tuple of (doc, default) from a doc line
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
str
|
Example - "dataset. Defaults to mnist" |
mnist
|
rstrip_default
|
bool
|
Whether to rstrip whitespace, newlines, and '.' from the default |
required |
default_search_announce
|
Optional[Union[str, Iterable[str]]]
|
Default text(s) to look for. If None, uses default specified in default_utils. |
required |
typ
|
float
|
The type of the default value, useful to disambiguate |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, Optional[str]]
|
Example - ("dataset. Defaults to mnist", "mnist") if emit_default_doc else ("dataset", "mnist") |
Source code in cdd/shared/defaults_utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
needs_quoting
Figures out whether values with this type need quoting
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ
|
Optional[str]
|
The type |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the type needs quoting |
Source code in cdd/shared/defaults_utils.py
remove_defaults_from_intermediate_repr
Remove "Default of" text from IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_default_prop
|
bool
|
Whether to emit default property |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/shared/defaults_utils.py
set_default_doc
Emit param with 'doc' set to include 'Defaults'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Same shape as input but with Default append to doc. |
Source code in cdd/shared/defaults_utils.py
cdd.shared.docstring_parsers
cdd.shared.docstring_parsers
Docstring parsers.
Parses these formats into the cdd_python common IR format: - ReST docstring format (Sphinx) - numpydoc docstring format - Google's docstring format
Parameters:
Name | Type | Description | Default |
---|
Style
Bases: Enum
Simple enum taken from the docstring_parser codebase
Parameters:
Name | Type | Description | Default |
---|
__set_name_and_type_handle_doc_in_param
Internal function to internal function _set_name_and_type
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_param
|
dict
|
dict with keys: 'typ', 'doc', 'default' |
required |
name
|
str
|
Name of argument; useful for debugging and if the name hints as to the type |
required |
was_none
|
bool
|
Whether the default value was |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
Source code in cdd/shared/docstring_parsers.py
parse_docstring
parse_docstring(docstring, infer_type=False, default_search_announce=None, parse_original_whitespace=False, word_wrap=True, emit_default_prop=True, emit_default_doc=False)
Parse the docstring into its components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docstring
|
Optional[str]
|
the docstring |
required |
default_search_announce
|
Optional[Union[str, Iterable[str]]]
|
Default text(s) to look for. If None, uses default specified in default_utils. |
required |
infer_type
|
bool
|
Whether to try inferring the typ (from the default) |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_default_prop
|
dict
|
Whether to include the default dictionary property. |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/shared/docstring_parsers.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
cdd.shared.docstring_utils
cdd.shared.docstring_utils
Functions which produce docstring portions from various inputs
Parameters:
Name | Type | Description | Default |
---|
Style
Bases: Enum
Simple enum taken from the docstring_parser codebase
Parameters:
Name | Type | Description | Default |
---|
derive_docstring_format
Infer the docstring format of the provided docstring
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docstring
|
Optional[str]
|
the docstring |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Literal['rest', 'numpydoc', 'google']
|
the style of docstring |
Source code in cdd/shared/docstring_utils.py
emit_param_str
emit_param_str(param, style, purpose, emit_doc=True, emit_type=True, word_wrap=True, emit_default_doc=True)
Produce the docstring param/return lines
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
style
|
Literal['rest', 'numpydoc', 'google']
|
the style of docstring |
required |
purpose
|
Literal['class', 'function']
|
|
required |
if purpose == 'function' elif purpose == 'class' then
|
:param |
required | |
(ReST only)
|
:cvar` (ReST only) |
required | |
emit_doc
|
bool
|
Whether to emit the doc |
required |
emit_type
|
bool
|
Whether to emit the type |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Newline joined pair of param, type |
Source code in cdd/shared/docstring_utils.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
ensure_doc_args_whence_original
Ensure doc args appear where they appeared originally
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_doc_str
|
str
|
The current doc_str |
required |
original_doc_str
|
str
|
The original doc_str |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
reshuffled doc_str with args/returns in same place as original (same header, footer, and whitespace) |
Source code in cdd/shared/docstring_utils.py
header_args_footer_to_str
Ensure there is always two newlines between header and next, and one between non-empty: args_returns and footer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header
|
str
|
Header section |
required |
args_returns
|
str
|
args|returns section |
required |
footer
|
str
|
Footer section |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
One string with these three section combined with a minimum of one nl betwixt each and two at first |
Source code in cdd/shared/docstring_utils.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
|
parse_docstring_into_header_args_footer
Parse docstring into three parts: header; args|returns; footer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_doc_str
|
str
|
The current doc_str |
required |
original_doc_str
|
str
|
The original doc_str |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[Optional[str], Optional[str], Optional[str]]
|
Header, args|returns, footer |
Source code in cdd/shared/docstring_utils.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
|
cdd.shared.emit
cdd.shared.emit
Transform from string or AST representations of input, to AST, file, or str input_str.
Parameters:
Name | Type | Description | Default |
---|
cdd.shared.emit.file
cdd.shared.emit.file
File emitter
Parameters:
Name | Type | Description | Default |
---|
file
Convert AST to a file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Union[Module, ClassDef, FunctionDef]
|
AST node |
required |
filename
|
str
|
emit to this file |
required |
mode
|
str
|
Mode to open the file in, defaults to append |
append
|
skip_black
|
bool
|
Whether to skip formatting with black |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
NoneType
|
None |
Source code in cdd/shared/emit/file.py
cdd.shared.emit.utils
cdd.shared.emit.utils
Utility functions for cdd.emit
Parameters:
Name | Type | Description | Default |
---|
cdd.shared.emit.utils.emitter_utils
cdd.shared.emit.utils.emitter_utils
Functions which produce intermediate_repr from various different inputs
Parameters:
Name | Type | Description | Default |
---|
ast_parse_fix
Hack to resolve unbalanced parentheses SyntaxError acquired from PyTorch parsing TODO: remove
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
String to parse |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Value |
Source code in cdd/shared/emit/utils/emitter_utils.py
get_emitter
Get emitter function specialised for output node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emit_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid"]
|
Which type to emit. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Callable[[...], dict]`
|
Function which returns intermediate_repr |
Source code in cdd/shared/emit/utils/emitter_utils.py
get_internal_body
Get the internal body from our IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_name
|
str
|
name of target. If both |
required |
target_type
|
Literal['self', 'cls', 'static']
|
Type of target, static is static or global method, others just become first arg |
required |
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[list, tuple]
|
Internal body or an empty tuple |
Source code in cdd/shared/emit/utils/emitter_utils.py
cdd.shared.parse
cdd.shared.parse
Transform from string or AST representations of input, to intermediate_repr, a dictionary consistent
with IntermediateRepr
, defined as:
ParamVal = TypedDict("ParamVal", {"typ": str, "doc": Optional[str], "default": Any})
IntermediateRepr = TypedDict("IntermediateRepr", {
"name": Optional[str],
"type": Optional[str],
"doc": Optional[str],
"params": OrderedDict[str, ParamVal],
"returns": Optional[OrderedDict[Literal["return_type"], ParamVal]],
})
Parameters:
Name | Type | Description | Default |
---|
cdd.shared.parse.utils
cdd.shared.parse.utils
Utility functions for cdd.parse
Parameters:
Name | Type | Description | Default |
---|
cdd.shared.parse.utils.parser_utils
cdd.shared.parse.utils.parser_utils
Functions which help the functions within the parser module
Parameters:
Name | Type | Description | Default |
---|
get_parser
Get parser function specialised for input node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
Node to parse |
required |
parse_name
|
Literal["argparse", "class", "function", "json_schema",
"pydantic", "sqlalchemy", "sqlalchemy_table", "sqlalchemy_hybrid","infer"]
|
Which type to parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Callable[[...], dict]`
|
Function which returns intermediate_repr |
Source code in cdd/shared/parse/utils/parser_utils.py
infer
Infer the parse
type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
tuple[args]
|
The arguments |
required |
kwargs
|
Optional[dict]
|
Keyword arguments |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Name of inferred parser |
Source code in cdd/shared/parse/utils/parser_utils.py
ir_merge
Merge two intermediate_repr (IR) together. It doesn't do a target.update(other)
,
instead it carefully merges params
and returns
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
str
|
The target IR to modify. These values take precedence. Dict is consistent with |
required |
other
|
dict
|
Read-only IR to use in update. IR is a dictionary consistent with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
IR of updated target. |
Source code in cdd/shared/parse/utils/parser_utils.py
merge_params
Merge two ParamVal dicts together. It doesn't do a target_params.update(other_params)
,
instead it carefully merges two collections of dicts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other_params
|
str
|
Read-only params to use in update. Iterable of |
required |
target_params
|
str
|
The target params to modify. These values take precedence. Iterable of |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
IR of updated target. |
Source code in cdd/shared/parse/utils/parser_utils.py
merge_present_params
Merge two ParamVal dicts together. It doesn't do a target_params.update(other_params)
,
instead it carefully merges two dicts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other_param
|
str
|
Read-only param to use in update. Dict consistent with |
required |
target_param
|
str
|
The target param to modify. These values take precedence. Dict consistent with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
IR of updated target. |
Source code in cdd/shared/parse/utils/parser_utils.py
cdd.shared.pkg_utils
cdd.shared.pkg_utils
pkg_utils
Parameters:
Name | Type | Description | Default |
---|
relative_filename
Remove all the paths which are not relevant
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Filename |
required |
remove_hints
|
tuple[str, ...]
|
Hints as to what can be removed |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Relative |
Source code in cdd/shared/pkg_utils.py
cdd.shared.pure_utils
cdd.shared.pure_utils
Pure utils for pure functions. For the same input will always produce the same input_str.
Parameters:
Name | Type | Description | Default |
---|
FilenameProtocol
Bases: Protocol
Filename protocol
Parameters:
Name | Type | Description | Default |
---|
SetEncoder
Bases: JSONEncoder
JSON encoder that supports set
s
Parameters:
Name | Type | Description | Default |
---|
default
Handle set
by giving a sorted list in its place
Parameters:
Name | Type | Description | Default |
---|
all_dunder_for_module
all_dunder_for_module(module_directory, include, exclude=frozenset(('compound', 'shared', 'tests')), path_validator=path.isdir)
Generate __all__
for a given module using single-level filename hierarchy exclusively
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_directory
|
str
|
Module path |
required |
include
|
Iterable[str]
|
Additional strings to include |
required |
exclude
|
frozenset
|
base filenames to ignore |
required |
path_validator
|
Callable[[str], bool]
|
Path validation function |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
list[str]
|
list of strings matching the expected |
Source code in cdd/shared/pure_utils.py
append_to_dict
Append keys to a dictionary in a hierarchical manner and set the last key to a value. For example, given an empty dictionary and keys = [a, b, c] and value = d then the new dictionary would look like the following: {a: {b: {c: d}}}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
dictionary to append keys |
required |
keys
|
list[str]
|
keys to append to d |
required |
value
|
any
|
value to set keys[-1] |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
|
Source code in cdd/shared/pure_utils.py
assert_equal
assert a and b are equal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
Any
|
anything |
required |
b
|
Any
|
anything else |
required |
cmp
|
Callable[[a, b], bool]
|
comparator function |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Literal[True]
|
True if equal, otherwise raises |
Source code in cdd/shared/pure_utils.py
balanced_parentheses
Checks if parentheses are balanced, ignoring whatever is inside quotes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the parens are balanced |
Source code in cdd/shared/pure_utils.py
blockwise
Blockwise, like pairwise but with a size
parameter
From: https://stackoverflow.com/a/4628446
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
Iterator
|
iterator |
required |
size
|
int
|
size of each block |
required |
fillvalue
|
Any
|
What to use to "pair" with if uneven |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterator
|
iterator with iterators inside of block size |
Source code in cdd/shared/pure_utils.py
code_quoted
Internally user-provided None
and non literal_eval
able input is quoted with ```
This function checks if the input is quoted such
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
Any
|
The input |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether the input is code quoted |
Source code in cdd/shared/pure_utils.py
count_chars_from
Count number of chars in string from one or other end, until ignore
is no longer True (or entire s
is covered)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
sentinel_char_unseen
|
bool
|
Function that takes one char and decided whether to ignore it or not |
required |
char
|
str
|
Single character for counting occurrences of |
required |
end
|
bool
|
True to look from the end; False to look from start |
required |
s_len
|
Callable[str, [int]]
|
String len function to use, override to work at a shorter substr, e.g., |
required |
start_idx
|
str
|
Index to start looking at string from, override to work at a shorter substr, e.g., |
required |
char_f
|
Optional[Callable[[str], bool]]
|
char function, if |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
int
|
Number of chars counted (until |
Source code in cdd/shared/pure_utils.py
count_iter_items
Consume an iterable not reading it into memory; return the number of items.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterable
|
Iterable
|
An iterable |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
int
|
Number of items in iterable |
Source code in cdd/shared/pure_utils.py
deindent
Remove all indentation from the input string, or level
(s) of indent if specified
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
level
|
str
|
Number of tabs to remove from input string or if None: remove all |
required |
sep
|
str
|
Separator (usually |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AnyStr
|
Deindented string |
Source code in cdd/shared/pure_utils.py
diff
Given an input with __len__
defined and an op which takes the input and produces one output
with __len__
defined, compute the difference and return (diff_len, output)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_obj
|
Any
|
The input |
required |
op
|
Callable[[Any], Sized]
|
The operation to run |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[int, Any]
|
length of difference, response of operated input |
Source code in cdd/shared/pure_utils.py
emit_separating_tabs
Emit a separating tab between paragraphs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string (probably a docstring) |
required |
indent_level
|
int
|
docstring indentation level whence: 0=no_tabs, 1=one tab; 2=two tabs |
required |
run_per_line
|
Callable[[str], str]
|
Run this function per line |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Original string with a separating tab between paragraphs, & possibly addition indentation on other lines |
Source code in cdd/shared/pure_utils.py
ensure_valid_identifier
Ensure identifier is valid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Potentially valid identifier |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Valid identifier from |
Source code in cdd/shared/pure_utils.py
filename_from_mod_or_filename
Resolve filename from module name or filename
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mod_or_filename
|
str
|
Module name or filename |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Filename |
Source code in cdd/shared/pure_utils.py
find_module_filepath
Find module's file location without first importing it
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
Module name, e.g., "cdd.tests" or "cdd" |
required | |
```str```
|
:type: str
|
|
required |
submodule_name
|
Submodule name, e.g., "test_pure_utils" |
required | |
```Optional[str]```
|
:type: Optional[str]
|
|
required |
none_when_no_spec
|
bool
|
When |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module location
:rpath: |
Source code in cdd/shared/pure_utils.py
get_module
Import a module.
The 'package' argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import.
Wraps importlib.import_module
to return the module if it's available in interpreter on ModuleNotFoundError error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Module name |
required |
package
|
Optional[str]
|
Package name |
required |
extra_symbols
|
Optional[dict]
|
Dictionary of extra symbols to use if |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Module |
Source code in cdd/shared/pure_utils.py
identity
Identity function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
tuple[Any]
|
Any values |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Any
|
the input value |
indent_all_but_first
Indent all lines except the first one
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
indent_level
|
int
|
indentation level whence: 0=no_tabs, 1=one tab; 2=two tabs |
required |
wipe_indents
|
bool
|
Whether to clean the |
required |
sep
|
str
|
Separator (usually |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
input string indented (except first line) |
Source code in cdd/shared/pure_utils.py
is_ir_empty
Checks whether the IR is empty, i.e., might have name and params but will generate a docstr without types or argdoc
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether IR is empty |
Source code in cdd/shared/pure_utils.py
is_triple_quoted
Whether the str is triple quoted
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
bool
|
Whether it has balanced triple quotes (either variety) |
Source code in cdd/shared/pure_utils.py
location_within
Finds element within iterable within container
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container
|
Any
|
The container, e.g., a str, or list. We are looking for the subset which matches an element in |
required |
iterable
|
Any
|
The iterable, can be constructed |
required |
cmp
|
Callable[[str, str], bool]
|
Comparator to check input against |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[int, int, Optional[Any]]
|
(Start index iff found else -1, End index iff found else -1, subset iff found else None) |
Source code in cdd/shared/pure_utils.py
lstrip_namespace
Remove starting namespace
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
input string |
required |
namespaces
|
Union[list[str], tuple[str], Generator[str], Iterator[str]]
|
namespaces to strip |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AnyStr
|
|
Source code in cdd/shared/pure_utils.py
multiline
For readability and linting, it's useful to turn a long line, like: >>> '''123456789_ 123456789_ 123456789_ 123456789'''
Into:
>>> '''123456789_
''' '''123456789_ ''' '''123456789_ ''' '''123456789'''
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
quote_with
|
tuple[str, str]
|
What to quote with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
multine input string |
Source code in cdd/shared/pure_utils.py
namespaced_pascal_to_upper_camelcase
Convert potentially namespaced pascal to upper camelcase
E.g., "foo__bar_can" becomes "Foo__BarCan"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Pascal cased string (potentially with namespace, i.e., |
required |
sep
|
str
|
Separator (a.k.a., namespace) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Upper camel case string (potentially with namespace) |
Source code in cdd/shared/pure_utils.py
namespaced_upper_camelcase_to_pascal
Convert potentially namespaced pascal to upper camelcase
E.g., "Foo__BarCan" becomes "foo__bar_can"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Upper camel case string (potentially with namespace, i.e., |
required |
sep
|
str
|
Separator (a.k.a., namespace) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Pascal cased string (potentially with namespace) |
Source code in cdd/shared/pure_utils.py
pairwise
Return successive overlapping pairs taken from the input iterable.
The number of 2-tuples in the output iterator will be one fewer than the number of inputs. It will be empty if the input iterable has fewer than two values.
https://docs.python.org/3/library/itertools.html#itertools.pairwise but it's only avail. from 3.10 onwards
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterable
|
Iterable
|
An iterable |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
zip
|
A pair of 2-tuples or empty |
Source code in cdd/shared/pure_utils.py
paren_wrap_code
The new builtin AST unparser adds extra parentheses, so match that behaviour on older versions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
Source code string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Potentially parenthetically wrapped input |
Source code in cdd/shared/pure_utils.py
parse_comment_from_line
Remove from comment onwards in line
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
str
|
Python source line |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
|
Source code in cdd/shared/pure_utils.py
pascal_to_upper_camelcase
Transform pascal input to upper camelcase
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Pascal cased string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Upper camel case string |
Source code in cdd/shared/pure_utils.py
pluralise
Return plural form of given lowercase singular word (English only). Based on ActiveState recipe http://code.activestate.com/recipes/413172/ and 577781
Note: For production you'd probably want to use nltk or an NLP AI model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
singular
|
str
|
Non-plural |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Plural version |
Source code in cdd/shared/pure_utils.py
quote
Quote the input string if it's not already quoted
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
Union[str, float, complex, int, None]
|
Input string or literal or None |
required |
mark
|
str
|
Quote mark to wrap with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Union[str, float, complex, int, None]
|
Quoted string or input (if input is not str) |
Source code in cdd/shared/pure_utils.py
read_file_to_str
Read filename into a str, closing the file afterwards
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Input filename |
required |
mode
|
str
|
File mode |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Filename content as str |
Source code in cdd/shared/pure_utils.py
reindent
Reindent the input string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
indent_level
|
int
|
docstring indentation level whence: 0=no_tabs, 1=one tab; 2=two tabs |
required |
join_on
|
str
|
What to join on, e.g., ' ' |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AnyStr
|
Reindented string |
Source code in cdd/shared/pure_utils.py
remove_whitespace_comments
Remove all insignificant whitespace and comments from source
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
Python source string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
|
Source code in cdd/shared/pure_utils.py
rpartial
sanitise
Sanitise the input string, appending an _
if it's a keyword
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
input string with '_' append if it's a keyword else input string |
Source code in cdd/shared/pure_utils.py
set_attr
Sets the named attribute on the given object to the specified value.
set_attr(x, 'y', v) is equivalent to ``x.y = v; return x''
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
An object |
required |
key
|
str
|
A key |
required |
val
|
Any
|
A value |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Any
|
The modified |
Source code in cdd/shared/pure_utils.py
set_item
Sets the item on the given object to the specified value.
set_item(x, 'y', v) is equivalent to ``x[y] = v; return x''
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
An object |
required |
key
|
Union[str, int]
|
A key |
required |
val
|
Any
|
A value |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Any
|
The modified |
Source code in cdd/shared/pure_utils.py
sliding_window
Sliding window
https://docs.python.org/3/library/itertools.html#itertools-recipes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterable
|
Iterable
|
An iterable |
required |
n
|
int
|
Window size |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Generator[tuple]
|
sliding window |
Source code in cdd/shared/pure_utils.py
strip_split
Split and strip the input string on given separator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
str
|
Module/ClassDef/FunctionDef/AnnAssign/Assign resolver with a dot syntax. |
required |
sep
|
str
|
Separator |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterator[str, ...]
|
Iterator of each element of the hierarchy |
Source code in cdd/shared/pure_utils.py
strip_starting
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line
|
str
|
Input string |
required |
str_to_strip
|
str
|
Removes only this (once… so not |
required |
Source code in cdd/shared/pure_utils.py
unquote
Unquote a string. Removes one set of leading quotes '''
or '"'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_str
|
str
|
Input string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[str]
|
Unquoted string |
Source code in cdd/shared/pure_utils.py
update_d
Update d inplace
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
dict
|
dict to update |
required |
arg
|
dict
|
dict to update with |
required |
kwargs
|
Optional[dict]
|
keyword args to update with |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
Updated dict |
Source code in cdd/shared/pure_utils.py
upper_camelcase_to_pascal
Transform upper camelcase input to pascal case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Upper camel case string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Pascal cased string |
Source code in cdd/shared/pure_utils.py
cdd.shared.source_transformer
cdd.shared.source_transformer
Source transformer module. Uses astor on Python < 3.9
Parameters:
Name | Type | Description | Default |
---|
ast_parse
ast_parse(source, filename='<unknown>', mode='exec', skip_annotate=False, skip_docstring_remit=False)
Convert the AST input to Python source string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Python source |
required | |
source
|
str
|
|
required |
filename
|
str
|
Filename being parsed |
required |
mode
|
Literal['exec', 'single', 'eval']
|
'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. |
required |
skip_annotate
|
bool
|
Don't run |
required |
skip_docstring_remit
|
bool
|
Don't parse & emit the docstring as a replacement for current docstring |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
AST
|
AST node |
Source code in cdd/shared/source_transformer.py
to_code
Convert the AST input to Python source string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
AST
|
AST node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Python source |
Source code in cdd/shared/source_transformer.py
cdd.shared.types
cdd.shared.types
Shared types
Parameters:
Name | Type | Description | Default |
---|
cdd.sqlalchemy
cdd.sqlalchemy
SQLalchemy parsers and emitters module
Parameters:
Name | Type | Description | Default |
---|
cdd.sqlalchemy.emit
cdd.sqlalchemy.emit
SQLalchemy emitters
Parameters:
Name | Type | Description | Default |
---|
sqlalchemy
sqlalchemy(intermediate_repr, emit_repr=True, class_name=None, class_bases=('Base',), decorator_list=None, table_name=None, force_pk_id=FORCE_PK_ID, docstring_format='rest', word_wrap=True, emit_original_whitespace=False, emit_default_doc=True)
Construct an SQLAlchemy declarative class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_repr
|
bool
|
Whether to generate a |
required |
class_name
|
name
|
name of class |
required |
class_bases
|
Iterable[str]
|
bases of class (the generated class will inherit these) |
required |
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
table_name
|
str
|
Table name, defaults to |
class_name
|
force_pk_id
|
bool
|
Whether to force primary_key to be named |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_original_whitespace
|
bool
|
Whether to emit an original whitespace (in docstring) or strip it out |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ClassDef
|
SQLalchemy declarative class AST |
Source code in cdd/sqlalchemy/emit.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
sqlalchemy_hybrid
sqlalchemy_hybrid(intermediate_repr, emit_repr=True, emit_create_from_attr=True, class_name=None, class_bases=('Base',), decorator_list=None, table_name=None, force_pk_id=FORCE_PK_ID, docstring_format='rest', word_wrap=True, emit_original_whitespace=False, emit_default_doc=True)
Construct an class TableName(Base): __table__ = sqlalchemy.Table(name, metadata, Column(…), …)
Valid in SQLalchemy 2.0 and 1.4: - docs.sqlalchemy.org/en/14/orm/declarative_tables.html#declarative-with-imperative-table-a-k-a-hybrid-declarative - docs.sqlalchemy.org/en/20/orm/declarative_tables.html#declarative-with-imperative-table-a-k-a-hybrid-declarative
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
emit_repr
|
bool
|
Whether to generate a |
required |
emit_create_from_attr
|
bool
|
Whether to generate a |
required |
class_name
|
name
|
name of class |
required |
class_bases
|
Iterable[str]
|
bases of class (the generated class will inherit these) |
required |
decorator_list
|
Optional[Union[List[str], List[]]]
|
List of decorators |
required |
table_name
|
str
|
Table name, defaults to |
class_name
|
force_pk_id
|
bool
|
Whether to force primary_key to be named |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_original_whitespace
|
bool
|
Whether to emit an original whitespace (in docstring) or strip it out |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ClassDef
|
SQLalchemy hybrids declarative class AST |
Source code in cdd/sqlalchemy/emit.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
sqlalchemy_table
sqlalchemy_table(intermediate_repr, name='config_tbl', table_name=None, force_pk_id=FORCE_PK_ID, docstring_format='rest', word_wrap=True, emit_original_whitespace=False, emit_default_doc=True)
Construct an name = sqlalchemy.Table(name, metadata, Column(…), …)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
name
|
str
|
name of binding + table |
required |
table_name
|
str
|
Table name, defaults to |
name
|
force_pk_id
|
bool
|
Whether to force primary_key to be named |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
word_wrap
|
bool
|
Whether to word-wrap. Set |
required |
emit_original_whitespace
|
bool
|
Whether to emit original whitespace or strip it out |
required |
emit_default_doc
|
bool
|
Whether help/docstring should include 'With default' text |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
ClassDef
|
AST of the Table expression + assignment |
Source code in cdd/sqlalchemy/emit.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
cdd.sqlalchemy.parse
cdd.sqlalchemy.parse
SQLalchemy parsers
TODO
- Implement update (see https://github.com/sqlalchemy/sqlalchemy/discussions/5940)
- Implement batch CRUD
Parameters:
Name | Type | Description | Default |
---|
sqlalchemy
Parse out a class C(Base): __tablename__= 'tbl'; dataset_name = Column(String, doc="p", primary_key=True)
,
as constructed on an SQLalchemy declarative Base
.
Also supports hybrid syntax: class TableName(Base): __table__ = sqlalchemy.Table(name, metadata, Column(…), …)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_def
|
Union[ClassDef]
|
A class inheriting from declarative |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/sqlalchemy/parse.py
sqlalchemy_hybrid
Parse out a class TableName(Base): __table__ = sqlalchemy.Table(name, metadata, Column(…), …)
,
as constructed on an SQLalchemy declarative Base
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_def
|
Union[ClassDef]
|
A class inheriting from declarative |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/sqlalchemy/parse.py
sqlalchemy_table
Parse out a sqlalchemy.Table
, or a name = sqlalchemy.Table
, into the IR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
call_or_name
|
Union[AnnAssign, Assign, Call]
|
The call to |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/sqlalchemy/parse.py
cdd.sqlalchemy.utils
cdd.sqlalchemy.utils
SQLalchemy parsers and emitters utility module
Parameters:
Name | Type | Description | Default |
---|
cdd.sqlalchemy.utils.emit_utils
cdd.sqlalchemy.utils.emit_utils
Utility functions for cdd.sqlalchemy.emit
Parameters:
Name | Type | Description | Default |
---|
ensure_has_primary_key
Add a primary key to the input (if nonexistent) then return the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intermediate_repr
|
dict
|
a dictionary consistent with |
required |
force_pk_id
|
bool
|
Whether to force primary_key to be named |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
dict
|
a dictionary consistent with |
Source code in cdd/sqlalchemy/utils/emit_utils.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
generate_create_from_attr_staticmethod
Generate a __repr__
method with all params, using str.format
syntax
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
OrderedDict
|
an |
required |
cls_name
|
str
|
Name of class |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
|
Source code in cdd/sqlalchemy/utils/emit_utils.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
|
generate_create_tables_mod
Generate the Base.metadata.create_all(engine)
for SQLalchemy
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Module to import from |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Module
|
Module with imports for SQLalchemy |
Source code in cdd/sqlalchemy/utils/emit_utils.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
|
generate_repr_method
Generate a __repr__
method with all params, using str.format
syntax
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
OrderedDict
|
an |
required |
cls_name
|
str
|
Name of class |
required |
docstring_format
|
Literal['rest', 'numpydoc', 'google']
|
Format of docstring |
required |
hybrid
|
bool
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
FunctionDef
|
|
Source code in cdd/sqlalchemy/utils/emit_utils.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
param_to_sqlalchemy_column_calls
Turn a param into Column(…)
s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_param
|
dict
|
Name, dict with keys: 'typ', 'doc', 'default' |
required |
include_name
|
bool
|
Whether to include the name (exclude in declarative base) |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Iterable[Call]
|
Iterable of elements in form of: |
Source code in cdd/sqlalchemy/utils/emit_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
rewrite_fk
Rewrite of the form:
To the following, inferring that the primary key field isid
by resolving the symbol and ast.parse
ing it:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol_to_module
|
Dict[str,str]`
|
Dictionary of symbol to module, like |
required |
column_assign
|
Assign
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Assign
|
|
Source code in cdd/sqlalchemy/utils/emit_utils.py
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 |
|
sqlalchemy_class_to_table
Convert SQLalchemy class to SQLalchemy Table expression
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_def
|
ClassDef
|
A class inheriting from declarative |
required |
parse_original_whitespace
|
bool
|
Whether to parse original whitespace or strip it out |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Call
|
SQLalchemy |
Source code in cdd/sqlalchemy/utils/emit_utils.py
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 |
|
sqlalchemy_table_to_class
Convert table_name = Table(column_name)
to `class table_name(Base): column_name
Parameters:
Name | Type | Description | Default |
---|
Source code in cdd/sqlalchemy/utils/emit_utils.py
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 |
|
update_fk_for_file
Given an existing filename, use its imports and to replace its foreign keys with the correct values
This is subsequent phase process, and must be preceded by: - All SQLalchemy models being in the same directory as filename - Correct imports being added
Then it can transform classes with members like:
To the following, inferring that the primary key field isid
by resolving the symbol and ast.parse
ing it:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Filename |
required |
Source code in cdd/sqlalchemy/utils/emit_utils.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
|
update_with_imports_from_columns
Given an existing filename, figure out its relative imports
This is subsequent phase process, and must be preceded by: - All SQLalchemy models being in the same directory as filename
It will take:
…and add this import:Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Python filename containing SQLalchemy |
required |
Source code in cdd/sqlalchemy/utils/emit_utils.py
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
|
cdd.sqlalchemy.utils.parse_utils
cdd.sqlalchemy.utils.parse_utils
Utility functions for cdd.parse.sqlalchemy
Parameters:
Name | Type | Description | Default |
---|
column_call_name_manipulator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
call
|
Call``
|
|
required |
operation
|
Literal["remove", "add"]
|
|
required |
name
|
str
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Call
|
Column call |
Source code in cdd/sqlalchemy/utils/parse_utils.py
column_call_to_param
Parse column call Call(func=Name("Column", Load(), …)
into param
Parameters:
Name | Type | Description | Default |
---|---|---|---|
call
|
Call
|
Column call from SQLAlchemy |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, dict]
|
Name, dict with keys: 'typ', 'doc', 'default' |
Source code in cdd/sqlalchemy/utils/parse_utils.py
column_parse_arg
Parse Column arg
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx_arg
|
int
|
argument number, node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Tuple[str, AST]]
|
|
Source code in cdd/sqlalchemy/utils/parse_utils.py
column_parse_extra_sql
Parse Column arg into extra sql type information
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx_arg
|
int
|
argument number, node |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Optional[Tuple[str, dict]]
|
|
Source code in cdd/sqlalchemy/utils/parse_utils.py
column_parse_kwarg
Parse Column kwarg
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_word
|
ast.keyword
|
The keyword argument |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, Any]
|
|
Source code in cdd/sqlalchemy/utils/parse_utils.py
concat_with_whitespace
Concatenate a with b with correct whitespace around and within each
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
str
|
first string |
required |
b
|
str
|
second string |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
combined strings with correct whitespace around and within |
Source code in cdd/sqlalchemy/utils/parse_utils.py
get_pk_and_type
Get the primary key and its type from an SQLalchemy class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sqlalchemy_class
|
ClassDef
|
SQLalchemy class |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
tuple[str, str]
|
Primary key and its type |
Source code in cdd/sqlalchemy/utils/parse_utils.py
get_table_name
Get the primary key and its type from an SQLalchemy class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sqlalchemy_class
|
ClassDef
|
SQLalchemy class |
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
str
|
Primary key and its type |
Source code in cdd/sqlalchemy/utils/parse_utils.py
cdd.sqlalchemy.utils.shared_utils
cdd.sqlalchemy.utils.shared_utils
Shared utility functions for SQLalchemy
Parameters:
Name | Type | Description | Default |
---|
update_args_infer_typ_sqlalchemy
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_param
|
dict
|
Param with typ |
required |
args
|
list
|
|
required |
name
|
str
|
|
required |
nullable
|
Optional[bool]
|
Whether it is NULL-able |
required |
x_typ_sql
|
dict
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
return_type |
Tuple[bool, Optional[Union[List[AST], Tuple[AST]]]]
|
Whether the type is nullable, possibly a list/tuple of types to generate columns for |
Source code in cdd/sqlalchemy/utils/shared_utils.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|