Skip to content

fix(cli): support relative BEANCOUNT_FILE - #1709

Closed
m9810223 wants to merge 1 commit into
beancount:mainfrom
m9810223:cli-relative-path
Closed

m9810223 wants to merge 1 commit into
beancount:mainfrom
m9810223:cli-relative-path

Conversation

@m9810223

@m9810223 m9810223 commented Nov 7, 2023 •

Copy link
Copy Markdown
Contributor

Support relative path string like bcs/main.bc and pass it thru BEANCOUNT_FILE.

$ BEANCOUNT_FILE=bcs/main.bc fava -p 5001
Invalid mimetype set for '.js', overriding
Starting Fava on http://127.0.0.1:5001
Exception on / [GET]
Traceback (most recent call last):
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 865, in full_dispatch_request
    rv = self.preprocess_request()
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 1234, in preprocess_request
    url_func(request.endpoint, request.view_args)
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 233, in _pull_beancount_file
    fava_app.config["LEDGERS"] = _ledger_slugs_dict(
                                 ^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 106, in _ledger_slugs_dict
    for ledger in ledgers:
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 234, in <genexpr>
    FavaLedger(filepath)
  File "./.venv/lib/python3.12/site-packages/fava/core/__init__.py", line 272, in __init__
    self.load_file()
  File "./.venv/lib/python3.12/site-packages/fava/core/__init__.py", line 279, in load_file
    self.all_entries, self.errors, self.options = _load(
                                                  ^^^^^^
  File "./.venv/lib/python3.12/site-packages/beancount/loader.py", line 501, in _load
    entries, parse_errors, options_map = _parse_recursive(
                                         ^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/beancount/loader.py", line 371, in _parse_recursive
    assert path.isabs(source)
AssertionError

```console
$ BEANCOUNT_FILE=bcs/main.bc fava -p 5001
Invalid mimetype set for '.js', overriding
Starting Fava on http://127.0.0.1:5001
Exception on / [GET]
Traceback (most recent call last):
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 865, in full_dispatch_request
    rv = self.preprocess_request()
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/flask/app.py", line 1234, in preprocess_request
    url_func(request.endpoint, request.view_args)
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 233, in _pull_beancount_file
    fava_app.config["LEDGERS"] = _ledger_slugs_dict(
                                 ^^^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 106, in _ledger_slugs_dict
    for ledger in ledgers:
  File "./.venv/lib/python3.12/site-packages/fava/application.py", line 234, in <genexpr>
    FavaLedger(filepath)
  File "./.venv/lib/python3.12/site-packages/fava/core/__init__.py", line 272, in __init__
    self.load_file()
  File "./.venv/lib/python3.12/site-packages/fava/core/__init__.py", line 279, in load_file
    self.all_entries, self.errors, self.options = _load(
                                                  ^^^^^^
  File "./.venv/lib/python3.12/site-packages/beancount/loader.py", line 501, in _load
    entries, parse_errors, options_map = _parse_recursive(
                                         ^^^^^^^^^^^^^^^^^
  File "./.venv/lib/python3.12/site-packages/beancount/loader.py", line 371, in _parse_recursive
    assert path.isabs(source)
AssertionError
```
@yagebu

yagebu commented Nov 11, 2023

Copy link
Copy Markdown
Member

Hi, thank you for the PR :)

Relative paths in this env variable seem error-prone, I'm not sure that it's good to support that. What is your use case for this, can't you put the absolute path into the env variable?

@m9810223

Copy link
Copy Markdown
Contributor Author

I see. Keep it absolute is better, thank you. 😆

@m9810223 m9810223 closed this Nov 11, 2023
@yagebu

yagebu commented Nov 11, 2023 •

Copy link
Copy Markdown
Member

I will improve the handling of this to show a better error message though :)

See #1712

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

Successfully merging this pull request may close these issues.

2 participants