Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse include properly #4

Open
8h2a opened this issue Feb 11, 2016 · 18 comments
Open

parse include properly #4

8h2a opened this issue Feb 11, 2016 · 18 comments

Comments

@8h2a
Copy link

8h2a commented Feb 11, 2016

The moment i started "buy" i got this error message:

Cannot open ledger file: unparsable data at line 1, char 1

And the following stacktrace:

Traceback (most recent call last):
  File "/usr/local/bin/buy", line 5, in <module>
    pkg_resources.run_script('ledgerhelpers==0.0.20', 'buy')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 528, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1394, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/EGG-INFO/scripts/buy", line 11, in <module>
    sys.exit(buy.main())
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/programs/buy.py", line 276, in main
    journal, s = common.load_journal_and_settings_for_gui()
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/__init__.py", line 44, in f
    return kallable(*a, **kw)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/__init__.py", line 955, in load_journal_and_settings_for_gui
    cannot_start_dialog("Cannot open ledger file: %s" % e)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/__init__.py", line 927, in <lambda>
    cannot_start_dialog = lambda msg: FatalError("Cannot start program", msg, outside_mainloop=True)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/__init__.py", line 924, in FatalError
    d.run()
KeyboardInterrupt

My setup: The first and only line in my main ledger file is an "include ..." which includes another ledger file.
The included ledger file also has an "include" to include the previous ledger file (from the previous year). This won't work if the include path is relative:

While parsing file "", line 1:
Error: File to include was not found: [...]

Once i fixed that i noticed that i had to remove the next line which was "D 1,000.00 €". So i removed that line as well. Then i got the following error:

Traceback (most recent call last):
  File "/usr/local/bin/buy", line 5, in <module>
    pkg_resources.run_script('ledgerhelpers==0.0.20', 'buy')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 528, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1394, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/EGG-INFO/scripts/buy", line 11, in <module>
    sys.exit(buy.main())
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/programs/buy.py", line 282, in main
    win = klass(journal, s, " ".join(args) if args else None)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/programs/buy.py", line 101, in __init__
    BuyWindow.__init__(self)
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/programs/buy.py", line 37, in __init__
    self.amount = common.LedgerAmountEntry()
  File "/usr/local/lib/python2.7/dist-packages/ledgerhelpers-0.0.20-py2.7.egg/ledgerhelpers/__init__.py", line 738, in __init__
    self.display.set_xalign(1.0)
AttributeError: 'Label' object has no attribute 'set_xalign'
@Rudd-O
Copy link
Owner

Rudd-O commented Feb 11, 2016

I need to address the include problem as it's a legit bug, and so is the D as well.

The other issue you refer to is a matter of figuring out what GTK+ version you have on your system, because I fear you might have a strange version -- set_xalign() is a documented method of GtkLabel so that shouldn't give you any sort of problem.

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 11, 2016

Reminder for myself to notify the author of this pull request when the include issue is fixed:

#1

@8h2a
Copy link
Author

8h2a commented Feb 11, 2016

I'm using Ubuntu 14.04
python-gtk2 2.24.0-3ubuntu3

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 12, 2016

Do you have python gobject 3? Python-GTK2 is not enough. I don't know how your error happened given that the script demands version 3.:

#!/usr/bin/env python

import datetime
from gi.repository import GObject
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import sys
import threading

It's obviously demanding Gtk 3 before instantiating the wrappers. Gtk 2 doesn't have that method, but Gtk 3 does. This is maddening. How would we go about finding out which version of Gtk is being imported here, on your machine?

@8h2a
Copy link
Author

8h2a commented Feb 12, 2016

Yes, I do have python-gobject 3.12.0-1ubuntu1

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 13, 2016

So can you check this out?

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
help (Gtk.Label.set_xalign)

and see if you get that AttributeError again?

@8h2a
Copy link
Author

8h2a commented Feb 14, 2016

I get the same error message again:

AttributeError: type object 'Label' has no attribute 'set_xalign'

Apparently my python uses the version "libgtk-3-0:amd64 3.10.8-0ubuntu1.6".
I checked it with:

>>> Gtk.get_major_version()
3L
>>> Gtk.get_minor_version()
10L
>>> Gtk.get_micro_version()
8L

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 14, 2016

Something is bugged with your Gtk+. Can you file a bug report with
Ubuntu about labels not having set_xalign()? That is a normal method in
Gtk+ 3 and higher.

Rudd-O
http://rudd-o.com/

@8h2a
Copy link
Author

8h2a commented Feb 14, 2016

Apparently this function is only available in version 3.16 and above.

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 14, 2016

On 02/14/2016 01:04 PM, d wrote:

Apparently this function is only available in version 3.16 and above.


Reply to this email directly or view it on GitHub
#4 (comment).

How did you find out about that?

Rudd-O
http://rudd-o.com/

@8h2a
Copy link
Author

8h2a commented Feb 14, 2016

@Rudd-O
Copy link
Owner

Rudd-O commented Feb 14, 2016

OK. I have pushed a fix that stops using set_xalign(). It should be tagged 0.0.21 and I'd like your feedback.

@Rudd-O Rudd-O changed the title Issues with my ledger file parse include properly Feb 14, 2016
@Rudd-O
Copy link
Owner

Rudd-O commented Feb 14, 2016

As for how include should be dealt with, the parsing of the file needs to be done in such a way that there need to be two parsing modes:

Mode A treats includes by simply tokenizing them as stanzas, but does not attempt to include anything. The resulting data structure contains include tokens.

Mode B recursively parses includes. The resulting data structure contains the tokens from the included files in lieu of the includes.

Mode A is necessary for things like sorting the data file. Mode B is necessary for things like producing autocomplete transactions in addtrans.

@8h2a
Copy link
Author

8h2a commented Feb 14, 2016

Thanks! It seems to be working now.

The issue with the "D 1,000.00 €" still remains though.
And i found a new minor bug: In the UI it says "$" everywhere, but when it saves the transaction it's actually "€". (The stored transaction is correct).

And it uses "," instead of "." for the currency.
e.g. "€ -13,00" instead of "€ -13.00".
That is because of the aforementioned missing default commodity setting.

Should i open up new issues to discuss them separately?

@Rudd-O
Copy link
Owner

Rudd-O commented Oct 5, 2016

Yes please, thank you!

@hoclun-rigsep
Copy link

Bumping this issue; I would like to use addtrans but the structure of my includes takes precedence.

@phylor
Copy link
Contributor

phylor commented Apr 8, 2020

@Rudd-O Are you still planning to add support for the include directive? I'd love to use addtrans, but can't because it doesn't like the include directive.

@Rudd-O
Copy link
Owner

Rudd-O commented Apr 14, 2020

I am planning to, because I need to get addtrans to work with Beancount as well, and -- quite frankly -- both Ledger and Beancount require support for include.

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

No branches or pull requests

4 participants