Support Beancount v3 (and v2.3+) via beangulp/beanquery - #263
Merged
Merged
Conversation
beancount v3 extracted the import framework into beangulp and the query engine into beanquery. Add both as dependencies (pinned to the tested 0.2.0) and relax the beancount constraint to >=2.3.5 (both companion packages support 2.3+, so v2 users are not forced to upgrade). Bump python_requires to >=3.9. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wrap legacy ImporterProtocol importers in beangulp's Adapter and accept native beangulp.Importer subclasses directly, so importers written against either interface work. Importers receive absolute paths instead of _FileMemo objects, name is read as a property, and extract() takes existing entries positionally. Fixes jbms#253. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
beancount.query and beancount.ops.prices were removed in v3. Reimplement the two BQL admin utilities on beanquery's public run_query API, mapping result rows back to directives/postings via hash_entry (rename_account keys on account+position+price+posting_flag so a WHERE targeting one of several same-account postings renames only that one). delete_transactions now matches Transaction directives only; this is documented in its docstring/CLI help. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
v3 attaches __automatic__ to interpolated postings and __residual__ to account_rounding postings. Add both to META_IGNORE so they do not enter the posting-match tuple and break matching against imported counterparts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
v3 ships py.typed, so mypy newly type-checks the whole codebase against beancount's Directive union. Treat beancount/beangulp/beanquery as untyped (follow_imports=skip) to preserve pre-v3 behavior, and silence pre-existing BeautifulSoup/lxml false-positives surfaced by current mypy/bs4 versions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pkg_resources (setuptools) is deprecated and absent from minimal/isolated environments (tox venv, Python >=3.12). Use importlib.resources (stdlib, 3.9+) to read the frontend assets, removing the runtime setuptools dependency. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
beancount v3 requires Python >=3.9, so drop 3.8 and extend to 3.12; set fail-fast: false. Install setuptools and setuptools_scm explicitly since 3.12 no longer bundles setuptools and setup.py needs them. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Parametrized test importing every beancount_import module, to catch import-time regressions such as removed v3 APIs before they surface at runtime. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
This is great! Is there anything I can do to help get this PR merged? Thank you. |
Collaborator
Author
|
@Trigun27 can you test it on your setup? |
Sorry for the delay. I refactored it to use the new PR methods. Works on my end now: parsers and dedup are both good. |
Collaborator
Author
|
Thanks for testing @Trigun27. |
|
Thanks for this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for Beancount v3 while staying compatible with v2.3+.
v3 extracted the import framework into
beangulpand the query engine intobeanquery, and removedbeancount.ingest,beancount.query, andbeancount.ops.prices. This PR migrates the code that used those APIs onto the new packages.Both
beangulpandbeanquerysupport beancount 2.3+ as well as 3.x, so the constraint is relaxed tobeancount>=2.3.5rather than forcing v3 — existing v2 users are unaffected.Fixes #253. This is an alternative to #256 that additionally accepts native
beangulp.Importersubclasses (not only legacyImporterProtocol) and covers the rest of the v3 surface (query CLIs, posting metadata, typing, packaging/CI).Changes (8 focused commits)
generic_importer_source— accept nativebeangulp.Importerand wrap legacyImporterProtocolimporters via beangulp'sAdapter, so importers written against either interface work (Beangulp compatible? #253).delete_transactions/rename_account— migrate the two BQL utilities from the removedbeancount.querytobeanquery.journal_editor— ignore v3's__automatic__/__residual__posting metadata so it doesn't leak into the posting-match key and break matching.webserver— read the bundled frontend via stdlibimportlib.resourcesinstead of the deprecatedpkg_resources.py.typedbeancount/beangulp/beanquery as untyped, preserving the project's existing type-check behavior.python_requires>=3.9, a Python 3.9–3.12 test matrix, and an import smoke test guarding against import-time regressions.Testing
🤖 Generated with Claude Code