From db8de563baed43d4c2dd3f29121fa3532e78aa6d Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Mon, 22 Jul 2019 18:20:13 +0300 Subject: [PATCH] Add dont_write_bytecode flag --- src/main.rs | 11 +++++++++++ vm/src/sysmodule.rs | 3 ++- vm/src/vm.rs | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 63af32d61..3d63be519 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,11 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> { .short("S") .help("don't imply 'import site' on initialization"), ) + .arg( + Arg::with_name("dont-write-bytecode") + .short("B") + .help("don't write .pyc files on import"), + ) .arg( Arg::with_name("ignore-environment") .short("E") @@ -171,6 +176,12 @@ fn create_settings(matches: &ArgMatches) -> PySettings { settings.quiet = true; } + if matches.is_present("dont-write-bytecode") + || (!ignore_environment && env::var_os("PYTHONDONTWRITEBYTECODE").is_some()) + { + settings.dont_write_bytecode = true; + } + settings } diff --git a/vm/src/sysmodule.rs b/vm/src/sysmodule.rs index 523ec6007..dc80d695b 100644 --- a/vm/src/sysmodule.rs +++ b/vm/src/sysmodule.rs @@ -88,6 +88,7 @@ impl SysFlags { flags.ignore_environment = settings.ignore_environment; flags.verbose = settings.verbose; flags.quiet = settings.quiet; + flags.dont_write_bytecode = settings.dont_write_bytecode; flags } } @@ -322,7 +323,7 @@ settrace() -- set the global debug tracing function "path_hooks" => ctx.new_list(vec![]), "path_importer_cache" => ctx.new_dict(), "pycache_prefix" => vm.get_none(), - "dont_write_bytecode" => vm.new_bool(true), + "dont_write_bytecode" => vm.new_bool(vm.settings.dont_write_bytecode), "setprofile" => ctx.new_rustfunc(sys_setprofile), "settrace" => ctx.new_rustfunc(sys_settrace), "version" => vm.new_str(version::get_version()), diff --git a/vm/src/vm.rs b/vm/src/vm.rs index c36b1287e..1bf8e21c3 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -90,6 +90,9 @@ pub struct PySettings { /// -q pub quiet: bool, + /// -B + pub dont_write_bytecode: bool, + /// Environment PYTHONPATH and RUSTPYTHONPATH: pub path_list: Vec, } @@ -122,6 +125,7 @@ impl Default for PySettings { ignore_environment: false, verbose: 0, quiet: false, + dont_write_bytecode: false, path_list: vec![], } }