Skip to content

Make CSV importer configurable via ConfigArgParse - #166

Merged
Gerrrr merged 1 commit into
apache:masterfrom
MrlixiangWE:fix/119-csv-configargparse
Aug 25, 2026
Merged

Make CSV importer configurable via ConfigArgParse#166
Gerrrr merged 1 commit into
apache:masterfrom
MrlixiangWE:fix/119-csv-configargparse

Conversation

@MrlixiangWE

Copy link
Copy Markdown
Contributor

Problem

CSV is the only importer whose delimiter and quote character cannot be set through ConfigArgParse. They can currently only be configured per test in YAML.

Before / after

Before: CSV delimiter and quote character can only be configured through per-test csv_options in YAML.

After: they can also be set through --csv-delimiter and --csv-quote-char, the matching environment variables, or a csv section in the config file. Explicit global values override per-test options; otherwise existing behavior is unchanged.

Verification

uv run pytest -q --ignore=tests/graphite_e2e_test.py --ignore=tests/postgres_e2e_test.py

uv run tox -e lint

uv build --no-create-gitignore

Closes #119

@Gerrrr Gerrrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Please revert the breaking yaml config change, otherwise LGTM.

Comment thread docs/CSV.md
@MrlixiangWE
MrlixiangWE force-pushed the fix/119-csv-configargparse branch from bc0ee05 to 70fdcad Compare August 9, 2026 04:01
Comment thread docs/CSV.md
Comment thread otava/config.py Outdated
@MrlixiangWE
MrlixiangWE force-pushed the fix/119-csv-configargparse branch 2 times, most recently from 6b525db to 065b418 Compare August 23, 2026 07:29
@Gerrrr
Gerrrr requested a balanced review from Copilot August 23, 2026 19:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds global CSV delimiter and quote-character configuration through CLI, environment variables, and YAML.

Changes:

  • Introduces CsvConfig and applies global overrides to CSV tests.
  • Adds parser, precedence, and help-output tests.
  • Updates CSV examples and documentation.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
otava/csv_options.py Defines global CSV parser options.
otava/config.py Loads and propagates global CSV configuration.
otava/test_config.py Applies global overrides to per-test CSV options.
tests/config_test.py Tests parsing, precedence, and propagation.
tests/cli_help_test.py Updates expected CLI help.
tests/cli_options_test.py Corrects the per-test quote key.
tests/csv_e2e_test.py Corrects the CSV E2E configuration.
tests/resources/sample_config.yaml Adds per-test CSV options.
tests/resources/substitution_test_config.yaml Adds global CSV substitution values.
examples/csv/config/otava.yaml Corrects the example quote key.
docs/CSV.md Documents global CSV configuration.
Suppressed comments (1)

otava/csv_options.py:41

  • csv.reader also requires quotechar to be exactly one character, while this option permits empty or multi-character values from the CLI, environment, or YAML. Those values fail only when a CSV test runs. Reuse the delimiter's parse-time character validator here so configuration errors are reported immediately.
            "--csv-quote-char",

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread otava/csv_options.py
@staticmethod
def add_parser_args(arg_group):
arg_group.add_argument(
"--csv-delimiter",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good feedback. I will merge this PR after this is fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed. Both options now use a single_character type validator, so a multi-character value is rejected when the configuration is parsed:

error: argument --csv-delimiter: must be a single character, got '::'

That covers the config file, the CLI flag and the environment variable, with tests for each. The per-test csv_options keys still accept multi-character values, but that behavior predates this PR — I can tighten it here too if you prefer.

Also rebased onto de46ddf.

CSV delimiter and quote character could only be set per test in YAML.
They can now also be set through a top-level csv section in the config
file, the --csv-delimiter and --csv-quote-char options, and the
CSV_DELIMITER and CSV_QUOTE_CHAR environment variables. Explicit global
values override per-test csv_options; otherwise existing behavior is
unchanged.

The per-test YAML key is renamed from quotechar to quote_char. The
loader only ever read quote_char, so the documented quotechar spelling
was silently ignored and no working configuration depends on it.

Closes apache#119
@MrlixiangWE
MrlixiangWE force-pushed the fix/119-csv-configargparse branch from 065b418 to 573e54f Compare August 25, 2026 04:05

@Gerrrr Gerrrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for this contribution and for addressing feedback!

@Gerrrr
Gerrrr merged commit a1ef00d into apache:master Aug 25, 2026
6 checks passed
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.

Make CSV importer configurable via ConfigArgParse

3 participants