Skip to content

Fix compatibility with bibtexparser 2 - #590

Open
pattems wants to merge 1 commit into
scholarly-python-package:developfrom
pattems:py313-bibtexparser-2
Open

pattems wants to merge 1 commit into
scholarly-python-package:developfrom
pattems:py313-bibtexparser-2

Conversation

@pattems

@pattems pattems commented Oct 29, 2026

Copy link
Copy Markdown

Fixes #546.

Description

bibtexparser 2.x is now the stable release on PyPI (2.0.1 on 2026-09-10, 2.1.0 on 2026-10-02). It removes bibtexparser.bibdatabase, bparser, loads() and dumps(). Since bibtexparser is unpinned in setup.py and requirements.txt, a fresh pip install scholarly on Python 3.10+ now pulls in 2.x, and import scholarly fails with

ModuleNotFoundError: No module named 'bibtexparser.bibdatabase'

This PR moves the BibTeX parsing (in PublicationParser.fill) and writing (in PublicationParser.bibtex) into two small helpers. They use the 2.x API when it's installed and the 1.x API otherwise, so nothing needs pinning: bibtexparser 2 requires Python 3.10, and pip still installs 1.x on 3.8/3.9. The 2.x path produces the same entry dict (ENTRYTYPE, ID, lower-case field names, unbraced values) and the same BibTeX text as 1.x (fields sorted by name, one-space indent, {}-enclosed values). testdata/test_bibtex_result.txt therefore still matches.

Checklist

  • Check that the base branch is set to develop and not main.
  • Ensure that the documentation will be consistent with the code upon merging. (No API change.)
  • Add a line or a few lines that check the new features added. (The existing test_bibtex covers the output; see below for an offline check.)
  • Ensure that unit tests pass. (Offline check below; I didn't run the network tests against Google Scholar.)

Testing

Offline script, run against this branch on CPython 3.12.13, 3.13.14 and 3.14.3, each with bibtexparser 1.4.4 and with 2.1.0 (six venvs). It feeds PublicationParser.fill() a Google-Scholar-style BibTeX string for the test_bibtex paper through a stub navigator, then calls bibtex() on the filled publication:

  • bibtex() output is byte-identical to testdata/test_bibtex_result.txt in all six combinations
  • the bib dict produced by fill() is identical across all six
  • parse+dump round-trip of the fixture reproduces it exactly
  • before this change: bibtexparser 1.4.4 passes, and with 2.1.0 the import fails with the ModuleNotFoundError above
  • flake8 scholarly/publication_parser.py with the repo's .flake8: 0 issues

Context: found while testing packages against Python 3.13 for FreeBSD ports (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292105).

bibtexparser 2.x (2.0.1 and 2.1.0 are now the latest stable releases on
PyPI) removed bibtexparser.bibdatabase, bparser, loads() and dumps(), so
"import scholarly" fails with
ModuleNotFoundError: No module named 'bibtexparser.bibdatabase'
on any fresh install on Python 3.10+.

Move the BibTeX parsing and writing into two helpers that use the 2.x
API when it is available and the 1.x API otherwise (bibtexparser 2
requires Python 3.10, so 3.8 and 3.9 still get 1.x). The 2.x path
produces the same entry dicts and the same BibTeX text as 1.x
(fields sorted by name, one-space indent, brace-enclosed values).

Fixes scholarly-python-package#546.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T01:44:33.711798Z 6e133f4 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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