local plugin import issue

135 views
Skip to first unread message

Stefano Zacchiroli

unread,
Dec 29, 2017, 11:09:49 AM12/29/17
to bean...@googlegroups.com
Heya,
an import issue for a local beancount plugin is driving me crazy. The
plugin is (locally) installed as a python3 module that can be loaded
just fine by any python3 invocation I could imagine, but bean-check
cannot find it.

------------------------------------------------------------------------
Example/walkthrough, with commentary:

## bean-check fails loading the module
zack@scaramouche:~/dati/ledger$ bean-check current.beancount
<load>:0: Error importing "mybeancount.public.file_ordering": No module named 'mybeancount.public.file_ordering'

## the module is well declared in the beancount ledger, which is why
## bean-check tries to load it
zack@scaramouche:~/dati/ledger$ grep -n file_ordering current.beancount
12:plugin "mybeancount.public.file_ordering"

## bean-check is executed as env python3
zack@scaramouche:~/dati/ledger$ head -n 1 `which bean-check`
#!/usr/bin/env python3

## trying by hand, the plugin loads as a module just fine
zack@scaramouche:~/dati/ledger$ /usr/bin/env python3
Python 3.6.4 (default, Dec 19 2017, 14:09:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mybeancount.public.file_ordering
>>>

## trying by hand, take 2, using importlib in exact the same way that
## the beancount Python library does. Again, works just fine:
zack@scaramouche:~/dati/ledger$ /usr/bin/env python3
Python 3.6.4 (default, Dec 19 2017, 14:09:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib
>>> importlib.import_module('mybeancount.public.file_ordering')
<module 'mybeancount.public.file_ordering' from '/home/zack/.local/lib/python3.6/site-packages/mybeancount/public/file_ordering.py'>
>>>
------------------------------------------------------------------------

What am I missing here? I've also looked for sys.path fiddling in the
beancount code, but didn't find any that seem relevant here.

I'm able to reproduce the issue on two different machines (Debian
testing and Debian Stretch), with fresh beancount installations.

Many thanks in advance for your help,
Cheers
--
Stefano Zacchiroli . za...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader & OSI Board Director . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

Martin Blais

unread,
Dec 29, 2017, 1:47:15 PM12/29/17
to Beancount
Did you export PYTHONPATH?
Defining it is not enough, you need to export it (that's a bash construct).

Otherwise, add some printf's here:
https://bitbucket.org/blais/beancount/src/tip/beancount/loader.py?fileviewer=file-view-default#loader.py-506

Also, does your module have a __plugins__ attribute?
(I'll add a warning about that, I think it's currently a silent failure)




--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20171229160941.GC16638%40upsilon.cc.
For more options, visit https://groups.google.com/d/optout.

Stefano Zacchiroli

unread,
Dec 30, 2017, 1:38:36 AM12/30/17
to bean...@googlegroups.com
On Fri, Dec 29, 2017 at 01:46:51PM -0500, Martin Blais wrote:
> Did you export PYTHONPATH?

That wasn't it. I don't even define a PYTHONPATH, because all modules
are installed in system-wide dirs that are in the default sys.path.

The "fix" was removing the beancount-specific picklecache. Many thanks
to Whoop on the #beancount IRC channel for suggesting this.

I was experimenting with the module installation without changing the
beancount file, so it was being cached. I'm guessing it also caches
something that inhibits re-loading user-defined plugins, because
otherwise this (still) doesn't make sense to me :)

Thanks anyway for your quick feedback Martin!

Martin Blais

unread,
Dec 30, 2017, 1:41:14 AM12/30/17
to Beancount
That explains it.

I'd like to improve the command-line options for controlling the cache at some point, they're not great.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages