Skip to content

Commit cdfcf52

Browse files
committed
Use env::var where applicable. Fix flame-it feature build.
1 parent 49afefd commit cdfcf52

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ fn main() {
3131
let settings = create_settings(&matches);
3232
let vm = VirtualMachine::new(settings);
3333

34-
let res = run_rustpython(&vm, matches);
34+
let res = run_rustpython(&vm, &matches);
3535
// See if any exception leaked out:
3636
handle_exception(&vm, res);
3737

3838
#[cfg(feature = "flame-it")]
3939
{
4040
main_guard.end();
41-
if let Err(e) = write_profile(matches) {
41+
if let Err(e) = write_profile(&matches) {
4242
error!("Error writing profile information: {}", e);
4343
process::exit(1);
4444
}
@@ -146,15 +146,15 @@ fn create_settings(matches: &ArgMatches) -> PySettings {
146146
if matches.is_present("optimize") {
147147
settings.optimize = matches.occurrences_of("optimize").try_into().unwrap();
148148
} else if !ignore_environment {
149-
if let Some(value) = get_env_var_value("PYTHONOPTIMIZE") {
149+
if let Ok(value) = get_env_var_value("PYTHONOPTIMIZE") {
150150
settings.optimize = value;
151151
}
152152
}
153153

154154
if matches.is_present("verbose") {
155155
settings.verbose = matches.occurrences_of("verbose").try_into().unwrap();
156156
} else if !ignore_environment {
157-
if let Some(value) = get_env_var_value("PYTHONVERBOSE") {
157+
if let Ok(value) = get_env_var_value("PYTHONVERBOSE") {
158158
settings.verbose = value;
159159
}
160160
}
@@ -175,9 +175,9 @@ fn create_settings(matches: &ArgMatches) -> PySettings {
175175
}
176176

177177
/// Get environment variable and turn it into integer.
178-
fn get_env_var_value(name: &str) -> Option<u8> {
179-
env::var_os(name).map(|value| {
180-
if let Ok(value) = u8::from_str(&value.into_string().unwrap()) {
178+
fn get_env_var_value(name: &str) -> Result<u8, std::env::VarError> {
179+
env::var(name).map(|value| {
180+
if let Ok(value) = u8::from_str(&value) {
181181
value
182182
} else {
183183
1
@@ -201,7 +201,7 @@ fn get_paths(env_variable_name: &str) -> Vec<String> {
201201
}
202202

203203
#[cfg(feature = "flame-it")]
204-
fn write_profile(matches: ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
204+
fn write_profile(matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
205205
use std::fs::File;
206206

207207
enum ProfileFormat {
@@ -244,7 +244,7 @@ fn write_profile(matches: ArgMatches) -> Result<(), Box<dyn std::error::Error>>
244244
Ok(())
245245
}
246246

247-
fn run_rustpython(vm: &VirtualMachine, matches: ArgMatches) -> PyResult<()> {
247+
fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {
248248
import::init_importlib(&vm, true)?;
249249

250250
if let Some(paths) = option_env!("BUILDTIME_RUSTPYTHONPATH") {

0 commit comments

Comments
 (0)