Add APA, IEEE, and Chicago citation styles#34
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #34 +/- ##
==========================================
+ Coverage 98.05% 98.55% +0.49%
==========================================
Files 10 13 +3
Lines 1438 1795 +357
==========================================
+ Hits 1410 1769 +359
+ Misses 28 26 -2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
Adds new local Pybtex-based citation formatting styles (APA 7, IEEE, Chicago 17) to complement the existing GB/T 7714 support, and expands the test suite to validate expected rendered outputs.
Changes:
- Introduce
APAStyle,IEEEStyle, andChicagoStyleimplementations underbib_lookup/styles/. - Update
BibLookupto formatformat="text"locally (via BibTeX parsing + Pybtex templates) for supported styles. - Replace/expand style tests with example-driven expected outputs and additional coverage tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
bib_lookup/bib_lookup.py |
Routes format="text" for supported styles through local Pybtex formatting and forces BibTeX retrieval. |
bib_lookup/styles/apa.py |
Adds APA 7th Edition formatting templates and author-name rules. |
bib_lookup/styles/ieee.py |
Adds IEEE formatting templates plus month/pages helpers and author-name rules. |
bib_lookup/styles/chicago.py |
Adds Chicago 17th (Notes & Bibliography) formatting templates and author-name rules. |
bib_lookup/styles/gbt7714.py |
Updates GB/T template behavior and name formatting logic used by local rendering. |
bib_lookup/styles/__init__.py |
Exports the new styles from the package. |
test/test_styles.py |
Reworks tests around a shared example corpus and adds coverage-oriented assertions. |
.github/workflows/publish.yml |
Bumps artifact upload/download GitHub Actions versions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| # Test IEEE style - add label [1] as pybtex would | ||
| ieee_style = IEEEStyle() | ||
| ieee_template = ieee_style.get_article_template(entry) | ||
| ieee_result = str(ieee_template.format_data({"entry": entry, "bib_data": bib_data, "style": ieee_style})).strip() | ||
| ieee_result_with_label = f"[1] {ieee_result}" | ||
| assert ( |
| surname = " ".join(parts).upper() # GB/T 7714 requires uppercase surnames | ||
| initials_list = [] | ||
| for names_list in [person.first_names, person.middle_names]: | ||
| for name in names_list: | ||
| if name: | ||
| initials_list.append(name[0]) | ||
|
|
||
| initials_list.append(name[0].upper()) # Uppercase initials | ||
| initials = " ".join(initials_list) | ||
| return f"{surname} {initials}".strip() |
bib_lookup/bib_lookup.py
Outdated
| # For APA/Chicago style, we prefer their default max_names (20/10) | ||
| # if the global max_names is still at default (3) | ||
| if style.lower() in ["apa", "chicago"] and self.max_names == 3: | ||
| custom_style = style_class() |
| if "doi" in e.fields: | ||
| doi = e.fields["doi"] | ||
| if not doi.startswith("http"): | ||
| doi = f"https://doi.org/{doi}" | ||
| template = join(sep=". ")[template, doi] | ||
| if "url" in e.fields: | ||
| # Add URL even if DOI is present (per expected output) | ||
| template = join(sep=". ")[template, field("url")] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2da42d4b33
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
bib_lookup/styles/gbt7714.py
Outdated
| join(sep=": ")[ | ||
| join[optional_field("volume"), optional["(", field("number"), ")"]], | ||
| optional[field("pages")], | ||
| field("pages"), |
There was a problem hiding this comment.
Keep GB/T article pages optional during formatting
Using field("pages") makes page numbers mandatory for every GB/T article, but many DOI/Crossref records legitimately omit pages (online-first articles, article-number journals, etc.); when that happens the template evaluation raises and BibLookup.__call__ falls back to default_err, so text citation lookup fails for otherwise valid entries. This was previously tolerant via an optional pages field and should remain optional.
Useful? React with 👍 / 👎.
bib_lookup/styles/gbt7714.py
Outdated
| optional[field("pages")], | ||
| ], | ||
| join(sep=": ")[optional_field("address"), field("publisher")], | ||
| join(sep=": ")[field("year"), field("pages")], |
There was a problem hiding this comment.
Keep GB/T conference pages optional during formatting
The inproceedings template now requires pages unconditionally, so conference entries without page metadata raise during formatting and end up as lookup errors in text mode. Since missing pages are common in upstream metadata, this turns valid entries into failures and regresses previous behavior where pages were optional.
Useful? React with 👍 / 👎.
| return ", ".join(formatted_persons[:-1]) + f", and {formatted_persons[-1]}" | ||
| else: | ||
| # Truncated case | ||
| persons_to_format = persons[:7] |
There was a problem hiding this comment.
Honor configured Chicago author limit in truncation
The truncation branch ignores self.limit and always takes persons[:7], so when callers set a custom max_names (propagated to ChicagoStyle), output can include more authors than configured before adding et al (for example, limit 3 can still print up to 7 names). This makes the max_names setting ineffective for Chicago output.
Useful? React with 👍 / 👎.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Implements three new citation styles (APA 7th Edition, IEEE, and Chicago 17th Edition) alongside the existing GB/T 7714-2015 style.
New Style Classes
Supported Entry Types