impl _imp.check_hash_based_pycs

This commit is contained in:
Jeong YunWon committed 2022-08-15 16:09:32 +09:00
1 parent 70f303eab0
commit 42eb6554f0
4 files changed
+23 -2

No files matched your search

-2
View File
@@ -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"),
+13
View File
@@ -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") {
+6
View File
@@ -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<Vec<PyObjectRef>> {
Ok(Vec::new())
+4
View File
@@ -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"),
}
}