瀏覽代碼

Update numbat dependencies

David Peter 4 月之前
父節點
當前提交
c9786462be

文件差異過大導致無法顯示
+ 298 - 181
Cargo.lock


+ 8 - 7
numbat-cli/Cargo.toml

@@ -10,19 +10,19 @@ version = "1.16.0"
 edition = "2021"
 license = "MIT OR Apache-2.0"
 readme = "../README.md"
-rust-version = "1.70"
+rust-version = "1.76"
 
 [dependencies]
 anyhow = "1"
-rustyline = { version = "14.0.0", features = ["derive"] }
-dirs = "5"
+rustyline = { version = "16.0.0", features = ["derive"] }
+dirs = "6"
 numbat = { version = "1.16.0", path = "../numbat" }
-colored = "2"
-itertools = "0.12"
+colored = "3"
+itertools = "0.14"
 toml = { version = "0.8.8", features = ["parse"] }
 serde = { version = "1.0.195", features = ["derive"] }
-terminal_size = "0.3.0"
-jiff = "0.1"
+terminal_size = "0.4.2"
+jiff = "0.2"
 
 [dependencies.clap]
 version = "4"
@@ -32,6 +32,7 @@ features = ["suggestions", "color", "wrap_help", "derive"]
 assert_cmd = "2"
 predicates = "3"
 
+
 [[bin]]
 name = "numbat"
 path = "src/main.rs"

+ 1 - 2
numbat-cli/src/main.rs

@@ -11,7 +11,6 @@ use highlighter::NumbatHighlighter;
 
 use itertools::Itertools;
 use numbat::command::{CommandControlFlow, CommandRunner};
-use numbat::compact_str::CompactString;
 use numbat::diagnostic::ErrorDiagnostic;
 use numbat::module_importer::{BuiltinModuleImporter, ChainedImporter, FileSystemImporter};
 use numbat::pretty_print::PrettyPrint;
@@ -309,7 +308,7 @@ impl Cli {
                 modules: self.context.lock().unwrap().list_modules().collect(),
                 all_timezones: jiff::tz::db()
                     .available()
-                    .map(CompactString::from)
+                    .map(|name| name.as_str().into())
                     .collect(),
             },
             highlighter: NumbatHighlighter {

+ 5 - 3
numbat-exchange-rates/Cargo.toml

@@ -7,11 +7,13 @@ repository = "https://github.com/sharkdp/numbat"
 version = "0.5.0"
 edition = "2021"
 license = "MIT OR Apache-2.0"
-rust-version = "1.70"
+rust-version = "1.76"
 
 [dependencies]
-attohttpc = { version = "0.27.0", default-features = false, features = ["tls-rustls-webpki-roots"], optional = true }
-quick-xml = "0.31.0"
+attohttpc = { version = "0.27.0", default-features = false, features = [
+    "tls-rustls-webpki-roots",
+], optional = true }
+quick-xml = "0.37.5"
 
 [features]
 fetch-exchangerates = ["dep:attohttpc"]

文件差異過大導致無法顯示
+ 132 - 539
numbat-wasm/Cargo.lock


+ 5 - 4
numbat-wasm/Cargo.toml

@@ -3,6 +3,7 @@ name = "numbat-wasm"
 authors = ["David Peter <[email protected]>"]
 version = "0.1.0"
 edition = "2021"
+rust-version = "1.76"
 
 [lib]
 crate-type = ["cdylib", "rlib"]
@@ -11,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
 default = ["console_error_panic_hook"]
 
 [dependencies]
-wasm-bindgen = "0.2.90"
+wasm-bindgen = "0.2.100"
 
 # The `console_error_panic_hook` crate provides better debugging of panics by
 # logging them with `console.error`. This is great for development, but requires
@@ -23,11 +24,11 @@ numbat = { path = "../numbat", default-features = false, features = [
 ] }
 html-escape = "0.2.13"
 termcolor = "1.4.1"
-codespan-reporting = "0.11.1"
-getrandom = { version = "0.2.12", features = ["js"] }
+codespan-reporting = "0.12"
+getrandom = { version = "0.3.3", features = ["wasm_js"] }
 
 [dev-dependencies]
-wasm-bindgen-test = "0.3.40"
+wasm-bindgen-test = "0.3.50"
 
 [profile.release]
 # Tell `rustc` to optimize for small code size.

+ 2 - 0
numbat-wasm/build.sh

@@ -3,4 +3,6 @@
 set -euo pipefail
 
 rm -rf www/pkg
+
+export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
 wasm-pack build --target=web --out-dir=www/pkg

+ 1 - 0
numbat-wasm/test.sh

@@ -1,3 +1,4 @@
 #!/bin/bash
 
+export RUSTFLAGS='--cfg getrandom_backend="wasm_js"'
 wasm-pack test --headless --firefox

+ 12 - 11
numbat/Cargo.toml

@@ -10,21 +10,21 @@ version = "1.16.0"
 edition = "2021"
 license = "MIT OR Apache-2.0"
 readme = "README.md"
-rust-version = "1.74"
+rust-version = "1.76"
 
 [dependencies]
-thiserror = "1"
-itertools = "0.12"
+thiserror = "2"
+itertools = "0.14"
 num-rational = "0.4"
 num-integer = "0.1.45"
 num-traits = "0.2"
-codespan-reporting = "0.11"
+codespan-reporting = "0.12"
 strsim = "0.11.0"
 pretty_dtoa = "0.3"
 numbat-exchange-rates = { version = "0.5.0", path = "../numbat-exchange-rates" }
-heck = { version = "0.4.1", features = ["unicode"] }
+heck = "0.5.0"
 unicode-ident = "1.0.12"
-unicode-width = "0.1.11"
+unicode-width = "0.2"
 libc = "0.2.152"
 rust-embed = { version = "8.2.0", features = [
     "interpolate-folder-path",
@@ -32,20 +32,21 @@ rust-embed = { version = "8.2.0", features = [
 ] }
 num-format = "0.4.4"
 walkdir = "2"
-jiff = { version = "0.1.3", features = ["js"] }
+jiff = { version = "0.2.14", features = ["js"] }
 termcolor = { version = "1.4.1", optional = true }
 html-escape = { version = "0.2.13", optional = true }
-rand = "0.8.5"
+rand = "0.9"
 strfmt = "0.2.4"
 indexmap = "2.2.6"
 mendeleev = "0.8.1"
-plotly = "0.10.0"
-compact_str = { version = "0.8.0", features = ["serde"] }
+plotly = { version = "0.12.0", optional = true }
+compact_str = { version = "0.9.0", features = ["serde"] }
 
 [features]
-default = ["fetch-exchangerates"]
+default = ["fetch-exchangerates", "plotting"]
 fetch-exchangerates = ["numbat-exchange-rates/fetch-exchangerates"]
 html-formatter = ["termcolor", "html-escape"]
+plotting = ["plotly"]
 
 [dev-dependencies]
 approx = "0.5"

+ 2 - 1
numbat/src/datetime.rs

@@ -80,7 +80,8 @@ pub fn to_string(dt: &Zoned) -> CompactString {
         write!(out, "{}", dt.strftime("%Y-%m-%d %H:%M:%S")).unwrap();
 
         let offset = dt.offset();
-        let zone_abbreviation = tz.to_offset(dt.timestamp()).2;
+        let offset_info = tz.to_offset_info(dt.timestamp());
+        let zone_abbreviation = offset_info.abbreviation();
 
         if zone_abbreviation.starts_with('+') || zone_abbreviation.starts_with('-') {
             write!(out, " (UTC {offset})").unwrap();

+ 17 - 10
numbat/src/ffi/plot.rs

@@ -1,12 +1,18 @@
+#[cfg(feature = "plotting")]
 use plotly::Plot;
 
+#[cfg(feature = "plotting")]
 use super::macros::*;
+
+#[cfg(feature = "plotting")]
+use compact_str::CompactString;
+
 use super::Args;
 use super::Result;
 use crate::value::Value;
 use crate::RuntimeError;
-use compact_str::CompactString;
 
+#[cfg(feature = "plotting")]
 fn line_plot(mut args: Args) -> Plot {
     let mut fields = arg!(args).unsafe_as_struct_fields();
     let ys = fields.pop().unwrap();
@@ -49,6 +55,7 @@ fn line_plot(mut args: Args) -> Plot {
     crate::plot::line_plot(xs, ys, &x_label, &y_label)
 }
 
+#[cfg(feature = "plotting")]
 fn bar_chart(mut args: Args) -> Plot {
     let mut fields = arg!(args).unsafe_as_struct_fields();
     let x_labels = fields.pop().unwrap();
@@ -81,21 +88,14 @@ fn bar_chart(mut args: Args) -> Plot {
     crate::plot::bar_chart(values, x_labels, &value_label)
 }
 
-#[cfg(not(target_family = "wasm"))]
+#[cfg(feature = "plotting")]
 fn show_plot(plot: Plot) -> CompactString {
     plot.show();
 
     CompactString::const_new("Plot will be opened in the browser")
 }
 
-#[cfg(target_family = "wasm")]
-fn show_plot(_plot: Plot) -> CompactString {
-    // The way we could implement this would be to return plot.to_inline_html(..).
-    // This would have to be retrieved on the JS side and then rendered using plotly.js.
-
-    CompactString::const_new("Plotting is currently not supported on this platform.")
-}
-
+#[cfg(feature = "plotting")]
 pub fn show(args: Args) -> Result<Value> {
     // Dynamic dispatch hack since we don't have bounded polymorphism.
     // And no real support for generics in the FFI.
@@ -118,3 +118,10 @@ pub fn show(args: Args) -> Result<Value> {
 
     return_string!(owned = show_plot(plot))
 }
+
+#[cfg(not(feature = "plotting"))]
+pub fn show(_args: Args) -> Result<Value> {
+    return Err(Box::new(RuntimeError::UserError(
+        "Plotting is currently not supported on this platform.".into(),
+    )));
+}

+ 1 - 0
numbat/src/lib.rs

@@ -24,6 +24,7 @@ pub mod module_importer;
 mod name_resolution;
 mod number;
 mod parser;
+#[cfg(feature = "plotting")]
 mod plot;
 mod prefix;
 mod prefix_parser;

+ 4 - 0
numbat/src/plot.rs

@@ -1,4 +1,6 @@
 use compact_str::CompactString;
+
+#[cfg(feature = "plotting")]
 use plotly::{
     color::Rgb,
     common::{Font, Line},
@@ -6,6 +8,7 @@ use plotly::{
     Bar, Configuration, Layout, Plot, Scatter,
 };
 
+#[cfg(feature = "plotting")]
 pub fn line_plot(xs: Vec<f64>, ys: Vec<f64>, x_label: &str, y_label: &str) -> Plot {
     let x_min = xs[0];
     let x_max = xs[xs.len() - 1];
@@ -31,6 +34,7 @@ pub fn line_plot(xs: Vec<f64>, ys: Vec<f64>, x_label: &str, y_label: &str) -> Pl
     plot
 }
 
+#[cfg(feature = "plotting")]
 pub fn bar_chart(values: Vec<f64>, x_labels: Vec<CompactString>, value_label: &str) -> Plot {
     let mut plot = Plot::new();
 

+ 1 - 1
numbat/src/product.rs

@@ -165,7 +165,7 @@ impl<Factor: Clone + Ord + Canonicalize, const CANONICALIZE: bool> Product<Facto
             .factors
             .iter()
             .cloned()
-            .group_by(|f1| f1.merge_key())
+            .chunk_by(|f1| f1.merge_key())
             .into_iter()
             .map(|(_, group)| {
                 group

+ 1 - 1
numbat/src/quantity.rs

@@ -187,7 +187,7 @@ impl Quantity {
             .unit
             .canonicalized()
             .iter()
-            .group_by(|f| f.unit_id.sort_key())
+            .chunk_by(|f| f.unit_id.sort_key())
         {
             let group_as_unit = Unit::from_factors(group.cloned());
             let group_representative = group_as_unit

+ 1 - 5
numbat/tests/interpreter.rs

@@ -768,7 +768,7 @@ fn test_full_simplify_for_function_calls() {
 
 #[test]
 fn test_datetime_runtime_errors() {
-    expect_failure("datetime(\"2000-01-99\")", "Unrecognized datetime format");
+    expect_failure("datetime(\"2000-01-99\")", "Unrecognized datetime format: failed to parse day in date \"2000-01-99\": day is not valid: parameter 'day' with value 99 is not in the required range of 1..=31");
     expect_failure("now() -> tz(\"Europe/NonExisting\")", "Unknown timezone");
     expect_failure(
         "date(\"2000-01-01\") + 1e100 years",
@@ -778,10 +778,6 @@ fn test_datetime_runtime_errors() {
         "date(\"2000-01-01\") + 15_000 years",
         "DateTime out of range",
     );
-    expect_failure(
-        "format_datetime(\"%Y-%m-%dT%H%:M\", now())",
-        "strftime formatting failed: found unrecognized directive %M following %:.",
-    );
     expect_failure(
         "format_datetime(\"%Y %;\", now())",
         "strftime formatting failed: found unrecognized specifier directive %;.",

部分文件因文件數量過多而無法顯示