Skip to content

Commit

Permalink
Use std LazyLock instead of the crate lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 committed Dec 24, 2024
1 parent e704d18 commit 28f9295
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ documentation = "https://docs.rs/matplotlib"
license = "MIT"
keywords = ["plot", "graph", "curve", "surface"]
categories = ["science", "visualization", "mathematics", "graphics"]
rust-version = "1.80"

[dependencies]
numpy = "0.23.0"
ndarray = "0.16.1"
curve-sampling = { version = "0.5", optional = true, git = "https://github.com/Chris00/rust-curve-sampling.git" }
lazy_static = "1.4.0"

[dependencies.pyo3]
version = "0.23.3"
Expand Down
21 changes: 11 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
//! [Matplotlib]: https://matplotlib.org/
use std::{
borrow::Cow,
fmt::{Display, Formatter},
marker::PhantomData,
path::Path, borrow::Cow,
path::Path,
sync::LazyLock,
};
use lazy_static::lazy_static;
use pyo3::{
prelude::*,
intern,
Expand Down Expand Up @@ -122,16 +123,16 @@ macro_rules! pyimport { ($name: path, $m: literal) => {
})
}}

lazy_static! {
/// ⚠ Accessing these may try to lock Python's GIL. Make sure it is
/// executed outside a call to `Python::with_gil`.
static ref FIGURE: Result<Py<PyModule>, ImportError> = {
/// ⚠ Accessing these may try to lock Python's GIL. Make sure it is
/// executed outside a call to `Python::with_gil`.
static FIGURE: LazyLock<Result<Py<PyModule>, ImportError>> =
LazyLock::new(|| {
pyimport!(matplotlib::FIGURE, "matplotlib.figure")
};
static ref PYPLOT: Result<Py<PyModule>, ImportError> = {
});
static PYPLOT: LazyLock<Result<Py<PyModule>, ImportError>> =
LazyLock::new(|| {
pyimport!(matplotlib::PYPLOT, "matplotlib.pyplot")
};
}
});

// RuntimeWarning: More than 20 figures have been opened. Figures
// created through the pyplot interface (`matplotlib.pyplot.figure`)
Expand Down

0 comments on commit 28f9295

Please sign in to comment.