Yamkix API reference¶
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
yamkix project code.
API Overview¶
Top-level package for yamkix.
YamkixConfig
dataclass
¶
Defines the available Yamkix configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
explicit_start |
bool
|
Whether to include explicit start markers ( |
explicit_end |
bool
|
Whether to include explicit end markers ( |
default_flow_style |
bool
|
Whether to use default flow style. Setting |
dash_inwards |
bool
|
Whether to use dash inwards, i.e. whether to indent the dash in front of a sequence. |
quotes_preserved |
bool
|
Whether to preserve quotes, i.e. preserve the original quotes used in the input in the output. |
parsing_mode |
str
|
|
spaces_before_comment |
int | None
|
Number of spaces before comments. |
enforce_double_quotes |
bool
|
Whether to enforce double quotes when quotes_preserved is False |
line_width |
int
|
Maximum line width. |
align_comments |
bool
|
Whether to align EOL comments within each dict/list to the maximum column. |
version |
bool | None
|
Whether to include version information (deprecated) |
io_config |
YamkixInputOutputConfig
|
Input/Output configuration. |
Source code in src/yamkix/config.py
__str__
¶
Return a string representation of the YamkixConfig.
Source code in src/yamkix/config.py
YamkixInputOutputConfig
dataclass
¶
Yamkix input/output configuration.
Part of the config that manages input and output.
Attributes:
| Name | Type | Description |
|---|---|---|
input |
str | None
|
The input file to parse if not |
output |
str | None
|
The name of the file to generate if not |
Source code in src/yamkix/config.py
create_yamkix_config_from_typer_args
¶
create_yamkix_config_from_typer_args(
input_file: str | None,
output_file: str | None,
stdout: bool,
typ: str,
no_explicit_start: bool,
explicit_end: bool,
no_quotes_preserved: bool,
enforce_double_quotes: bool,
default_flow_style: bool,
no_dash_inwards: bool,
spaces_before_comment: int | None,
line_width: int,
align_comments: bool,
files: list[Path] | None,
) -> list[YamkixConfig]
Create a list of YamkixConfig from Typer arguments.
Note
If files is not None, this function will create a YamkixConfig for each file in the list.
And input_file, output_file and stdout will not be taken into account.
If files is None, a single YamkixConfig will be created using the provided arguments.
Source code in src/yamkix/config.py
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 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
get_default_yamkix_config
¶
Return Yamkix default configuration.
Returns:
| Name | Type | Description |
|---|---|---|
yamkix_config |
YamkixConfig
|
The default configuration provided by
|
Source code in src/yamkix/config.py
get_opinionated_yaml_writer
¶
Configure a yaml parser/formatter the yamkix way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yamkix_config
|
YamkixConfig
|
a YamkixConfig instance |
required |
Returns:
a ruamel.yaml YAML instance, configured according to the YamkixConfig you provided and:
mapping = 2(map indent)sequence = 4(sequence indent)offset = 2(sequence dash offset)
Source code in src/yamkix/yaml_writer.py
get_yamkix_config_from_default
¶
get_yamkix_config_from_default(
parsing_mode: str | None = None,
explicit_start: bool | None = None,
explicit_end: bool | None = None,
default_flow_style: bool | None = None,
dash_inwards: bool | None = None,
quotes_preserved: bool | None = None,
enforce_double_quotes: bool = False,
spaces_before_comment: int | None = None,
line_width: int | None = None,
align_comments: bool | None = None,
io_config: YamkixInputOutputConfig | None = None,
) -> YamkixConfig
Return a Yamkix configuration, based on the default one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsing_mode
|
str | None
|
|
None
|
explicit_start
|
bool | None
|
Whether to include explicit start markers ( |
None
|
explicit_end
|
bool | None
|
Whether to include explicit end markers ( |
None
|
default_flow_style
|
bool | None
|
Whether to use default flow style. Setting |
None
|
dash_inwards
|
bool | None
|
Whether to use dash inwards, i.e. whether to indent the dash in front of a sequence. |
None
|
quotes_preserved
|
bool | None
|
Whether to preserve quotes, i.e. preserve the original quotes used in the input in the output. |
None
|
enforce_double_quotes
|
bool
|
Whether to enforce double quotes when quotes_preserved is False. |
False
|
spaces_before_comment
|
int | None
|
Number of spaces before comments. |
None
|
line_width
|
int | None
|
Maximum line width. |
None
|
align_comments
|
bool | None
|
Whether to align EOL comments within each dict/list to the maximum column. |
None
|
io_config
|
YamkixInputOutputConfig | None
|
Input/Output configuration. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
yamkix_config |
YamkixConfig
|
A |
Tip
Use this function when you want to create a custom configuration that just overrides some of the default values.
Note
If you want to create a configuration from scratch, build a YamkixConfig object directly.
Source code in src/yamkix/config.py
get_yamkix_version
¶
yamkix_dump_all
¶
yamkix_dump_all(
one_or_more_items: list[CommentedBase],
yaml: YAML,
dash_inwards: bool,
output_file: str | None,
spaces_before_comment: int | None,
double_quotes_yaml: YAML | None = None,
capture_buffer: StringIO | None = None,
align_comments_flag: bool = False,
) -> None
Dump all the documents from the input structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
one_or_more_items
|
list[CommentedBase]
|
The YAML document(s) to dump. The result of a |
required |
yaml
|
YAML
|
The |
required |
dash_inwards
|
bool
|
Whether to apply dash inwards formatting. |
required |
output_file
|
str | None
|
The output file to write to. If |
required |
spaces_before_comment
|
int | None
|
The number of spaces to use before comments. |
required |
double_quotes_yaml
|
YAML | None
|
An optional |
None
|
capture_buffer
|
StringIO | None
|
An optional |
None
|
align_comments_flag
|
bool
|
Whether to align EOL comments within each dict/list to the maximum column. |
False
|
Source code in src/yamkix/yamkix.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 | |
yamkix_dump_one
¶
yamkix_dump_one(
single_item: CommentedBase,
yaml: YAML,
dash_inwards: bool,
out: TextIO,
spaces_before_comment: int | None,
) -> None
Dump a single document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
single_item
|
CommentedBase
|
The YAML document to dump.
This is the result of a |
required |
yaml
|
YAML
|
The YAML writer to use. |
required |
dash_inwards
|
bool
|
Whether to apply dash inwards formatting. |
required |
out
|
TextIO
|
The output stream to write to. |
required |
spaces_before_comment
|
int | None
|
The number of spaces to use before comments. |
required |