quentinsf / icsv2ledger

Interactive importing of CSV files to Ledger
196 stars 70 forks source link

Add support for YAML configuration files #141

Open antler5 opened 3 years ago

antler5 commented 3 years ago

Applies to any provided config file ending in .yaml or .yml, and searches for ./.icsv2ledgerrc.yaml and ./.icsv2ledgerrc.yml by default.

Includes updates to documentation with an explanation of file path precedence and an adaptation of the existing configuration example.

Although PyYAML parses the configuration file into a dict, we immediately read it into configparser to maintain consistency in the rest of the program.

Adds an import of chain from the itertools module to succinctly flatten a list of list comprehensions in the config file search-path section. I've done further refactoring of this section on my personal fork, but that's to my preferences, and likely not Pythonic, as I'm still learning what that means- my instincts are probably too DRY :p Hence, I've kept this patch minimal, and only changed the lines that I needed to.

I'd have liked to support passing a list of field-indexes to the desc option, instead of the current solution of quoting it into a string for the existing regex-split, but found that it was always parsed in as a string ('[2, 5]') instead of a list ([2, 5]), so it kept trying to iterate over the square brackets? I'm really new to Python, and am clearly missing something here. Comments welcome!