Skip to content

Commit

Permalink
Update deno to 1.36.1, tokio to 1.28.1, and testing fixes (#89)
Browse files Browse the repository at this point in the history
* Update deno deps to 1.36.1

* Avoid deadlock with separate tokio runtime for image loading

* Remove unnecessary pins, update tokio

* check_png

* Use dssim for image comparison in CLI tests

* bundle license update
  • Loading branch information
jonmmease authored Aug 12, 2023
1 parent ecf80c7 commit 20adcb7
Show file tree
Hide file tree
Showing 11 changed files with 2,183 additions and 528 deletions.
383 changes: 226 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

560 changes: 475 additions & 85 deletions thirdparty_rust.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vl-convert-python/tests/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_png_theme_config(name, scale, theme):
theme=theme,
config=config,
)
assert png == expected_png
check_png(png, expected_png)


def test_gh_78():
Expand Down
560 changes: 475 additions & 85 deletions vl-convert-python/thirdparty_rust.yaml

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions vl-convert-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ description = "Library for converting Vega-Lite visualization specifications to
keywords = ["Visualization", "Vega", "Vega-Lite"]

[dependencies]
# Deno 1.34.2. Before updating deno_runtime/deno_core, see note in DEVELOP.md
deno_runtime = "0.116.0"
deno_core = "0.190.0"
swc_macros_common = "=0.3.7"
# Deno 1.36.1. Before updating deno_runtime/deno_core, see note in DEVELOP.md
deno_runtime = "0.123.0"
deno_core = "0.200.0"
serde_json = {version="1.0.85", features=["preserve_order"]}
serde = {version="1.0.145", features=["derive"]}
futures = "0.3.24"
futures-util = "0.3.24"
tokio = {version= "1.21", features=["rt-multi-thread"]}
tokio = {version= "1.28.1", features=["rt-multi-thread"]}
reqwest = {version="0.11.12", default-features=false, features=["rustls-tls", "blocking"]}
rustls = "=0.20.6"
lazy_static = "1.4.0"
usvg = "0.35.0"
resvg = "0.35.0"
Expand Down
21 changes: 12 additions & 9 deletions vl-convert-rs/src/converter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::module_loader::import_map::{url_for_path, vega_themes_url, vega_url, VlVersion};
use crate::module_loader::VlConvertModuleLoader;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::Path;
use std::rc::Rc;
Expand All @@ -9,7 +10,7 @@ use deno_runtime::deno_core::anyhow::bail;
use deno_runtime::deno_core::error::AnyError;
use deno_runtime::deno_core::{serde_v8, v8, Extension};

use deno_core::{op, ModuleCode};
use deno_core::{op, ModuleCode, Op};
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_runtime::deno_core;
use deno_runtime::deno_web::BlobStore;
Expand Down Expand Up @@ -241,13 +242,15 @@ function vegaLiteToSvg_{ver_name}(vlSpec, config, theme) {{
pub async fn try_new() -> Result<Self, AnyError> {
let module_loader = Rc::new(VlConvertModuleLoader::new());

let ext = Extension::builder("vl_convert_extensions")
.ops(vec![
// Op to measure text width with resvg
op_text_width::decl(),
op_get_json_arg::decl(),
])
.build();
let ext = Extension {
name: "vl_convert_extensions",
ops: Cow::Owned(vec![
// Op to measure text width with resvg,
op_text_width::DECL,
op_get_json_arg::DECL,
]),
..Default::default()
};

let create_web_worker_cb = Arc::new(|_| {
todo!("Web workers are not supported");
Expand Down Expand Up @@ -276,7 +279,7 @@ function vegaLiteToSvg_{ver_name}(vlSpec, config, theme) {{
get_error_class_fn: Some(&get_error_class_name),
cache_storage_dir: None,
origin_storage_dir: None,
blob_store: BlobStore::default(),
blob_store: Arc::new(BlobStore::default()),
broadcast_channel: InMemoryBroadcastChannel::default(),
shared_array_buffer_store: None,
compiled_wasm_module_store: None,
Expand Down
8 changes: 6 additions & 2 deletions vl-convert-rs/src/image_loading.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::converter::TOKIO_RUNTIME;
use http::StatusCode;
use log::error;
use reqwest::Client;
Expand All @@ -10,6 +9,11 @@ static VL_CONVERT_USER_AGENT: &str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

lazy_static! {
static ref IMAGE_TOKIO_RUNTIME: tokio::runtime::Runtime =
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
static ref REQWEST_CLIENT: Client = reqwest::ClientBuilder::new()
.user_agent(VL_CONVERT_USER_AGENT)
.build()
Expand All @@ -35,7 +39,7 @@ pub fn custom_string_resolver() -> ImageHrefStringResolverFn {

// Download image to temporary file with reqwest
let bytes: Option<_> = task::block_in_place(move || {
TOKIO_RUNTIME.block_on(async {
IMAGE_TOKIO_RUNTIME.block_on(async {
if let Ok(response) = REQWEST_CLIENT.get(href).send().await {
// Check status code.
match response.status() {
Expand Down
560 changes: 475 additions & 85 deletions vl-convert-rs/thirdparty_rust.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vl-convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ assert_cmd = "2.0"
predicates = "3.0.2"
rstest = "0.17.0"
tempfile = "3.3.0"
dssim = "3.2.4"
46 changes: 33 additions & 13 deletions vl-convert/tests/test_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_cmd::prelude::*; // Add methods on commands
use dssim::{Dssim, DssimImage};
use predicates::prelude::*; // Used for writing assertions
use rstest::rstest;
use std::fs;
Expand Down Expand Up @@ -73,10 +74,10 @@ fn load_expected_svg(name: &str, vl_version: &str) -> String {
fs::read_to_string(spec_path).unwrap()
}

fn load_expected_png(name: &str, vl_version: &str, theme: Option<&str>) -> Vec<u8> {
fn load_expected_png(name: &str, vl_version: &str, theme: Option<&str>) -> Option<DssimImage<f32>> {
let vl_version = VlVersion::from_str(vl_version).unwrap();
let root_path = Path::new(env!("CARGO_MANIFEST_DIR"));
let spec_path = root_path
let image_path = root_path
.join("..")
.join("vl-convert-rs")
.join("tests")
Expand All @@ -88,7 +89,7 @@ fn load_expected_png(name: &str, vl_version: &str, theme: Option<&str>) -> Vec<u
} else {
format!("{}.png", name)
});
fs::read(&spec_path).unwrap_or_else(|_| panic!("Failed to read {:?}", spec_path))
dssim::load_image(&Dssim::new(), image_path).ok()
}

fn output_path(filename: &str) -> String {
Expand Down Expand Up @@ -236,7 +237,6 @@ mod test_vl2svg {

#[rustfmt::skip]
mod test_vl2png {
use std::fs;
use std::process::Command;
use crate::*;

Expand Down Expand Up @@ -264,21 +264,31 @@ mod test_vl2png {
.arg("--font-dir").arg(test_font_dir())
.arg("--scale").arg(scale.to_string());

// Load expected
let expected_png = load_expected_png(name, vl_version, None);
cmd.assert().success();

// Load expected
let expected_png = load_expected_png(name, vl_version, None).unwrap();


// Load written spec
let output_png = fs::read(&output).unwrap();
assert_eq!(expected_png, output_png);
let output_png = dssim::load_image(&Dssim::new(), &output).unwrap();

let attr = Dssim::new();
let (diff, _) = attr.compare(&expected_png, &output_png);

if diff > 0.0001 {
panic!(
"Images don't match for {}.png with diff {}",
name, diff
)
}

Ok(())
}
}

#[rustfmt::skip]
mod test_vl2png_theme_config {
use std::fs;
use std::process::Command;
use crate::*;

Expand Down Expand Up @@ -314,13 +324,23 @@ mod test_vl2png_theme_config {
.arg("--config").arg(config_path)
.arg("--scale").arg(scale.to_string());

// Load expected
let expected_png = load_expected_png(name, vl_version, Some(theme));
cmd.assert().success();

// Load expected
let expected_png = load_expected_png(name, vl_version, Some(theme)).unwrap();

// Load written spec
let output_png = fs::read(&output).unwrap();
assert_eq!(expected_png, output_png);
let output_png = dssim::load_image(&Dssim::new(), &output).unwrap();

let attr = Dssim::new();
let (diff, _) = attr.compare(&expected_png, &output_png);

if diff > 0.0001 {
panic!(
"Images don't match for {}.png with diff {}",
name, diff
)
}

Ok(())
}
Expand Down
Loading

0 comments on commit 20adcb7

Please sign in to comment.