Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit the correct indentation of sequence #430

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dota17
Copy link

@dota17 dota17 commented Aug 26, 2020

Modify the output format of Custom indent in sequence by adding the is_qequence parameter in write_indicator().
Refer to #234, The test case is:

doc = """
%TAG !E! !SSSSS
---
- hosts: localhost
  vars:
    yaml:
      single_attr: value1
      list_of_dict_attr:
        - attr1: value1
          attr2: value2
          attr3:
            - item1
            - item2
  tasks:
    - debug: msg="{{ yaml | to_nice_yaml }}"
- 
  - aaa
  - ccc
...

the result is shown below:

print(yaml.dump(data, indent=6, allow_unicode=True, default_flow_style=False))

    - hosts: localhost
      tasks:
          - debug: msg="{{ yaml | to_nice_yaml }}"
      vars:
            yaml:
                  list_of_dict_attr:
                      - attr1: value1
                        attr2: value2
                        attr3:
                            - item1
                            - item2
                  single_attr: value1
    -     - aaa
          - ccc

print(yaml.dump(data, indent=3, allow_unicode=True, default_flow_style=False))

 - hosts: localhost
   tasks:
    - debug: msg="{{ yaml | to_nice_yaml }}"
   vars:
      yaml:
         list_of_dict_attr:
          - attr1: value1
            attr2: value2
            attr3:
             - item1
             - item2
         single_attr: value1
 -  - aaa
    - ccc

In brief, This output format is more consistent with spec.

Do I need to add the testcases in PR? @perlpunk

@perlpunk
Copy link
Member

I guess a test would be nice :)
But I'm not maintaining PyYAML or making any decisions.

@perlpunk
Copy link
Member

perlpunk commented Aug 28, 2020

One thing to keep in mind is that the output of libyaml is different. So there would be a difference between yaml.Dumper and yaml.CDumper.
That will probably be an issue with a test.

@JobaDiniz
Copy link

will this ever be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants