def load_file(self) -> None: """Load the main file and all included files and set attributes.""" # use the internal function to disable cache if not self._is_encrypted: # pylint: disable=protected-access self.all_entries, self.errors, self.options = _load( [(self.beancount_file_path, True)], None, None, None) else: self.all_entries, self.errors, self.options = load_file( self.beancount_file_path) self.get_filtered.cache_clear() self.account_types = get_account_types(self.options) self.price_map = build_price_map(self.all_entries) self.all_root_account = realization.realize(self.all_entries, self.account_types) self.all_entries_by_type = group_entries_by_type(self.all_entries) self.accounts = AccountDict() for open_entry in self.all_entries_by_type.Open: self.accounts.setdefault(open_entry.account).meta = open_entry.meta for close in self.all_entries_by_type.Close: self.accounts.setdefault(close.account).close_date = close.date self.fava_options, errors = parse_options( self.all_entries_by_type.Custom) self.errors.extend(errors) if not self._is_encrypted: self._watcher.update(*self.paths_to_watch()) for mod in MODULES: getattr(self, mod).load_file()
def __init__(self, path: str) -> None: #: The path to the main Beancount file. self.beancount_file_path = path self._is_encrypted = is_encrypted_file(path) #: An :class:`AttributesModule` instance. self.attributes = AttributesModule(self) #: A :class:`.BudgetModule` instance. self.budgets = BudgetModule(self) #: A :class:`.ChartModule` instance. self.charts = ChartModule(self) #: A :class:`.ExtensionModule` instance. self.extensions = ExtensionModule(self) #: A :class:`.FileModule` instance. self.file = FileModule(self) #: A :class:`.IngestModule` instance. self.ingest = IngestModule(self) #: A :class:`.FavaMisc` instance. self.misc = FavaMisc(self) #: A :class:`.DecimalFormatModule` instance. self.format_decimal = DecimalFormatModule(self) #: A :class:`.QueryShell` instance. self.query_shell = QueryShell(self) self._watcher = Watcher() #: List of all (unfiltered) entries. self.all_entries = [] #: Dict of list of all (unfiltered) entries by type. self.all_entries_by_type = group_entries_by_type([]) #: A list of all errors reported by Beancount. self.errors: list[BeancountError] = [] #: A Beancount options map. self.options: BeancountOptions = OPTIONS_DEFAULTS #: A dict containing information about the accounts. self.accounts = AccountDict() #: A dict with commodity names (from the 'name' metadata) self.commodity_names: dict[str, str] = {} #: A dict with all of Fava's option values. self.fava_options: FavaOptions = FavaOptions() self._date_first: datetime.date | None = None self._date_last: datetime.date | None = None self.load_file()