Skip to content

Add support for YAML configuration files#141

Open
antler5 wants to merge 1 commit into
quentinsf:masterfrom
antler5:upstream_yaml_config
Open

Add support for YAML configuration files#141
antler5 wants to merge 1 commit into
quentinsf:masterfrom
antler5:upstream_yaml_config

Conversation

@antler5

@antler5 antler5 commented Aug 4, 2021

Copy link
Copy Markdown

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!

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!
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.

1 participant