diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index cc4c05e0f..0d40b3ce1 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -353,8 +353,6 @@ class ImportTests(unittest.TestCase): self.assertEqual(_imp.source_hash(42, b'hi'), b'\xc6\xe7Z\r\x03:}\xab') self.assertEqual(_imp.source_hash(43, b'hi'), b'\x85\x9765\xf8\x9a\x8b9') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_pyc_invalidation_mode_from_cmdline(self): cases = [ ([], "default"), diff --git a/src/lib.rs b/src/lib.rs index f876676ea..fae4c9e3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -206,6 +206,14 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> { .number_of_values(1) .help("warning control; arg is action:message:category:module:lineno"), ) + .arg( + Arg::with_name("check-hash-based-pycs") + .long("check-hash-based-pycs") + .takes_value(true) + .number_of_values(1) + .default_value("default") + .help("always|default|never\ncontrol how Python invalidates hash-based .pyc files"), + ) .arg( Arg::with_name("bytes-warning") .short("b") @@ -321,6 +329,11 @@ fn create_settings(matches: &ArgMatches) -> Settings { settings.dont_write_bytecode = true; } + settings.check_hash_based_pycs = matches + .value_of("check-hash-based-pycs") + .unwrap_or("default") + .to_owned(); + let mut dev_mode = false; let mut warn_default_encoding = false; if let Some(xopts) = matches.values_of("implementation-option") { diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index ab18738ff..919b425e9 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -55,6 +55,12 @@ mod _imp { import, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine, }; + #[pyattr] + fn check_hash_based_pycs(vm: &VirtualMachine) -> PyStrRef { + vm.ctx + .new_str(vm.state.settings.check_hash_based_pycs.clone()) + } + #[pyfunction] fn extension_suffixes() -> PyResult> { Ok(Vec::new()) diff --git a/vm/src/vm/setting.rs b/vm/src/vm/setting.rs index dbb571455..4a9b3d710 100644 --- a/vm/src/vm/setting.rs +++ b/vm/src/vm/setting.rs @@ -62,6 +62,9 @@ pub struct Settings { // TODO: use this; can TextIOWrapper even work with a non-buffered? pub stdio_unbuffered: bool, + /// --check-hash-based-pycs + pub check_hash_based_pycs: String, + /// false for wasm. Not a command-line option pub allow_external_library: bool, } @@ -93,6 +96,7 @@ impl Default for Settings { argv: vec![], hash_seed: None, stdio_unbuffered: false, + check_hash_based_pycs: "default".to_owned(), allow_external_library: cfg!(feature = "importlib"), } }