beancount.loader
Loader code. This is the main entry point to load up a file.
beancount.loader.LoadError
Bases: NamedTuple
Represents an error encountered during the loading process.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
45 46 47 48 49 50 | |
beancount.loader.aggregate_options_map(options_map, other_options_map)
Aggregate some of the attributes of options map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options_map
|
OptionsMap
|
The target map in which we want to aggregate attributes. Note: This value is mutated in-place. |
required |
other_options_map
|
list[OptionsMap]
|
A list of other options maps, some of whose values we'd like to see aggregated. |
required |
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
beancount.loader.combine_plugins(*plugin_modules)
Combine the plugins from the given plugin modules.
This is used to create plugins of plugins. Args: *plugins_modules: A sequence of module objects. Returns: A list that can be assigned to the new module's plugins attribute.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
742 743 744 745 746 747 748 749 750 751 752 753 754 | |
beancount.loader.compute_input_hash(filenames)
Compute a hash of the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filenames
|
A list of input files. Order is not relevant. |
required |
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
beancount.loader.delete_cache_function(cache_getter, function)
A wrapper that removes the cached filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_getter
|
A function of one argument, the top-level filename, which will return the name of the corresponding cache file. |
required | |
function
|
A function object to decorate for caching. |
required |
Returns: A decorated function which will delete the cached filename, if it exists.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
beancount.loader.get_cache_filename(pattern, filename)
Compute the cache filename from a given pattern and the top-level filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
A cache filename or pattern. If the pattern contains '{filename}' this will get replaced by the top-level filename. This may be absolute or relative. |
required |
filename
|
str
|
The top-level filename. |
required |
Returns: The resolved cache filename.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
beancount.loader.initialize(use_cache, cache_filename=None)
Initialize the loader.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | |
beancount.loader.load_doc(expect_errors=False)
A factory of decorators that loads the docstring and calls the function with entries.
This is an incredibly convenient tool to write lots of tests. Write a unittest using the standard TestCase class and put the input entries in the function's docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expect_errors
|
A boolean or None, with the following semantics, True: Expect errors and fail if there are none. False: Expect no errors and fail if there are some. None: Do nothing, no check. |
False
|
Returns: A wrapped method that accepts a single 'self' argument.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
beancount.loader.load_encrypted_file(filename, log_timings=None, log_errors=None, extra_validations=None, dedent=False, encoding=None)
Load an encrypted Beancount input file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
The name of an encrypted file to be parsed. |
required |
log_timings
|
Any
|
See load_string(). |
None
|
log_errors
|
Any
|
See load_string(). |
None
|
extra_validations
|
list[Any] | None
|
See load_string(). |
None
|
dedent
|
bool
|
See load_string(). |
False
|
encoding
|
str | None
|
See load_string(). |
None
|
Returns: A triple of (entries, errors, option_map) where "entries" is a date-sorted list of entries from the file, "errors" a list of error objects generated while parsing and validating the file, and "options_map", a dict of the options parsed from the file.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
beancount.loader.load_file(filename, log_timings=None, log_errors=None, extra_validations=None, encoding=None)
Open a Beancount input file, parse it, run transformations and validate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
The name of the file to be parsed. |
required |
log_timings
|
Callable[[str], None] | None
|
A file object or function to write timings to, or None, if it should remain quiet. (Note that this is intended to use the logging methods and does not insert a newline.) |
None
|
log_errors
|
Any
|
A file object or function to write errors to, or None, if it should remain quiet. |
None
|
extra_validations
|
list[Any] | None
|
A list of extra validation functions to run after loading this list of entries. |
None
|
encoding
|
str | None
|
A string or None, the encoding to decode the input filename with. |
None
|
Returns: A triple of (entries, errors, option_map) where "entries" is a date-sorted list of entries from the file, "errors" a list of error objects generated while parsing and validating the file, and "options_map", a dict of the options parsed from the file.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
beancount.loader.load_string(string, log_timings=None, log_errors=None, extra_validations=None, dedent=False, encoding=None)
Open a Beancount input string, parse it, run transformations and validate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
A Beancount input string. |
required |
log_timings
|
A file object or function to write timings to, or None, if it should remain quiet. |
None
|
|
log_errors
|
A file object or function to write errors to, or None, if it should remain quiet. |
None
|
|
extra_validations
|
list[Any] | None
|
A list of extra validation functions to run after loading this list of entries. |
None
|
dedent
|
bool
|
A boolean, if set, remove the whitespace in front of the lines. |
False
|
encoding
|
str | None
|
A string or None, the encoding to decode the input string with. |
None
|
Returns: A triple of (entries, errors, option_map) where "entries" is a date-sorted list of entries from the string, "errors" a list of error objects generated while parsing and validating the string, and "options_map", a dict of the options parsed from the string.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
beancount.loader.needs_refresh(options_map)
Predicate that returns true if at least one of the input files may have changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options_map
|
OptionsMap
|
An options dict as per the parser. |
required |
mtime
|
A modified time, to check if it covers the include files in the options_map. |
required |
Returns: A boolean, true if the input is obsoleted by changes in the input files.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
309 310 311 312 313 314 315 316 317 318 319 320 321 | |
beancount.loader.pickle_cache_function(cache_getter, time_threshold, function)
Decorate a loader function to make it loads its result from a pickle cache.
This considers the first argument as a top-level filename and assumes the function to be cached returns an (entries, errors, options_map) triple. We use the 'include' option value in order to check whether any of the included files has changed. It's essentially a special case for an on-disk memoizer. If any of the included files are more recent than the cache, the function is recomputed and the cache refreshed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_getter
|
Callable[[str], str]
|
A function of one argument, the top-level filename, which will return the name of the corresponding cache file. |
required |
time_threshold
|
float
|
A float, the number of seconds below which we don't bother caching. |
required |
function
|
A function object to decorate for caching. |
required |
Returns: A decorated function which will pull its result from a cache file if it is available.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
beancount.loader.run_transformations(entries, parse_errors, options_map, log_timings)
Run the various transformations on the entries.
This is where entries are being synthesized, checked, plugins are run, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Directives
|
A list of directives as read from the parser. |
required |
parse_errors
|
list[BeancountError]
|
A list of errors so far. |
required |
options_map
|
OptionsMap
|
An options dict as read from the parser. |
required |
log_timings
|
Any
|
A function to write timing log entries to, or None, if it should be quiet. |
required |
Returns: A list of modified entries, and a list of errors, also possibly modified.
Source code in .venv/lib/python3.12/site-packages/beancount/loader.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |