Visitar URL original
Write bytecode by palaviv · Pull Request #1166 · RustPython/RustPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add dont_write_bytecode flag
  • Loading branch information
palaviv committed Jul 24, 2019
commit db8de563baed43d4c2dd3f29121fa3532e78aa6d
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion vm/src/sysmodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()),
Expand Down
4 changes: 4 additions & 0 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
Expand Down Expand Up @@ -122,6 +125,7 @@ impl Default for PySettings {
ignore_environment: false,
verbose: 0,
quiet: false,
dont_write_bytecode: false,
path_list: vec![],
}
}
Expand Down