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

Preserve formatting if yml already exists #10

Closed
Gregory108 opened this issue Sep 8, 2021 · 2 comments
Closed

Preserve formatting if yml already exists #10

Gregory108 opened this issue Sep 8, 2021 · 2 comments

Comments

@Gregory108
Copy link

Running dbt-invoke comes at the price of loosing formatting.
Currently, dbt-invoke properties squashes and unindents

    - name: X

    - name: Y

to

- name: X
- name: Y

Or re-formats lists (e.g. in tests) from

values: ["A", "B"]

to

values:
    - "A"
    - "B"

Hence there are three options:

  • either people have to switch to formatting - compact and rich with hyphens (which is less readable and navigable)
  • or we have to redo formatting after every dbt-invoke properties (Nope out!=)
  • limit the use of dbt-invoke properties only to freshly-generated models and update variables list manually (my current approach=/)

Request:
To preserve formatting for pieces of documentation are already written in yml

(PS: how can I contribute?)

@robastel
Copy link
Member

robastel commented Sep 10, 2021

This would be a nice option if we can make it work. I would also like to keep the option to reformat to some basic default formatting like we have now. We use that at Dashlane to make sure our property files are formatted consistently.

It looks like the ruamel.yaml package can handle "round-trip" yaml formatting with a few limitations. We currently use PyYAML which does not handle "round-trip" formatting as far as I know.

My first idea would be to alter the parse_yaml and write_yaml functions in _utils.py to take that into account. I think we would want to control this behavior by accepting a new command line argument in properties.py, but I am open to other thoughts.

I'm glad you would like to contribute! I think the best way go about that process is to:

  • Open up an issue like you did here
  • Discuss and agree on a design
  • Create a fork to implement the design
  • Add test(s) if the changes are not covered by an existing test
  • Make sure all tests are passing
  • Update README.md
  • Update the version number
  • Submit a pull request

What are your thoughts on of all that?

@ciklista ciklista mentioned this issue Feb 22, 2022
3 tasks
@robastel
Copy link
Member

robastel commented Mar 9, 2022

The recently merged PR #20 (thanks @ciklista) has addressed the preservation of:

  • comments
  • list formatting
    values: ["A", "B"]
  • empty lines between items
    - name: X
    
    - name: Y

It has not addressed custom indentation schemes. I'll close this issue because a standalone issue (#23) has been created for custom indentation.

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

No branches or pull requests

2 participants