Skip to content

Commit 42eb655

Browse files
committed
impl _imp.check_hash_based_pycs
1 parent 70f303e commit 42eb655

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

Lib/test/test_imp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ def test_source_hash(self):
353353
self.assertEqual(_imp.source_hash(42, b'hi'), b'\xc6\xe7Z\r\x03:}\xab')
354354
self.assertEqual(_imp.source_hash(43, b'hi'), b'\x85\x9765\xf8\x9a\x8b9')
355355

356-
# TODO: RUSTPYTHON
357-
@unittest.expectedFailure
358356
def test_pyc_invalidation_mode_from_cmdline(self):
359357
cases = [
360358
([], "default"),

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
206206
.number_of_values(1)
207207
.help("warning control; arg is action:message:category:module:lineno"),
208208
)
209+
.arg(
210+
Arg::with_name("check-hash-based-pycs")
211+
.long("check-hash-based-pycs")
212+
.takes_value(true)
213+
.number_of_values(1)
214+
.default_value("default")
215+
.help("always|default|never\ncontrol how Python invalidates hash-based .pyc files"),
216+
)
209217
.arg(
210218
Arg::with_name("bytes-warning")
211219
.short("b")
@@ -321,6 +329,11 @@ fn create_settings(matches: &ArgMatches) -> Settings {
321329
settings.dont_write_bytecode = true;
322330
}
323331

332+
settings.check_hash_based_pycs = matches
333+
.value_of("check-hash-based-pycs")
334+
.unwrap_or("default")
335+
.to_owned();
336+
324337
let mut dev_mode = false;
325338
let mut warn_default_encoding = false;
326339
if let Some(xopts) = matches.values_of("implementation-option") {

vm/src/stdlib/imp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ mod _imp {
5555
import, PyObjectRef, PyRef, PyResult, TryFromObject, VirtualMachine,
5656
};
5757

58+
#[pyattr]
59+
fn check_hash_based_pycs(vm: &VirtualMachine) -> PyStrRef {
60+
vm.ctx
61+
.new_str(vm.state.settings.check_hash_based_pycs.clone())
62+
}
63+
5864
#[pyfunction]
5965
fn extension_suffixes() -> PyResult<Vec<PyObjectRef>> {
6066
Ok(Vec::new())

vm/src/vm/setting.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ pub struct Settings {
6262
// TODO: use this; can TextIOWrapper even work with a non-buffered?
6363
pub stdio_unbuffered: bool,
6464

65+
/// --check-hash-based-pycs
66+
pub check_hash_based_pycs: String,
67+
6568
/// false for wasm. Not a command-line option
6669
pub allow_external_library: bool,
6770
}
@@ -93,6 +96,7 @@ impl Default for Settings {
9396
argv: vec![],
9497
hash_seed: None,
9598
stdio_unbuffered: false,
99+
check_hash_based_pycs: "default".to_owned(),
96100
allow_external_library: cfg!(feature = "importlib"),
97101
}
98102
}

0 commit comments

Comments
 (0)