enable deserialization of configuration for common utilities

korrat
Oct 2, 2022, 1:12 PM
MG46NYACGKHTJ5V6NLPDGKQSETQQNCOGP7TDS4KPJDJFNPKWEFJAC

Dependencies

  • [2] NSWL54NM allow deriving pretty printing config from a set of directives
  • [3] CLAGB2U4 make Config debuggable
  • [4] QRIJE4AQ add a simple pretty printer for beancount directives
  • [5] D6UTHZA4 add a simple writer for saving a set of directives to a tree of files
  • [6] SJ6AFVZL remove const configuration in favor of runtime config
  • [7] 5S4MZHL5 pretty print decimals using icu

Change contents

  • replacement in common/beancount-tree-writer/src/lib.rs at line 1
    [4.83][4.0:61]()
    use beancount_pretty_printer::Config as PrettyPrinterConfig;
    [4.83]
    [4.84]
    pub use config::Config;
  • edit in common/beancount-tree-writer/src/lib.rs at line 8
    [4.238][4.238:342]()
    use color_eyre::eyre::format_err;
    use color_eyre::Help;
    use color_eyre::Report;
    use color_eyre::Result;
  • replacement in common/beancount-tree-writer/src/lib.rs at line 21
    [4.651][3.0:17](),[3.17][4.651:708](),[4.651][4.651:708]()
    #[derive(Debug)]
    pub struct Config {
    pub base_directory: Utf8PathBuf,
    [4.651]
    [4.62]
    mod config;
  • edit in common/beancount-tree-writer/src/lib.rs at line 23
    [4.63][4.63:108](),[4.108][4.708:771](),[4.708][4.708:771]()
    pub pretty_printer: PrettyPrinterConfig,
    }
    #[derive(Debug, Snafu)]
    pub struct TreeWriterError(Error);
  • replacement in common/beancount-tree-writer/src/lib.rs at line 24
    [4.795][4.795:1225]()
    enum Error {
    #[snafu(display("encountered unsupported directive while indexing: {directive:?}"))]
    IndexingDirective {
    backtrace: Backtrace,
    directive: Directive,
    },
    #[snafu(display("error while pretty printing directives for key {index:?} to {file}"))]
    PrettyPrinting {
    backtrace: Backtrace,
    file: Utf8PathBuf,
    index: DirectiveIndex,
    source: io::Error,
    },
    }
    [4.795]
    [4.1225]
    pub struct Error(InnerError);
  • replacement in common/beancount-tree-writer/src/lib.rs at line 27
    [4.1250][4.1250:1270]()
    config: Config,
    [4.1250]
    [4.1270]
    config: config::Config,
  • replacement in common/beancount-tree-writer/src/lib.rs at line 31
    [4.1291][4.1291:1332]()
    pub fn new(config: Config) -> Self {
    [4.1291]
    [4.1332]
    pub fn new(config: config::Config) -> Self {
  • edit in common/beancount-tree-writer/src/lib.rs at line 38
    [4.1462]
    [4.1462]
    let pretty_printer_config = match self.config.pretty_printer {
    config::PrettyPrinterConfig::GloballyDerived => Some(
    beancount_pretty_printer::Config::derive_from_directives(&directives),
    ),
    config::PrettyPrinterConfig::LocallyDerived => None,
    config::PrettyPrinterConfig::Static(config) => Some(config),
    };
  • replacement in common/beancount-tree-writer/src/lib.rs at line 56
    [4.1834][4.1834:1910]()
    .map(|(index, directives)| self.write_month(index, directives))
    [4.1834]
    [4.1910]
    .map(|(index, directives)| self.write_month(pretty_printer_config, index, directives))
  • replacement in common/beancount-tree-writer/src/lib.rs at line 63
    [4.2049][4.2049:2225]()
    Err(errors.into_iter().fold(
    format_err!("encountered errors while writing directives to file tree"),
    Report::error,
    ))
    [4.2049]
    [4.2225]
    todo!("convert errors to summarized report")
  • edit in common/beancount-tree-writer/src/lib.rs at line 71
    [4.2297]
    [4.2297]
    pretty_printer_config: Option<beancount_pretty_printer::Config>,
  • replacement in common/beancount-tree-writer/src/lib.rs at line 74
    [4.2368][4.2368:2397]()
    ) -> Result<(), Error> {
    [4.2368]
    [4.2397]
    ) -> Result<(), InnerError> {
  • replacement in common/beancount-tree-writer/src/lib.rs at line 77
    [4.2451][4.2451:2514]()
    let file = index.file_in(&self.config.base_directory);
    [4.2451]
    [4.2514]
    let pretty_printer_config = pretty_printer_config.unwrap_or_else(|| {
    beancount_pretty_printer::Config::derive_from_directives(&directives)
    });
    let file = index.file_in(&self.config.output_path);
  • replacement in common/beancount-tree-writer/src/lib.rs at line 84
    [4.2575][4.109:234]()
    PrettyPrinter::buffered(self.config.pretty_printer, file)
    .print_directives(&directives)
    [4.2575]
    [4.2667]
    PrettyPrinter::buffered(pretty_printer_config, file).print_directives(&directives)
  • replacement in common/beancount-tree-writer/src/lib.rs at line 131
    [4.3849][4.3849:3873]()
    type Error = Error;
    [4.3849]
    [4.3873]
    type Error = InnerError;
  • edit in common/beancount-tree-writer/src/lib.rs at line 152
    [4.4381]
    [4.4381]
    }
    #[derive(Debug, Snafu)]
    enum InnerError {
    #[snafu(display("encountered unsupported directive while indexing: {directive:?}"))]
    IndexingDirective {
    backtrace: Backtrace,
    directive: Directive,
    },
    #[snafu(display("error while pretty printing directives for key {index:?} to {file}"))]
    PrettyPrinting {
    backtrace: Backtrace,
    file: Utf8PathBuf,
    index: DirectiveIndex,
    source: io::Error,
    },
  • edit in common/beancount-tree-writer/src/lib.rs at line 169
    [4.4383]
    type Result<T, E = Error> = std::result::Result<T, E>;
  • replacement in common/beancount-tree-writer/Cargo.toml at line 16
    [4.4724][4.4724:4801]()
    [dependencies.beancount-pretty-printer]
    path = "../beancount-pretty-printer"
    [4.4724]
    [4.4801]
    # Workspace dependencies
    beancount-pretty-printer.path = "../beancount-pretty-printer"
    beancount-types.path = "../beancount-types"
  • replacement in common/beancount-tree-writer/Cargo.toml at line 20
    [4.4802][4.4802:4861]()
    [dependencies.beancount-types]
    path = "../beancount-types"
    [4.4802]
    [4.4861]
    # Inherited from workspace
    serde.workspace = true
  • edit in common/beancount-pretty-printer/src/lib.rs at line 21
    [4.301]
    [4.301]
    use serde::Deserialize;
  • replacement in common/beancount-pretty-printer/src/lib.rs at line 30
    [4.367][4.617:647]()
    #[derive(Clone, Copy, Debug)]
    [4.367]
    [4.647]
    #[derive(Clone, Copy, Debug, Deserialize)]
  • replacement in common/beancount-pretty-printer/src/lib.rs at line 73
    [4.421][4.921:951]()
    #[derive(Clone, Copy, Debug)]
    [4.421]
    [4.951]
    #[derive(Clone, Copy, Debug, Deserialize)]
  • edit in common/beancount-pretty-printer/Cargo.toml at line 23
    [2.7672]
    [4.1741]
    serde.workspace = true