New issue 202: Question: How to create a python package for a price source?

https://bitbucket.org/blais/beancount/issues/202/question-how-to-create-a-python-package



vonpupp:



Hi,



I have created a custom price source that seems to work fine, however I would 
like to be able to create a package for it so it can be easily distributed and 
maintained without messing with beancount source code.



Currently I have the following package skeleton (I used cookicutter)

```

.

├── beancount_cryptocompare

│   ├── cryptocompareusd.py

│   └── __pycache__

│       ├── cryptocompareusd.cpython-36.pyc

│       └── __init__.cpython-36.pyc

├── beancount_cryptocompare.egg-info

│   ├── dependency_links.txt

│   ├── not-zip-safe

│   ├── PKG-INFO

│   ├── requires.txt

│   ├── SOURCES.txt

│   └── top_level.txt

├── ...

├── setup.cfg

├── setup.py

```



When I run a python shell and `import beancount_cryptocompare.cryptocompareusd` 
it doesn't complain, however when I use the namespace on the price attribute it 
doesn't work, example:



```

(.env3) > $ bean-price -e USD:cryptocompareusd/ETH --no-cache                   
                                                                                
                  

Traceback (most recent call last):

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
147, in import_source

    __import__(default_name)

ModuleNotFoundError: No module named 'beancount.prices.sources.cryptocompareusd'



During handling of the above exception, another exception occurred:



Traceback (most recent call last):

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
151, in import_source

    __import__(module_name)

  File 
"/home/av/repos/crypto/beancount_cryptocompare/beancount_cryptocompare/cryptocompareusd.py",
 line 10, in <module>

    import cryptocompare

ModuleNotFoundError: No module named 'cryptocompare'



During handling of the above exception, another exception occurred:



Traceback (most recent call last):

  File "/usr/bin/bean-price", line 2, in <module>

    from beancount.prices.price import main; main()

  File "/usr/lib/python3.6/site-packages/beancount/prices/price.py", line 310, 
in main

    args, jobs, entries = process_args()

  File "/usr/lib/python3.6/site-packages/beancount/prices/price.py", line 281, 
in process_args

    psource_map = find_prices.parse_source_map(source_str)

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
99, in parse_source_map

    for source_str in source_strs.split(','))

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
99, in <genexpr>

    for source_str in source_strs.split(','))

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
124, in parse_single_source

    module = import_source(short_module_name)

  File "/usr/lib/python3.6/site-packages/beancount/prices/find_prices.py", line 
155, in import_source

    module_name, exc))

ImportError: Could not find price source module "cryptocompareusd": No module 
named 'cryptocompare'

```



If I try with the full namespace, it doesn't work either, example:

```

av@sa4 ~/repos/crypto/beancount_cryptocompare                                   
                                                                                
        [20:54:15] 

(.env3) > $ bean-price -e USD:beancount_cryptocompare.cryptocompareusd/ETH 
--no-cache                                                                      
                       

usage: bean-price [-h] [-e] [-v] [-d DATE] [-i] [-u] [-c] [-a] [-s] [-n]

                  [--cache CACHE_FILENAME] [--no-cache] [--clear-cache]

                  sources [sources ...]

```



>From what I understood the `find_prices` works as some sort of plugin importer 
>or similar, is that right?



Could you please help me?



Thank you very much.




-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20171127225941.10000.94120%40celery-worker-107.ash1.bb-inf.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to