xuhcc / beancount-ethereum-importer

Ethereum transaction importer for Beancount
GNU General Public License v3.0
11 stars 5 forks source link

bean-identify breaks when using beancount ethereum #9

Closed hhamud closed 2 years ago

hhamud commented 2 years ago

The indentify function in the importer class cannot be called.

here is the traceback:

  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 64, in find_imports
    matched = importer.identify(file)
AttributeError: 'tuple' object has no attribute 'identify'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/bin/bean-identify", line 33, in <module>
    sys.exit(load_entry_point('beancount==2.3.5', 'console_scripts', 'bean-identify')())
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 31, in identify_main
    return trampoline_to_ingest(identify)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 198, in trampoline_to_ingest
    return run_import_script_and_ingest(parser)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 246, in run_import_script_and_ingest
    return ingest(importers_list)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 140, in ingest
    args.command(args, parser, importers_list, abs_downloads, hooks=hooks)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 100, in run
    return identify(importers_list, files_or_directories)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 82, in identify
    for filename, importers in find_imports(importers_list, files_or_directories,
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 69, in find_imports
    importer.name(), exc)
AttributeError: 'tuple' object has no attribute 'name'
[<importers.custom_importers.BinanceImporter object at 0x7f9267dc8850>, <importers.custom_importers.KrakenImporter object at 0x7f9267dc87f0>, <beancount.ingest.importers.csv.Importer object at 0x7f926790b520>, <beancount.ingest.importers.csv.Importer object at 0x7f926790ba60>, (<importers.custom_importers.ETHImporter object at 0x7f926790ba90>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9d0>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9a0>,)]
Traceback (most recent call last):
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 64, in find_imports
    matched = importer.identify(file)
AttributeError: 'tuple' object has no attribute 'identify'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/bin/bean-extract", line 33, in <module>
    sys.exit(load_entry_point('beancount==2.3.5', 'console_scripts', 'bean-extract')())
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 36, in extract_main
    return trampoline_to_ingest(extract)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 198, in trampoline_to_ingest
    return run_import_script_and_ingest(parser)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 246, in run_import_script_and_ingest
    return ingest(importers_list)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/scripts_utils.py", line 140, in ingest
    args.command(args, parser, importers_list, abs_downloads, hooks=hooks)
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/extract.py", line 243, in run
    extract(importers_list, files_or_directories, sys.stdout,
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/extract.py", line 177, in extract
    for filename, importers in identify.find_imports(importer_config,
  File "/home/user/Documents/hamud_group/Accounting/beancount_accounting/venv/lib/python3.10/site-packages/beancount/ingest/identify.py", line 69, in find_imports
    importer.name(), exc)
AttributeError: 'tuple' object has no attribute 'name'
xuhcc commented 2 years ago

@hhamud It doesn't look like it comes from beancount-ethereum. Please check your importer list, some of its items are tuples:

[<importers.custom_importers.BinanceImporter object at 0x7f9267dc8850>, <importers.custom_importers.KrakenImporter object at 0x7f9267dc87f0>, <beancount.ingest.importers.csv.Importer object at 0x7f926790b520>, <beancount.ingest.importers.csv.Importer object at 0x7f926790ba60>, (<importers.custom_importers.ETHImporter object at 0x7f926790ba90>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9d0>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9a0>,)]

hhamud commented 2 years ago

@hhamud It doesn't look like it comes from beancount-ethereum. Please check your importer list, some of its items are tuples:

[<importers.custom_importers.BinanceImporter object at 0x7f9267dc8850>, <importers.custom_importers.KrakenImporter object at 0x7f9267dc87f0>, <beancount.ingest.importers.csv.Importer object at 0x7f926790b520>, <beancount.ingest.importers.csv.Importer object at 0x7f926790ba60>, (<importers.custom_importers.ETHImporter object at 0x7f926790ba90>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9d0>,), (<importers.custom_importers.ETHImporter object at 0x7f926790b9a0>,)]

I had to go directly into the beancount package and print out what was being processed in the function find_imports in identify.py. Only the beancount-ethereum package importers are being coupled in a tuple and I don't really understand why?

xuhcc commented 2 years ago

I don't know. importers.custom_importers.ETHImporter is not beancount-ethereum importer (unless you somehow wrap it). The python import path of the importer from beancount-ethereum package should look like beancount_ethereum.importer.Importer.

hhamud commented 2 years ago

I don't know. importers.custom_importers.ETHImporter is not beancount-ethereum importer (unless you somehow wrap it). The python import path of the importer from beancount-ethereum package should look like beancount_ethereum.importer.Importer.

Printed snippet from using the Importer class straight from the package: [<importers.custom_importers.BinanceImporter object at 0x7fa4a0530700>, <importers.custom_importers.KrakenImporter object at 0x7fa4a05306d0>, <beancount.ingest.importers.csv.Importer object at 0x7fa4a00ae860>, <beancount.ingest.importers.csv.Importer object at 0x7fa4a00ae9b0>, (<beancount_ethereum.importer.Importer object at 0x7fa4a00ae9e0>,), (<beancount_ethereum.importer.Importer object at 0x7fa4a00ae920>,), (<beancount_ethereum.importer.Importer object at 0x7fa4a00ae8f0>,)]

I was having the same problems and what I did was I copied the importer into its own individual file to try and debug and I am still getting the same error.

xuhcc commented 2 years ago

How do you run bean-identify? Could you show your importer configuration file?

hhamud commented 2 years ago

sure, I run bean-identify via bash bean-identify config.py data/

All data files are either json or csv. config.py file

import os
from beancount.ingest.importers.csv import Importer as CSVImporter, Col
from importers.custom_importers import BinanceImporter, KrakenImporter
from beancount_ethereum import Importer as ETHImporter

config_dir = os.path.join(os.path.dirname(__file__), 'chain_configs')

binance_importer = BinanceImporter(
                       'Income:Cash', # account
)

kraken_importer=KrakenImporter("Income:Cash", "Expenses:Fees:Kraken")

tide_importer = CSVImporter({
                        Col.DATE: 'Date',
                        Col.NARRATION1: 'Transaction description',
                        Col.ACCOUNT: 'From',
                        Col.PAYEE: 'To',
                        Col.AMOUNT: 'Amount',
                        },
                       'Assets:Cash', # account
                       'GBP', # currency
                            )

amazon_importer = CSVImporter({
                        Col.DATE: 'Order Date',
                        Col.NARRATION1: 'Title',
                        Col.ACCOUNT: 'Account Group',
                        Col.PAYEE: 'Seller Name',
                        Col.AMOUNT: 'Item Net Total',
                        },
                       'Expenses:Amazon', # account
                       'GBP', # currency
                              )

eth_importer = ETHImporter(config_path=os.path.join(config_dir, 'ethereum.json')),
gnosis_importer = ETHImporter(config_path=os.path.join(config_dir, 'gnosis.json')),
arb_importer = ETHImporter(config_path=os.path.join(config_dir, 'arbitrum.json')),

# beancount's scripts use this
CONFIG = [binance_importer, kraken_importer, tide_importer, amazon_importer, eth_importer, gnosis_importer, arb_importer]
xuhcc commented 2 years ago

Look at this part:

eth_importer = ETHImporter(config_path=os.path.join(config_dir, 'ethereum.json')),
gnosis_importer = ETHImporter(config_path=os.path.join(config_dir, 'gnosis.json')),
arb_importer = ETHImporter(config_path=os.path.join(config_dir, 'arbitrum.json')),

There's a comma at the end of each line. In Python x = y, is the same as x = (y,) that's why you've got tuples