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. |
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
__post_init__
Set display names for input
and output
.
Source code in src/yamkix/config.py
__str__
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,
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
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 |
|
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,
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
|
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,
) -> 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
|
Source code in src/yamkix/yamkix.py
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 |