smart_importer.apply_hooks works by monkey patching an Importer's extract 
method. I don't think anyone would ever argue that monkey patching methods 
in Python is anything other than a method of last resort to use in the 
absence of a better defined API.

beangulp provides an API, which smart_importer.apply_hooks doesn't use.

smart_importer doesn't use beangulp's API because the "shape" of the API is 
different from the smart_importer implementation. smart_importer expects to 
be called with (importer: Importer, file: str, imported_entries: 
data.Directives, existing: data.Directives) but that's not what beangulp 
calls hooks with. It calls them with (extracted: list[import_file:str, 
imported_entries: data.Directives, import_account:str, importer: Importer], 
existing: data.Directives).

That is: smart_importer works on a single account -- if you want to use it 
on multiple accounts you are expected to create multiple instances. But 
beangulp hooks are expected to work on multiple accounts -- if they need to 
only operate on some subset of accounts it is up to them to skip those 
during processing.

By not being a beangulp hook and instead monkey patching the importer's 
extract, it means that smart_importer gets invoked at a different point in 
time than beangulp hooks. In particular, it gets invoked before beangulp's 
deduplication instead of after. And since it monkey patches the importer's 
extract instead of being passed in a list to beangulp.Ingest(importers, 
hooks) it means the user can't control when the hook is run relative to 
other hooks. That means you can't, for instance, run a "clean up my bank's 
weird naming of payees before running ML training" hook before running 
smart_importer.

On Sunday, March 9, 2025 at 7:11:24 PM UTC+10:30 Red S wrote:

> Out of curiosity: I’m sure it’s just me, but I don’t understand what about 
> smart_importer is not working with beangulp? smart_importer.apply_hooks 
> is what I was using to apply smart_importer.PredictPostings, and that 
> works equally well with beangulp as it did with v2’s ingest. <scratching 
> head>??
> ​
>
>
> On Thursday, March 6, 2025 at 3:06:24 AM UTC-8 just...@gmail.com wrote:
>
>> I consider "doesn't work with beangulp hooks" as "doesn't work with 
>> beangulp". YMMV.
>>
>> On Thursday, March 6, 2025 at 8:39:41 PM UTC+10:30 Patrick Ruckstuhl 
>> wrote:
>>
>>> Hi, 
>>>
>>> No it's not. It's running great with beancount 3, beangulp and fava with 
>>> the last upgrade (did the changes after fava supported it). There are still 
>>> some potential improvements to maybe drop the smartimporter hooks and use 
>>> standard beangulp hooks but right now it works well. 
>>>
>>> Regards, 
>>> Patrick 
>>>
>>> On March 6, 2025 11:04:28 AM GMT+01:00, Stefano Zacchiroli <
>>> za...@upsilon.cc> wrote: 
>>> >On Wed, Mar 05, 2025 at 11:09:10PM -0800, Justus Pendleton wrote: 
>>> >> I searched previous posts but couldn't find anyone that had 
>>> contributed a 
>>> >> beangulp hook that mimics the "predict postings" thing from legacy 
>>> >> smart_importer. 
>>> > 
>>> >In what sense is smart_importer "legacy"? Has it been declared 
>>> abandoned 
>>> >/ incompatible with v3 or ....? 
>>> > 
>>> >Thanks! 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/beancount/0bdad3c8-1616-40c5-af39-5be59fdec9f5n%40googlegroups.com.

Reply via email to