eladrich / pyrallis

Pyrallis is a framework for structured configuration parsing from both cmd and files. Simply define your desired configuration structure as a dataclass and let pyrallis do the rest!
https://eladrich.github.io/pyrallis/
MIT License
189 stars 7 forks source link

Dumping without defaults #1

Closed yairf11 closed 2 years ago

yairf11 commented 2 years ago

Hi,

When serializing a dataclass, there are cases in which we would like the output to be as concise as possible, and omit config entries if their value is the default one.

What do you think about adding a parameter to the encode/dump functions so that this behavior could be toggled on/off by the user?

eladrich commented 2 years ago

Hi Yair, Great suggestion, let me give it a try and see how it goes

eladrich commented 2 years ago

Added an option to pyrallis.dump as suggested.

pyrallis.dump(cfg, omit_defaults=True)

The main downside is that, while concise, saving the partial config means that changing the default in your dataclass might have unexpected results on older configs.

Will merge into the master alongside some other planned changes.