File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -106,26 +106,30 @@ impl From<&ImportError> for Error {
106
106
}
107
107
108
108
/// Import and return a handle to the module `$m`.
109
- macro_rules! pyimport { ( $m: literal) => {
109
+ macro_rules! pyimport { ( $name : path , $ m: literal) => {
110
110
Python :: with_gil( |py|
111
111
match PyModule :: import_bound( py, intern!( py, $m) ) {
112
112
Ok ( m) => Ok ( m. into( ) ) ,
113
113
Err ( e) => {
114
- let v = e. value_bound( py) . to_string( ) ;
115
- Err ( ImportError ( v) )
114
+ let mut msg = stringify!( $name) . to_string( ) ;
115
+ msg. push_str( ": " ) ;
116
+ if let Ok ( s) = e. value_bound( py) . str ( ) {
117
+ let s = s. to_str( ) . unwrap_or( "Import error" ) ;
118
+ msg. push_str( s)
119
+ }
120
+ Err ( ImportError ( msg) )
116
121
}
117
122
} )
118
123
} }
119
124
120
- // ⚠ Accessing these may try to lock Python's GIL. Make sure it is
121
- // executed outside a call to `Python::with_gil`.
122
125
lazy_static ! {
123
- // Import matplotlib modules.
126
+ /// ⚠ Accessing these may try to lock Python's GIL. Make sure it is
127
+ /// executed outside a call to `Python::with_gil`.
124
128
static ref FIGURE : Result <Py <PyModule >, ImportError > = {
125
- pyimport!( "matplotlib.figure" )
129
+ pyimport!( matplotlib :: FIGURE , "matplotlib.figure" )
126
130
} ;
127
131
static ref PYPLOT : Result <Py <PyModule >, ImportError > = {
128
- pyimport!( "matplotlib.pyplot" )
132
+ pyimport!( matplotlib :: PYPLOT , "matplotlib.pyplot" )
129
133
} ;
130
134
}
131
135
You can’t perform that action at this time.
0 commit comments