Skip to content

feat: add gbmedium config, set CLI subcommand, and config warning#50

Merged
wenh06 merged 6 commits into
masterfrom
feat/gbmedium-and-set-config
Jul 4, 2026
Merged

feat: add gbmedium config, set CLI subcommand, and config warning#50
wenh06 merged 6 commits into
masterfrom
feat/gbmedium-and-set-config

Conversation

@wenh06

@wenh06 wenh06 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add gbmedium config option for GB/T 7714 style: True forces [J/OL], False forces [J], None (default) auto-detects from DOI/URL fields
  • Add bib-lookup set KEY VALUE subcommand for setting individual config values (none/null resets to None)
  • --config now warns on unknown keys instead of silently discarding them (keys are still written)
  • Refactor: style-specific settings collected in _style_kwargs dict via _init_style_kwargs, making it easy to add new per-style parameters
  • str2bool now passes None through so config keys reset to None work for boolean fields

wenh06 added 3 commits July 4, 2026 15:49
…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.
Copilot AI review requested due to automatic review settings July 4, 2026 07:50
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@c79f342). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
bib_lookup/cli.py 95.91% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copilot AI 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.

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 gbmedium config/constructor option and propagate it into the GB/T 7714 formatter to control [J] vs [J/OL].
  • Add bib-lookup set KEY VALUE for updating individual config keys, including resetting to None.
  • Refactor style-specific parameters into BibLookup._style_kwargs and 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.

Comment thread bib_lookup/cli.py
Comment on lines +111 to 115
# 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(
Comment thread bib_lookup/cli.py
Comment on lines +48 to +50
if value.startswith("[") and value.endswith("]"):
return [v.strip() for v in value.strip("[]").split(",")]
return value
Comment thread bib_lookup/bib_lookup.py Outdated
Comment on lines +415 to +419
self._style_kwargs = {
"gbt7714": {"gbmedium": _gbmedium_val},
"gbt": {"gbmedium": _gbmedium_val},
"gbt-7714": {"gbmedium": _gbmedium_val},
}
Comment thread README.md Outdated
```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"
wenh06 added 3 commits July 4, 2026 19:02
- 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.
@wenh06 wenh06 requested a review from Copilot July 4, 2026 13:02
@wenh06 wenh06 added the enhancement New feature or request label Jul 4, 2026
@wenh06 wenh06 enabled auto-merge July 4, 2026 13:03

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread bib_lookup/cli.py
Comment on lines +124 to 128
# 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)}")
Comment thread bib_lookup/cli.py
Comment on lines +138 to +140
if len(args_set) != 2:
print("Error: ``set`` accepts exactly 2 arguments: KEY VALUE.")
sys.exit(1)
Comment thread test/test_styles.py
Comment on lines +623 to +627
def _fake_handle(self, feed_content):
# Pretend we got a 200 OK with HTML content
# by monkeypatching session.get directly
pass

@wenh06 wenh06 added this pull request to the merge queue Jul 4, 2026
Merged via the queue into master with commit edf0925 Jul 4, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants