feat: add gbmedium config, set CLI subcommand, and config warning#50
Conversation
…ettings Add `gbmedium` option to control the [J] vs [J/OL] medium tag in GB/T 7714 article output (True → force [J/OL], False → force [J], None → auto-detect). Style-specific settings are now collected in a `_style_kwargs` dict inside `BibLookup` (populated by `_init_style_kwargs`) instead of individual attributes, making it easy to add new per-style parameters. `str2bool` now passes `None` through so config keys reset to `None` work for boolean fields.
Add `bib-lookup set KEY VALUE` for setting individual config values; VALUE of none/null resets the key to None (falling back to built-in logic). --config now warns (instead of silently discarding) when unknown keys are encountered; the keys are still written to the config file.
Document the new `gbmedium` config option, the `set` CLI subcommand, and the improved --config unknown-key warning behaviour.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
=========================================
Coverage ? 98.40%
=========================================
Files ? 13
Lines ? 1945
Branches ? 0
=========================================
Hits ? 1914
Misses ? 31
Partials ? 0 ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
This PR adds a new GB/T 7714 style control (gbmedium) and improves configuration ergonomics by introducing a bib-lookup set KEY VALUE shortcut, while also changing --config behavior to warn on unknown keys and preserve them.
Changes:
- Add
gbmediumconfig/constructor option and propagate it into the GB/T 7714 formatter to control[J]vs[J/OL]. - Add
bib-lookup set KEY VALUEfor updating individual config keys, including resetting toNone. - Refactor style-specific parameters into
BibLookup._style_kwargsand adjust config parsing/warnings.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
test/test_styles.py |
Adds unit + end-to-end tests validating gbmedium behavior in the GBT7714 style and via BibLookup. |
test/test_cli.py |
Adds CLI tests for the new set subcommand and unknown-key warnings. |
README.md |
Documents the new set shortcut and adds gbmedium to the config table. |
CHANGELOG.rst |
Records the new CLI subcommand, gbmedium, warning behavior, and refactor notes. |
bib_lookup/utils.py |
Updates str2bool to pass None through unchanged. |
bib_lookup/styles/gbt7714.py |
Implements gbmedium-driven medium tag selection ([J] vs [J/OL]). |
bib_lookup/cli.py |
Adds config-key validation helpers, set handling, and changes --config unknown-key behavior. |
bib_lookup/bib_lookup.py |
Adds _style_kwargs + _init_style_kwargs and passes style kwargs into formatter constructors. |
bib_lookup/_const.py |
Adds gbmedium default and introduces STYLE_PARAMETERS registry for per-style keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Warn about unknown keys (but keep them — they may be style-specific) | ||
| unknown_keys = set(config.keys()) - _valid_config_keys() | ||
| if len(unknown_keys) > 0: | ||
| verb = "are" if len(unknown_keys) > 1 else "is" | ||
| warnings.warn( |
| if value.startswith("[") and value.endswith("]"): | ||
| return [v.strip() for v in value.strip("[]").split(",")] | ||
| return value |
| self._style_kwargs = { | ||
| "gbt7714": {"gbmedium": _gbmedium_val}, | ||
| "gbt": {"gbmedium": _gbmedium_val}, | ||
| "gbt-7714": {"gbmedium": _gbmedium_val}, | ||
| } |
| ```bash | ||
| bib-lookup set timeout 2.0 | ||
| bib-lookup set style gbt | ||
| bib-lookup set gbmedium true # reset a key to its built-in default with "none" |
- Restore list/bool/None parsing for --config KEY=VALUE pairs (was lost during refactor of _handle_config, causing ignore_fields etc. to be stored as raw strings) - Strip quotes from list elements and handle empty lists [] in _parse_config_value - Fix _init_style_kwargs to update _style_kwargs in place instead of overwriting, so adding new style-specific settings later won't clobber - Include identifier and truncated raw input in Parse Error messages for easier debugging of Crossref parsing failures - Fix misleading README example comment for gbmedium
When Crossref/Springer returns 200 OK with HTML content (ignored Accept header), _handle_doi was returning the raw HTML to the parser, causing 'list index out of range'. Now detects non-BibTeX responses and returns network_err early. Adds a test that mocks an HTML response to verify.
Narrow the HTML-vs-BibTeX check to only flag responses that look like HTML (<!DOCTYPE or <html), not any non-@ content. This avoids false positives on plain-text responses while still catching Crossref/Springer returning HTML error/landing pages instead of BibTeX. Updates the handler tests to cover both the success and HTML-response cases.
| # Merge with existing user config and write back | ||
| existing = _read_user_config() | ||
| existing.update(config) | ||
| _write_user_config(existing) | ||
| print(f"Setting configurations:\n{json.dumps(config, indent=4)}") |
| if len(args_set) != 2: | ||
| print("Error: ``set`` accepts exactly 2 arguments: KEY VALUE.") | ||
| sys.exit(1) |
| def _fake_handle(self, feed_content): | ||
| # Pretend we got a 200 OK with HTML content | ||
| # by monkeypatching session.get directly | ||
| pass | ||
|
|
Summary
gbmediumconfig option for GB/T 7714 style:Trueforces[J/OL],Falseforces[J],None(default) auto-detects from DOI/URL fieldsbib-lookup set KEY VALUEsubcommand for setting individual config values (none/nullresets toNone)--confignow warns on unknown keys instead of silently discarding them (keys are still written)_style_kwargsdict via_init_style_kwargs, making it easy to add new per-style parametersstr2boolnow passesNonethrough so config keys reset toNonework for boolean fields